src/squirrel_helper.hpp
branchnoai
changeset 9635 9ee82e091af7
parent 9629 66dde6412125
child 9651 6e2860c67455
--- a/src/squirrel_helper.hpp	Thu Jul 12 14:55:28 2007 +0000
+++ b/src/squirrel_helper.hpp	Thu Jul 12 15:04:26 2007 +0000
@@ -446,6 +446,7 @@
 		sq_getinstanceup(vm, 1, &real_instance, 0);
 		/* Get the real function pointer */
 		sq_getuserdata(vm, nparam, &ptr, 0);
+		if (real_instance == NULL) return sq_throwerror(vm, _SC("couldn't detect real instance of class for non-static call"));
 
 		/* Delegate it to a template that can handle this specific function */
 		return HelperT<Tmethod>::SQCall((Tcls *)real_instance, *(Tmethod *)ptr, vm);
@@ -487,13 +488,13 @@
 	 *  params. It creates the instance in C++, and it sets all the needed
 	 *  settings in SQ to register the instance.
 	 */
-	template <typename Tcls, typename Tmethod>
+	template <typename Tcls, typename Tmethod, int Tnparam>
 	inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm)
 	{
 		/* Create the real instance */
 		Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm);
-		sq_setinstanceup(vm, -1, instance);
-		sq_setreleasehook(vm, -1, DefSQDestructorCallback<Tcls>);
+		sq_setinstanceup(vm, -Tnparam, instance);
+		sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>);
 		return 0;
 	}