Last active
December 20, 2015 03:09
-
-
Save RealyUniqueName/6062012 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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