Giter VIP home page Giter VIP logo

haxe-const's Introduction

haxe-const

Constants implemented for Haxe language with help of abstracts
Maybe you want macro version instead?

Installation & Usage

Quick install:

haxelib git haxeconst https://github.com/PeyTy/haxe-const.git

Quick update:

haxelib update haxeconst

Add to build.hxml:

-lib haxeconst

No import required if you use OOP syntax: var c = new Const(value); For short functional syntax, use import Const.Tools.const; and then var c = const(value);

Just create instance of Const class or use function const from import Const.Tools.const;:

// Ints:
var c = const(56);
// same as:
var c = new Const(56);
// c = 7; error!
// c++; error! No A++ ++A A-- --A for consts!
var x:Int = c;
trace(c+1);
trace(c*10);
trace(c/10);
trace(c-1);
trace(1-c);

// Floats:
var c = new Const(56.65);
// c = 123.456; error!
var x:Float = c;
trace(c+1);
trace(c*10);
trace(c/10.0);
trace(c-1);

// Strings:
var s = new Const("hello");
// s = "string"; error!
trace(s);
trace(s.length);

// Arrays:
var a = new Const([1,2,3]);
// a = [1]; error!
a.push(4);
trace(a);
trace(a.length);
var ar:Array<Int> = a;

// Anything:

class Demo {
	public var a:Int = 100;
	public var b = new Const({ hello : "hi!" });
}

var demo = new Const(new Demo());
// demo = new Demo(); error!
// demo.b = { hello : "um?" }; error!
trace(demo);
trace(demo.a);
demo.a = 101;
trace(demo.b.hello);
demo.b.hello = "hi-hi";

Hacking Consts (can be useful)

// The Only Hack =)
demo = new Const(new Demo()); // where demo -> already instantiated Const

// Function arguments:
function test(const:Const<Int>){
	// const = 7; error!
	trace(const); // 42 OK
}
test(new Const(42));

Known Bugs !need help!

// Ints:
var c = new Const(56);
var x:Int = c;
trace(x+c); // bug
trace(-c); // bug
// Floats:
var c = new Const(56.65);
var x:Float = c;
trace(x-c); // bug
trace(x+c); // bug
trace(-c); // bug

haxe-const's People

Contributors

peyty avatar pleclech avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.