src/squirrel_helper.hpp
branchnoai
changeset 9529 5f26f4bc574b
parent 9510 261d33fbabb8
child 9530 5b93bc87cc5e
equal deleted inserted replaced
9528:b2cc6f31363c 9529:5f26f4bc574b
   377 	inline SQInteger DefSQCallback(HSQUIRRELVM vm)
   377 	inline SQInteger DefSQCallback(HSQUIRRELVM vm)
   378 	{
   378 	{
   379 		/* Find the amount of params we got */
   379 		/* Find the amount of params we got */
   380 		int nparam = sq_gettop(vm);
   380 		int nparam = sq_gettop(vm);
   381 		SQUserPointer ptr = NULL;
   381 		SQUserPointer ptr = NULL;
   382 		SQUserPointer instance = NULL;
   382 		SQUserPointer real_instance = NULL;
       
   383 		HSQOBJECT instance;
       
   384 
       
   385 		/* Get the 'SQ' instance of this class */
       
   386 		Squirrel::GetInstance(vm, &instance);
       
   387 
       
   388 		/* Protect against calls to a non-static method in a static way */
       
   389 		sq_pushroottable(vm);
       
   390 		sq_pushstring(vm, Tcls::GetClassName(), -1);
       
   391 		sq_get(vm, -2);
       
   392 		sq_pushobject(vm, instance);
       
   393 		if (sq_instanceof(vm) != SQTrue) return sq_throwerror(vm, "class method is non-static");
       
   394 		sq_settop(vm, nparam);
   383 
   395 
   384 		/* Get the 'real' instance of this class */
   396 		/* Get the 'real' instance of this class */
   385 		sq_getinstanceup(vm, 1, &instance, 0);
   397 		sq_getinstanceup(vm, 1, &real_instance, 0);
   386 		/* Get the real function pointer */
   398 		/* Get the real function pointer */
   387 		sq_getuserdata(vm, nparam, &ptr, 0);
   399 		sq_getuserdata(vm, nparam, &ptr, 0);
       
   400 
   388 		/* Delegate it to a template that can handle this specific function */
   401 		/* Delegate it to a template that can handle this specific function */
   389 		return HelperT<Tmethod>::SQCall((Tcls *)instance, *(Tmethod *)ptr, vm);
   402 		return HelperT<Tmethod>::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm);
   390 	}
   403 	}
   391 
   404 
   392 }; // namespace SQConvert
   405 }; // namespace SQConvert
   393 
   406 
   394 #endif /* SQUIRREL_HELPER_HPP */
   407 #endif /* SQUIRREL_HELPER_HPP */