Stop printall(df.global) from breaking if there are unknown addresses.

develop
Alexander Gavrilov 2012-04-10 10:34:03 +04:00
parent 585de77489
commit 0e0740fddf
3 changed files with 18 additions and 6 deletions

@ -68,6 +68,11 @@ All typed objects have the following built-in features:
and values. Fields are enumerated in memory order. Methods and
lua wrapper properties are not included in the iteration.
**WARNING**: a few of the data structures (like ui_look_list)
contain unions with pointers to different types with vtables.
Using pairs on such structs is an almost sure way to crash with
an access violation.
* ``ref._kind``
Returns one of: ``primitive``, ``struct``, ``container``,

@ -395,6 +395,10 @@ Every structured field access produces a new userdata instance.</p>
<p>Returns an iterator for the sequence of actual C++ field names
and values. Fields are enumerated in memory order. Methods and
lua wrapper properties are not included in the iteration.</p>
<p><strong>WARNING</strong>: a few of the data structures (like ui_look_list)
contain unions with pointers to different types with vtables.
Using pairs on such structs is an almost sure way to crash with
an access violation.</p>
</li>
<li><p class="first"><tt class="docutils literal">ref._kind</tt></p>
<p>Returns one of: <tt class="docutils literal">primitive</tt>, <tt class="docutils literal">struct</tt>, <tt class="docutils literal">container</tt>,

@ -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);
}
/**