src/squirrel_helper.hpp
branchnoai
changeset 9635 9ee82e091af7
parent 9629 66dde6412125
child 9651 6e2860c67455
equal deleted inserted replaced
9634:e359d82f0652 9635:9ee82e091af7
   444 
   444 
   445 		/* Get the 'real' instance of this class */
   445 		/* Get the 'real' instance of this class */
   446 		sq_getinstanceup(vm, 1, &real_instance, 0);
   446 		sq_getinstanceup(vm, 1, &real_instance, 0);
   447 		/* Get the real function pointer */
   447 		/* Get the real function pointer */
   448 		sq_getuserdata(vm, nparam, &ptr, 0);
   448 		sq_getuserdata(vm, nparam, &ptr, 0);
       
   449 		if (real_instance == NULL) return sq_throwerror(vm, _SC("couldn't detect real instance of class for non-static call"));
   449 
   450 
   450 		/* Delegate it to a template that can handle this specific function */
   451 		/* Delegate it to a template that can handle this specific function */
   451 		return HelperT<Tmethod>::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm);
   452 		return HelperT<Tmethod>::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm);
   452 	}
   453 	}
   453 
   454 
   485 	/**
   486 	/**
   486 	 * A general template to handle creating of instance with any amount of
   487 	 * A general template to handle creating of instance with any amount of
   487 	 *  params. It creates the instance in C++, and it sets all the needed
   488 	 *  params. It creates the instance in C++, and it sets all the needed
   488 	 *  settings in SQ to register the instance.
   489 	 *  settings in SQ to register the instance.
   489 	 */
   490 	 */
   490 	template <typename Tcls, typename Tmethod>
   491 	template <typename Tcls, typename Tmethod, int Tnparam>
   491 	inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm)
   492 	inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm)
   492 	{
   493 	{
   493 		/* Create the real instance */
   494 		/* Create the real instance */
   494 		Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm);
   495 		Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm);
   495 		sq_setinstanceup(vm, -1, instance);
   496 		sq_setinstanceup(vm, -Tnparam, instance);
   496 		sq_setreleasehook(vm, -1, DefSQDestructorCallback<Tcls>);
   497 		sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>);
   497 		return 0;
   498 		return 0;
   498 	}
   499 	}
   499 
   500 
   500 }; // namespace SQConvert
   501 }; // namespace SQConvert
   501 
   502