diff options
| author | Alexander Gavrilov | 2012-03-29 14:47:33 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-03-29 14:47:33 +0400 |
| commit | a9b7c74a232357ccaa2796aa6aba2c53218075c3 (patch) | |
| tree | de699edd3cc04488ebc0be2d999e8780de6e34a3 /library/LuaTypes.cpp | |
| parent | 85c91c92d81b4ba226973aa9312c7b01e47554de (diff) | |
| download | dfhack-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/LuaTypes.cpp')
| -rw-r--r-- | library/LuaTypes.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp index 089ead0d..8b297453 100644 --- a/library/LuaTypes.cpp +++ b/library/LuaTypes.cpp @@ -215,12 +215,19 @@ static void autovivify_ptr(lua_State *state, int fname_idx, void **pptr, lua_pop(state, 1); } +static bool is_null(lua_State *state, int val_index) +{ + return lua_isnil(state, val_index) || + (lua_islightuserdata(state, val_index) && + !lua_touserdata(state, val_index)); +} + void df::pointer_identity::lua_write(lua_State *state, int fname_idx, void *ptr, type_identity *target, int val_index) { auto pptr = (void**)ptr; - if (lua_isnil(state, val_index)) + if (is_null(state, val_index)) *pptr = NULL; else if (lua_istable(state, val_index)) { |
