summaryrefslogtreecommitdiff
path: root/library/LuaTypes.cpp
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-04-10 10:34:03 +0400
committerAlexander Gavrilov2012-04-10 10:34:03 +0400
commit0e0740fddf26a849c97c26bd8e6dcb6cf58b9bf9 (patch)
tree0665da84702bd69e270e769fcd96b15a1967987c /library/LuaTypes.cpp
parent585de77489f8325fc40807723017fb52e1618a62 (diff)
downloaddfhack-0e0740fddf26a849c97c26bd8e6dcb6cf58b9bf9.tar.gz
dfhack-0e0740fddf26a849c97c26bd8e6dcb6cf58b9bf9.tar.bz2
dfhack-0e0740fddf26a849c97c26bd8e6dcb6cf58b9bf9.tar.xz
Stop printall(df.global) from breaking if there are unknown addresses.
Diffstat (limited to 'library/LuaTypes.cpp')
-rw-r--r--library/LuaTypes.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/library/LuaTypes.cpp b/library/LuaTypes.cpp
index 4213499e..2f9ef9e8 100644
--- a/library/LuaTypes.cpp
+++ b/library/LuaTypes.cpp
@@ -1072,10 +1072,10 @@ void LuaWrapper::SetFunctionWrappers(lua_State *state, const FunctionReg *reg)
/**
* Add fields in the array to the UPVAL_FIELDTABLE candidates on the stack.
*/
-static void IndexFields(lua_State *state, int base, struct_identity *pstruct)
+static void IndexFields(lua_State *state, int base, struct_identity *pstruct, bool globals)
{
if (pstruct->getParent())
- IndexFields(state, base, pstruct->getParent());
+ IndexFields(state, base, pstruct->getParent(), globals);
auto fields = pstruct->getFields();
if (!fields)
@@ -1105,7 +1105,10 @@ static void IndexFields(lua_State *state, int base, struct_identity *pstruct)
break;
default:
- AssociateId(state, base+3, ++cnt, name.c_str());
+ // Do not add invalid globals to the enumeration order
+ if (!globals || *(void**)fields[i].offset)
+ AssociateId(state, base+3, ++cnt, name.c_str());
+
lua_pushlightuserdata(state, (void*)&fields[i]);
lua_setfield(state, base+2, name.c_str());
break;
@@ -1143,7 +1146,7 @@ void LuaWrapper::IndexStatics(lua_State *state, int meta_idx, int ftable_idx, st
* Make a struct-style object metatable.
*/
static void MakeFieldMetatable(lua_State *state, struct_identity *pstruct,
- lua_CFunction reader, lua_CFunction writer)
+ lua_CFunction reader, lua_CFunction writer, bool globals = false)
{
int base = lua_gettop(state);
@@ -1152,7 +1155,7 @@ static void MakeFieldMetatable(lua_State *state, struct_identity *pstruct,
// Index the fields
lua_newtable(state);
- IndexFields(state, base, pstruct);
+ IndexFields(state, base, pstruct, globals);
// Add the iteration metamethods
PushStructMethod(state, base+1, base+3, meta_struct_next);
@@ -1304,7 +1307,7 @@ void struct_identity::build_metatable(lua_State *state)
void global_identity::build_metatable(lua_State *state)
{
- MakeFieldMetatable(state, this, meta_global_index, meta_global_newindex);
+ MakeFieldMetatable(state, this, meta_global_index, meta_global_newindex, true);
}
/**