summaryrefslogtreecommitdiff
path: root/library/LuaWrapper.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-03-29 14:47:33 +0400
committerAlexander Gavrilov2012-03-29 14:47:33 +0400
commita9b7c74a232357ccaa2796aa6aba2c53218075c3 (patch)
treede699edd3cc04488ebc0be2d999e8780de6e34a3 /library/LuaWrapper.cpp
parent85c91c92d81b4ba226973aa9312c7b01e47554de (diff)
downloaddfhack-a9b7c74a232357ccaa2796aa6aba2c53218075c3.tar.gz
dfhack-a9b7c74a232357ccaa2796aa6aba2c53218075c3.tar.bz2
dfhack-a9b7c74a232357ccaa2796aa6aba2c53218075c3.tar.xz
Allow assigning NULL lightuserdata to pointers, and export a global.
Otherwise there is no way to specify NULL via recursive lua table assign.
Diffstat (limited to 'library/LuaWrapper.cpp')
-rw-r--r--library/LuaWrapper.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/library/LuaWrapper.cpp b/library/LuaWrapper.cpp
index 4e1c6205..8e3bff7d 100644
--- a/library/LuaWrapper.cpp
+++ b/library/LuaWrapper.cpp
@@ -496,14 +496,7 @@ static int meta_sizeof(lua_State *state)
luaL_error(state, "Usage: object:sizeof() or df.sizeof(object)");
// Two special cases: nil and lightuserdata for NULL and void*
- if (lua_isnil(state, 1))
- {
- lua_pushnil(state);
- lua_pushinteger(state, 0);
- return 2;
- }
-
- if (lua_islightuserdata(state, 1))
+ if (lua_isnil(state, 1) || lua_islightuserdata(state, 1))
{
lua_pushnil(state);
lua_pushnumber(state, (size_t)lua_touserdata(state, 1));
@@ -1314,6 +1307,11 @@ static void DoAttach(lua_State *state)
lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_ASSIGN_NAME);
lua_setfield(state, -2, "assign");
+ lua_pushlightuserdata(state, NULL);
+ lua_setfield(state, -2, "NULL");
+ lua_pushlightuserdata(state, NULL);
+ lua_setglobal(state, "NULL");
+
freeze_table(state, true, "df");
lua_remove(state, -2);
lua_setmetatable(state, -2);