Browse Source

LUA binding. Some additions

Panagiotis Christopoulos Charitos 11 years ago
parent
commit
a912d2ee91

+ 17 - 0
include/anki/script/LuaBinder.h

@@ -59,6 +59,20 @@ public:
 	static void pushLuaCFuncStaticMethod(lua_State* l, const char* className,
 		const char* name, lua_CFunction luafunc);
 
+	template<typename TNumber>
+	static ANKI_USE_RESULT Error checkNumber(
+		lua_State* l, I stackIdx, TNumber& number)
+	{
+		lua_Number lnum;
+		Error err = checkNumberInternal(l, stackIdx, lnum);
+		if(!err)
+		{
+			number = lnum;
+		}
+
+		return err;
+	}
+
 	static void* luaAlloc(lua_State* l, size_t size);
 
 	static void luaFree(lua_State* l, void* ptr);
@@ -84,6 +98,9 @@ private:
 
 	static void* luaAllocCallback(
 		void* userData, void* ptr, PtrSize osize, PtrSize nsize);
+
+	static ANKI_USE_RESULT Error checkNumberInternal(
+		lua_State* l, I stackIdx, lua_Number& number);
 };
 
 //==============================================================================

+ 23 - 0
src/script/LuaBinder.cpp

@@ -136,6 +136,29 @@ void LuaBinder::pushLuaCFuncStaticMethod(lua_State* l, const char* className,
 	lua_pop(l, 1); // pop cfunc
 }
 
+//==============================================================================
+Error LuaBinder::checkNumberInternal(
+	lua_State* l, I stackIdx, lua_Number& number)
+{
+	Error err = ErrorCode::NONE;
+	lua_Number lnum;
+	int isnum;
+
+	lnum = lua_tonumberx(l, stackIdx, &isnum);
+	if(isnum)
+	{
+		number = lnum;
+	}
+	else
+	{
+		err = ErrorCode::USER_DATA;
+		lua_pushfstring(
+			l, "Number expected. Got %s", luaL_typename(l, stackIdx));
+	}
+
+	return err;
+}
+
 //==============================================================================
 void* LuaBinder::luaAlloc(lua_State* l, size_t size)
 {

+ 186 - 28
src/script/Math.cpp

@@ -25,6 +25,8 @@ static inline int pwrapVec2Ctor(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 0);
 	
@@ -85,6 +87,8 @@ static inline int pwrapVec2getX(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -121,6 +125,8 @@ static inline int pwrapVec2getY(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -157,6 +163,8 @@ static inline int pwrapVec2setX(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -167,7 +175,8 @@ static inline int pwrapVec2setX(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).x() = arg0;
@@ -193,6 +202,8 @@ static inline int pwrapVec2setY(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -203,7 +214,8 @@ static inline int pwrapVec2setY(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).y() = arg0;
@@ -229,6 +241,8 @@ static inline int pwrapVec2getAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -239,7 +253,8 @@ static inline int pwrapVec2getAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	F32 ret = (*self)[arg0];
@@ -268,6 +283,8 @@ static inline int pwrapVec2setAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 3);
 	
@@ -278,9 +295,11 @@ static inline int pwrapVec2setAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	F32 arg1(luaL_checknumber(l, 3));
+	F32 arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
 	// Call the method
 	(*self)[arg0] = arg1;
@@ -306,6 +325,8 @@ static inline int pwrapVec2copy(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -346,6 +367,8 @@ static inline int pwrapVec2__add(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -401,6 +424,8 @@ static inline int pwrapVec2__sub(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -456,6 +481,8 @@ static inline int pwrapVec2__mul(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -511,6 +538,8 @@ static inline int pwrapVec2__div(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -566,6 +595,8 @@ static inline int pwrapVec2__eq(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -609,6 +640,8 @@ static inline int pwrapVec2getLength(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -645,6 +678,8 @@ static inline int pwrapVec2getNormalized(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -693,6 +728,8 @@ static inline int pwrapVec2normalize(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -726,6 +763,8 @@ static inline int pwrapVec2dot(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -802,6 +841,8 @@ static inline int pwrapVec3Ctor(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 0);
 	
@@ -862,6 +903,8 @@ static inline int pwrapVec3getX(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -898,6 +941,8 @@ static inline int pwrapVec3getY(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -934,6 +979,8 @@ static inline int pwrapVec3getZ(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -970,6 +1017,8 @@ static inline int pwrapVec3setX(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -980,7 +1029,8 @@ static inline int pwrapVec3setX(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).x() = arg0;
@@ -1006,6 +1056,8 @@ static inline int pwrapVec3setY(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1016,7 +1068,8 @@ static inline int pwrapVec3setY(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).y() = arg0;
@@ -1042,6 +1095,8 @@ static inline int pwrapVec3setZ(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1052,7 +1107,8 @@ static inline int pwrapVec3setZ(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).z() = arg0;
@@ -1078,6 +1134,8 @@ static inline int pwrapVec3getAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1088,7 +1146,8 @@ static inline int pwrapVec3getAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	F32 ret = (*self)[arg0];
@@ -1117,6 +1176,8 @@ static inline int pwrapVec3setAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 3);
 	
@@ -1127,9 +1188,11 @@ static inline int pwrapVec3setAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	F32 arg1(luaL_checknumber(l, 3));
+	F32 arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
 	// Call the method
 	(*self)[arg0] = arg1;
@@ -1155,6 +1218,8 @@ static inline int pwrapVec3copy(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1195,6 +1260,8 @@ static inline int pwrapVec3__add(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1250,6 +1317,8 @@ static inline int pwrapVec3__sub(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1305,6 +1374,8 @@ static inline int pwrapVec3__mul(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1360,6 +1431,8 @@ static inline int pwrapVec3__div(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1415,6 +1488,8 @@ static inline int pwrapVec3__eq(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1458,6 +1533,8 @@ static inline int pwrapVec3getLength(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1494,6 +1571,8 @@ static inline int pwrapVec3getNormalized(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1542,6 +1621,8 @@ static inline int pwrapVec3normalize(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1575,6 +1656,8 @@ static inline int pwrapVec3dot(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1653,6 +1736,8 @@ static inline int pwrapVec4Ctor(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 0);
 	
@@ -1713,6 +1798,8 @@ static inline int pwrapVec4getX(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1749,6 +1836,8 @@ static inline int pwrapVec4getY(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1785,6 +1874,8 @@ static inline int pwrapVec4getZ(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1821,6 +1912,8 @@ static inline int pwrapVec4getW(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -1857,6 +1950,8 @@ static inline int pwrapVec4setX(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1867,7 +1962,8 @@ static inline int pwrapVec4setX(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).x() = arg0;
@@ -1893,6 +1989,8 @@ static inline int pwrapVec4setY(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1903,7 +2001,8 @@ static inline int pwrapVec4setY(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).y() = arg0;
@@ -1929,6 +2028,8 @@ static inline int pwrapVec4setZ(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1939,7 +2040,8 @@ static inline int pwrapVec4setZ(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).z() = arg0;
@@ -1965,6 +2067,8 @@ static inline int pwrapVec4setW(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -1975,7 +2079,8 @@ static inline int pwrapVec4setW(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	(*self).w() = arg0;
@@ -2001,6 +2106,8 @@ static inline int pwrapVec4getAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2011,7 +2118,8 @@ static inline int pwrapVec4getAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	F32 ret = (*self)[arg0];
@@ -2040,6 +2148,8 @@ static inline int pwrapVec4setAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 3);
 	
@@ -2050,9 +2160,11 @@ static inline int pwrapVec4setAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	F32 arg1(luaL_checknumber(l, 3));
+	F32 arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
 	// Call the method
 	(*self)[arg0] = arg1;
@@ -2078,6 +2190,8 @@ static inline int pwrapVec4copy(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2118,6 +2232,8 @@ static inline int pwrapVec4__add(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2173,6 +2289,8 @@ static inline int pwrapVec4__sub(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2228,6 +2346,8 @@ static inline int pwrapVec4__mul(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2283,6 +2403,8 @@ static inline int pwrapVec4__div(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2338,6 +2460,8 @@ static inline int pwrapVec4__eq(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2381,6 +2505,8 @@ static inline int pwrapVec4getLength(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -2417,6 +2543,8 @@ static inline int pwrapVec4getNormalized(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -2465,6 +2593,8 @@ static inline int pwrapVec4normalize(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -2498,6 +2628,8 @@ static inline int pwrapVec4dot(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2578,6 +2710,8 @@ static inline int pwrapMat3Ctor(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 0);
 	
@@ -2638,6 +2772,8 @@ static inline int pwrapMat3copy(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2678,6 +2814,8 @@ static inline int pwrapMat3getAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 3);
 	
@@ -2688,9 +2826,11 @@ static inline int pwrapMat3getAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	U arg1(luaL_checknumber(l, 3));
+	U arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
 	// Call the method
 	F32 ret = (*self)(arg0, arg1);
@@ -2719,6 +2859,8 @@ static inline int pwrapMat3setAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 4);
 	
@@ -2729,11 +2871,14 @@ static inline int pwrapMat3setAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	U arg1(luaL_checknumber(l, 3));
+	U arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
-	F32 arg2(luaL_checknumber(l, 4));
+	F32 arg2;
+	if(LuaBinder::checkNumber(l, 4, arg2)) return -1;
 	
 	// Call the method
 	(*self)(arg0, arg1) = arg2;
@@ -2779,6 +2924,8 @@ static inline int pwrapMat3x4Ctor(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 0);
 	
@@ -2839,6 +2986,8 @@ static inline int pwrapMat3x4copy(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -2879,6 +3028,8 @@ static inline int pwrapMat3x4getAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 3);
 	
@@ -2889,9 +3040,11 @@ static inline int pwrapMat3x4getAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	U arg1(luaL_checknumber(l, 3));
+	U arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
 	// Call the method
 	F32 ret = (*self)(arg0, arg1);
@@ -2920,6 +3073,8 @@ static inline int pwrapMat3x4setAt(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 4);
 	
@@ -2930,11 +3085,14 @@ static inline int pwrapMat3x4setAt(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	U arg0(luaL_checknumber(l, 2));
+	U arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
-	U arg1(luaL_checknumber(l, 3));
+	U arg1;
+	if(LuaBinder::checkNumber(l, 3, arg1)) return -1;
 	
-	F32 arg2(luaL_checknumber(l, 4));
+	F32 arg2;
+	if(LuaBinder::checkNumber(l, 4, arg2)) return -1;
 	
 	// Call the method
 	(*self)(arg0, arg1) = arg2;

+ 6 - 1
src/script/Renderer.cpp

@@ -25,6 +25,8 @@ static inline int pwrapDbggetEnabled(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -61,6 +63,8 @@ static inline int pwrapDbgsetEnabled(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -71,7 +75,8 @@ static inline int pwrapDbgsetEnabled(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	Bool arg0(luaL_checknumber(l, 2));
+	Bool arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	self->setEnabled(arg0);

+ 44 - 9
src/script/Scene.cpp

@@ -44,6 +44,8 @@ static inline int pwrapMoveComponentsetLocalOrigin(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -84,6 +86,8 @@ static inline int pwrapMoveComponentgetLocalOrigin(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -124,6 +128,8 @@ static inline int pwrapMoveComponentsetLocalRotation(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -164,6 +170,8 @@ static inline int pwrapMoveComponentgetLocalRotation(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -204,6 +212,8 @@ static inline int pwrapMoveComponentsetLocalScale(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -214,7 +224,8 @@ static inline int pwrapMoveComponentsetLocalScale(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Pop arguments
-	F32 arg0(luaL_checknumber(l, 2));
+	F32 arg0;
+	if(LuaBinder::checkNumber(l, 2, arg0)) return -1;
 	
 	// Call the method
 	self->setLocalScale(arg0);
@@ -240,6 +251,8 @@ static inline int pwrapMoveComponentgetLocalScale(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -297,6 +310,8 @@ static inline int pwrapSceneNodegetName(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -333,6 +348,8 @@ static inline int pwrapSceneNodeaddChild(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -375,13 +392,15 @@ static int wrapSceneNodeaddChild(lua_State* l)
 }
 
 //==============================================================================
-/// Pre-wrap method SceneNode::getComponent<MoveComponent>.
+/// Pre-wrap method SceneNode::tryGetComponent<MoveComponent>.
 static inline int pwrapSceneNodegetMoveComponent(lua_State* l)
 {
 	UserData* ud;
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -392,20 +411,26 @@ static inline int pwrapSceneNodegetMoveComponent(lua_State* l)
 	ANKI_ASSERT(self != nullptr);
 	
 	// Call the method
-	MoveComponent& ret = self->getComponent<MoveComponent>();
+	MoveComponent* ret = self->tryGetComponent<MoveComponent>();
 	
 	// Push return value
+	if(ANKI_UNLIKELY(ret == nullptr))
+	{
+		lua_pushstring(l, "Glue code returned nullptr");
+		return -1;
+	}
+	
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	ud = reinterpret_cast<UserData*>(voidp);
 	luaL_setmetatable(l, "MoveComponent");
-	ud->m_data = reinterpret_cast<void*>(&ret);
+	ud->m_data = reinterpret_cast<void*>(ret);
 	ud->m_gc = false;
 	
 	return 1;
 }
 
 //==============================================================================
-/// Wrap method SceneNode::getComponent<MoveComponent>.
+/// Wrap method SceneNode::tryGetComponent<MoveComponent>.
 static int wrapSceneNodegetMoveComponent(lua_State* l)
 {
 	int res = pwrapSceneNodegetMoveComponent(l);
@@ -440,6 +465,8 @@ static inline int pwrapModelNodegetSceneNodeBase(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -496,6 +523,8 @@ static inline int pwrapInstanceNodegetSceneNodeBase(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 1);
 	
@@ -552,6 +581,8 @@ static inline int pwrapSceneGraphnewModelNode(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 3);
 	
@@ -570,11 +601,12 @@ static inline int pwrapSceneGraphnewModelNode(lua_State* l)
 	ModelNode* ret = newSceneNode<ModelNode>(self, arg0, arg1);
 	
 	// Push return value
-	if(ANKI_UNLIKELY(ret == 0))
+	if(ANKI_UNLIKELY(ret == nullptr))
 	{
-		lua_pushstring(l, "Glue code returned zero");
+		lua_pushstring(l, "Glue code returned nullptr");
 		return -1;
 	}
+	
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	ud = reinterpret_cast<UserData*>(voidp);
 	luaL_setmetatable(l, "ModelNode");
@@ -602,6 +634,8 @@ static inline int pwrapSceneGraphnewInstanceNode(lua_State* l)
 	(void)ud;
 	void* voidp;
 	(void)voidp;
+	Error err = ErrorCode::NONE;
+	(void)err;
 	
 	LuaBinder::checkArgsCount(l, 2);
 	
@@ -618,11 +652,12 @@ static inline int pwrapSceneGraphnewInstanceNode(lua_State* l)
 	InstanceNode* ret = newSceneNode<InstanceNode>(self, arg0);
 	
 	// Push return value
-	if(ANKI_UNLIKELY(ret == 0))
+	if(ANKI_UNLIKELY(ret == nullptr))
 	{
-		lua_pushstring(l, "Glue code returned zero");
+		lua_pushstring(l, "Glue code returned nullptr");
 		return -1;
 	}
+	
 	voidp = lua_newuserdata(l, sizeof(UserData));
 	ud = reinterpret_cast<UserData*>(voidp);
 	luaL_setmetatable(l, "InstanceNode");

+ 4 - 4
src/script/Scene.xml

@@ -70,8 +70,8 @@ static T* newSceneNode(SceneGraph* scene, CString name, TArgs... args)
 					</args>
 					<return>Error</return>
 				</method>
-				<method name="getComponent&lt;MoveComponent&gt;" alias="getMoveComponent">
-					<return>MoveComponent&amp;</return>
+				<method name="tryGetComponent&lt;MoveComponent&gt;" alias="getMoveComponent">
+					<return>MoveComponent*</return>
 				</method>
 			</methods>
 		</class>
@@ -99,14 +99,14 @@ static T* newSceneNode(SceneGraph* scene, CString name, TArgs... args)
 						<arg>const CString&amp;</arg>
 						<arg>const CString&amp;</arg>
 					</args>
-					<return zeroAsError="1">ModelNode*</return>
+					<return>ModelNode*</return>
 				</method>
 				<method name="newInstanceNode">
 					<overrideCall><![CDATA[InstanceNode* ret = newSceneNode<InstanceNode>(self, arg0);]]></overrideCall>
 					<args>
 						<arg>const CString&amp;</arg>
 					</args>
-					<return zeroAsError="1">InstanceNode*</return>
+					<return>InstanceNode*</return>
 				</method>
 			</methods>
 		</class>

+ 25 - 28
src/script/lua_glue_gen.py

@@ -97,18 +97,18 @@ def ret(ret_el):
 
 	wglue("// Push return value")
 
-	zero_as_error = ret_el.get("zeroAsError", None)
-	if zero_as_error is not None and zero_as_error == "1":
-		wglue("if(ANKI_UNLIKELY(ret == 0))")
+	type_txt = ret_el.text
+	(type, is_ref, is_ptr, is_const) = parse_type_decl(type_txt)
+
+	if is_ptr:
+		wglue("if(ANKI_UNLIKELY(ret == nullptr))")
 		wglue("{")
 		ident(1)
-		wglue("lua_pushstring(l, \"Glue code returned zero\");")
+		wglue("lua_pushstring(l, \"Glue code returned nullptr\");")
 		wglue("return -1;")
 		ident(-1)
 		wglue("}")
-
-	type_txt = ret_el.text
-	(type, is_ref, is_ptr, is_const) = parse_type_decl(type_txt)
+		wglue("")
 	
 	if type_is_bool(type):
 		wglue("lua_pushboolean(l, ret);")
@@ -169,12 +169,12 @@ def arg(arg_txt, stack_index, index):
 
 	(type, is_ref, is_ptr, is_const) = parse_type_decl(arg_txt)
 
-	if type_is_bool(type):
-		wglue("%s arg%d(luaL_checknumber(l, %d));" \
-			% (type, index, stack_index))
-	elif type_is_number(type):
-		wglue("%s arg%d(luaL_checknumber(l, %d));" \
-			% (type, index, stack_index))
+	if type_is_bool(type) or type_is_number(type):
+		#wglue("%s arg%d(luaL_checknumber(l, %d));" \
+			#% (type, index, stack_index))
+		wglue("%s arg%d;" % (type, index))
+		wglue("if(LuaBinder::checkNumber(l, %d, arg%d)) return -1;" \
+			% (stack_index, index))
 	elif type == "char" or type == "CString":
 		wglue("const char* arg%d(luaL_checkstring(l, %d));" \
 			% (index, stack_index))
@@ -262,6 +262,15 @@ def get_meth_alias(meth_el):
 
 	return meth_alias
 
+def write_local_vars():
+	wglue("UserData* ud;")
+	wglue("(void)ud;")
+	wglue("void* voidp;")
+	wglue("(void)voidp;")
+	wglue("Error err = ErrorCode::NONE;")
+	wglue("(void)err;")
+	wglue("")
+
 def method(class_name, meth_el):
 	""" Handle a method """
 
@@ -276,11 +285,7 @@ def method(class_name, meth_el):
 		% (class_name, meth_alias))
 	wglue("{")
 	ident(1)
-	wglue("UserData* ud;")
-	wglue("(void)ud;")
-	wglue("void* voidp;")
-	wglue("(void)voidp;")
-	wglue("")
+	write_local_vars()
 
 	check_args(meth_el.find("args"), 1)
 
@@ -350,11 +355,7 @@ def static_method(class_name, meth_el):
 		% (class_name, meth_alias))
 	wglue("{")
 	ident(1)
-	wglue("UserData* ud;")
-	wglue("(void)ud;")
-	wglue("void* voidp;")
-	wglue("(void)voidp;")
-	wglue("")
+	write_local_vars()
 
 	check_args(meth_el.find("args"), 0)
 
@@ -406,11 +407,7 @@ def constructor(constr_el, class_name):
 	wglue("static inline int pwrap%sCtor(lua_State* l)" % class_name)
 	wglue("{")
 	ident(1)
-	wglue("UserData* ud;")
-	wglue("(void)ud;")
-	wglue("void* voidp;")
-	wglue("(void)voidp;")
-	wglue("")
+	write_local_vars()
 
 	check_args(constr_el.find("args"), 0)