Commonly required advanced tasks
Method handling
- The preferred way to handle methods with a specific object type for
this
:
ObjectDataStruct* data;
if( !SGS_PARSE_METHOD( C, Object_interface_pointer, data, Object_name, Method_name ) )
return 0;
sgs_FuncName( C, "<object>.<method>" );
if( !sgs_Method( C ) || !sgs_IsObject( C, 0, Object_interface_pointer ) )
return sgs_ArgErrorExt( C, 0, 1, "<object>", "" );
ObjectDataStruct* data = (ObjectDataStruct*) sgs_GetObjectData( C, 0 );
sgs_HideThis( C );
- The OLD way, version 2: Method + function handling (function that can be called as a method too)
int method_call = sgs_Method( C );
sgs_FuncName( C, method_call ? "<object>.<method>" : "<object_function>" );
if( !sgs_IsObject( C, 0, Object_interface_pointer ) )
return sgs_ArgErrorExt( C, 0, method_call, "<object>", "" );
ObjectDataStruct* data = (ObjectDataStruct*) sgs_GetObjectData( C, 0 );
sgs_ForceHideThis( C );
- The reason why the first method is preferred to others is: it's shorter, does pretty much the same thing and resolves to sgs_ParseMethod, which allows sharing more code and rebuilding the SGS_PARSE_METHOD macro abstraction, if necessary.