hxdecorate

Haxe library for creating decorators
https://github.com/nweedon/hxdecorate

To install, run:

haxelib install hxdecorate 1.1.0 

See using Haxelib in Haxelib documentation for more information.

README.md

hxdecorate

Build Status Haxelib

Installation

haxelib install hxdecorate 1.0.0

Aims

  • Primarily, merge macros and metadata capabilities together to emulate decorators
  • To be multiplatform
  • Building from above, supporting as many Haxe exports as possible with the same config syntax

Notes

  • Very early development: ideas and suggestions are appreciated!
  • This is currently working run-time only, but I'm really wanting to get build-time decorators working too (i.e. adding/modifying/deleting fields etc.)
  • Haxelib will be available at some point

Supported Targets

PlatformSupported
AS3
C++
C#
ES5
Flash
Java
Neko
Node.js
PHP
Python

Extra Supporting Features

The following build features are added automatically in hxdecorate, to make using the library as easy as possible: :keep :expose * :cppInclude

Use

Place on main class.

Syntax:

@:build(hxdecorate.Decorator.build({
  decorator_name : path_to_static_function#functionName,
  ...
},
[
  path_to_classes_with_decorators
]))

Example:

@:build(hxdecorate.Decorator.build({
	'DecoratorOne' : 'libraryTest.TestDecorators#decoratorOne',
	'DecoratorTwo' : 'libraryTest.TestDecorators#decoratorTwo'
}, [
	"libraryTest.ToDecorate"
]))
class Main
{
  // ...
}

Example Output

The following example shows JavaScript export behaviour:

package libraryTest;

@DecoratorOne({ one: 1 })
@DecoratorTwo({ two: 2 })
class ToDecorate
{
	public var annotations = [];
	public var parameters = [];

	public function new()
	{

	}
}

class TestDecorators
{
	private function new()
	{

	}

	public static function decoratorOne(input : Dynamic, caller : ToDecorate) : ToDecorate
	{
		caller.annotations.push(input);
		return caller;
	}

	public static function decoratorTwo(input : Dynamic, caller : ToDecorate) : ToDecorate
	{
		caller.parameters.push(input);
		return caller;
	}
}

Outputs to:

var libraryTest_ToDecorate = function() {
	this.parameters = [];
	this.annotations = [];
	$hx_exports.libraryTest.TestDecorators.decoratorTwo({ two : 2},$hx_exports.libraryTest.TestDecorators.decoratorOne({ one : 1},this));
};

More info: src/libraryTest/ToDecorate.hx and src/libraryTest/TestDecorators.hx

Contributors
nweedon
Version
1.1.0
Published
2 years ago
License
Apache

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github