Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct AnyVtable{
- String* (*toString)(Any* thisobj);
- ...
- Any (*call)(Any* thisobj, RestParams params);
- };
- struct Any{
- AnyVtable* vtable;
- union{
- Object* object;
- ...
- };
- };
- 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));
- }
- AnyVtable Foo_fnc_vtable = {
- /*toString = */ [](Any*) -> String*{
- return new String("Foo::fnc");
- },
- ...
- /*call = */ fnc_wrapper
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement