Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int nom_method_A( SGS_CTX )
- {
- SGSFN( "nom::method_A" );
- sgs_PushInt( C, 5 );
- if( sgs_Method( C ) )
- {
- sgs_PushItem( C, -1 );
- sgs_StoreProperty( C, 0, "a" );
- }
- return 1;
- }
- int nom_method_B( SGS_CTX )
- {
- SGSFN( "nom::method_B" );
- sgs_PushInt( C, 7 );
- if( sgs_Method( C ) )
- {
- sgs_PushItem( C, -1 );
- sgs_StoreProperty( C, 0, "b" );
- }
- return 1;
- }
- int nom_iface( SGS_CTX );
- int nom_ctor( SGS_CTX )
- {
- SGSFN( "nom::nom" );
- sgs_PushInterface( C, nom_iface );
- sgs_PushDict( C, 0 );
- sgs_ObjSetMetaObj( C, sgs_GetObjectStruct( C, -1 ), sgs_GetObjectStruct( C, -2 ) );
- return 1;
- }
- int nom_iface( SGS_CTX )
- {
- sgs_PushString( C, "method_A" );
- sgs_PushCFunction( C, nom_method_A );
- sgs_PushString( C, "method_B" );
- sgs_PushCFunction( C, nom_method_B );
- sgs_PushString( C, "__call" );
- sgs_PushCFunction( C, nom_ctor );
- atf_assert( sgs_PushDict( C, 6 ) == SGS_SUCCESS );
- atf_assert( sgs_StackSize( C ) >= 1 );
- sgs_ObjSetMetaMethodEnable( sgs_GetObjectStruct( C, -1 ), 1 );
- return 1;
- }
- DEFINE_TEST( native_obj_meta )
- {
- SGS_CTX = get_context();
- /* register as ctor/iface */
- sgs_PushInterface( C, nom_iface );
- sgs_StoreGlobal( C, "nom" );
- /* try creating and running the object */
- atf_assert( sgs_ExecString( C, ""
- "a = nom();\n"
- "printvar(a.method_A());\n"
- "printvar(a.method_B());\n"
- "function nom.method_C(){ this.c = 9; return 9; }\n"
- "printvar(a.method_C());\n"
- "printvar(a);\n"
- "" ) == SGS_SUCCESS );
- destroy_context( C );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement