Skip to content

Instantly share code, notes, and snippets.

@RealyUniqueName
Last active December 20, 2015 03:09
Show Gist options
  • Save RealyUniqueName/6062012 to your computer and use it in GitHub Desktop.
Save RealyUniqueName/6062012 to your computer and use it in GitHub Desktop.
package pony.flash;
import haxe.macro.Expr;
import pony.events.Signal;
#if !macro
import flash.external.ExternalInterface;
#end
/**
* ...
* @author AxGord
*/
class Exterface extends Signal implements Dynamic<Exterface> {
public static var get:Exterface = new Exterface();
private static var map:Map<String, Exterface> = new Map<String, Exterface>();
public var name(default, null):String;
//public var call:Dynamic;
private function new(?name:String) {
if (name != null) {
super();
this.name = name;
#if !macro
ExternalInterface.addCallback(name, cb);
#end
map.set(name, this);
//call = Reflect.makeVarArgs(cll);
}
}
private function cb(v:Array<Dynamic>):Void dispatchArgs(v);
public function resolve(field:String):Exterface {
var s:String = (name != null ? name + '.' : '') + field;
return map.exists(s) ? map.get(s) : new Exterface(s);
}
macro public function call(ex:Expr):Expr {
trace(ex);
return macro _call($ex);
}
#if !macro
public function _call(args:Array<Dynamic>):Dynamic {
args.unshift(name);
return Reflect.callMethod(null, ExternalInterface.call, args);
}
#end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment