1
0

ToLua++ lib: Assert when usertype is not known.

This commit is contained in:
Mattes D 2014-08-22 10:32:32 +02:00
parent 64fec204c4
commit 8b8ccac0b8

View File

@ -16,6 +16,7 @@
#include "../../../lua/src/lauxlib.h" #include "../../../lua/src/lauxlib.h"
#include <stdlib.h> #include <stdlib.h>
#include <assert.h>
TOLUA_API void tolua_pushvalue (lua_State* L, int lo) TOLUA_API void tolua_pushvalue (lua_State* L, int lo)
{ {
@ -55,12 +56,14 @@ TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type)
else else
{ {
luaL_getmetatable(L, type); luaL_getmetatable(L, type);
assert(!lua_isnil(L, -1)); /* Failure here means that the usertype is unknown to ToLua. Check what type you're pushing. */
lua_pushstring(L,"tolua_ubox"); lua_pushstring(L,"tolua_ubox");
lua_rawget(L,-2); /* stack: mt ubox */ lua_rawget(L,-2); /* stack: mt ubox */
if (lua_isnil(L, -1)) { if (lua_isnil(L, -1))
lua_pop(L, 1); {
lua_pushstring(L, "tolua_ubox"); lua_pop(L, 1);
lua_rawget(L, LUA_REGISTRYINDEX); lua_pushstring(L, "tolua_ubox");
lua_rawget(L, LUA_REGISTRYINDEX);
}; };
lua_pushlightuserdata(L,value); lua_pushlightuserdata(L,value);
lua_rawget(L,-2); /* stack: mt ubox ubox[u] */ lua_rawget(L,-2); /* stack: mt ubox ubox[u] */