Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo{
- public function fnc(x:int, y:Number):String{
- return x.toString() + y.toString();
- }
- }
- String* fnc(int x, double y){
- return String::concat(Int::toString(x), Number::toString(y));
- }
- Any fnc_wrapper(Any* closure, RestParams params){
- if ( params.length < 2 ){
- throw new TypeError("not enough arguments, expected no less than 2");
- }
- if ( params.length > 2 ){
- throw new TypeError("too many arguments, expected no more than 2");
- }
- int a0 = Any::unwrapInt(params[0]);
- double a1 = Any::unwrapNumber(params[1]);
- Foo* this_object = (Foo*)closure->object;
- return Any::wrap(this_object->fnc(a0, a1));
- }
- // you can do this
- var foo:Foo = new Foo();
- var method_closure:Function = foo['fnc'];
- var y:int = method_closure(4, "22.0");
- trace(y); // prints "422"
- Foo* foo = Foo::new();
- Function method_closure = Function::NewMethodClosure(foo, fnc_wrapper);
- int y = Any::unwrapInt(
- method_closure.invoke(
- {
- Any::wrap(4),
- Any::wrap(new String("22.0"))
- }
- )
- );
- trace({Any::wrap(y)});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement