Skip to content
This repository has been archived by the owner on Sep 23, 2019. It is now read-only.

nweedon/hxdecorate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hxdecorate

Build Status Haxelib

Installation

haxelib install hxdecorate 1.1.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

Platform Supported
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
{
  // ...
}

The decorator process can also be proxied through another build macro. See src/test/MainProxy.hx for an example.

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