Fwd: Inspecting objects

Thomas Nelson <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <[email protected]>
I am very sorry if this goes out twice, I sent it out yesterday and I've 
not seen it come back to me on the list or show up in the archives so 
I'm guessing something went wrong at my end.

I am trying to add some introspection to my luabind objects and I am 
starting to suspect that I'm missing something obvious.

I would like to check from C++ to see if an object has a value set on 
the lua side that is not otherwise defined in the C++.

When I make the assignment I can watch the value get set in a metatable 
via set_instance_value() and stepping into the lau_gettable (see 
has_item_in_lua() below) call eventually drops me into 
get_instance_value(), however the value that comes back seems to always 
be nil. Any thoughts on where I'm going wrong?

abbreviated code sample

Lua:
obj = MyLuabindObject; -- this object has been declared via luabind
obj.Foobar = 1; -- this property was not declared in the via luabind, it
should exist only in the lua side of the slice.

C++:
class MyCppObject: public wrap_base
{ // stuff
MyCppObject() {}

bool has_item_in_lua(const char *name)
{
// this is the code that I'm wondering about.
m_self.get(L); // should push self's userdata onto the stack

lua_pushstring(L, name); // push the name of the member I'm
looking for onto the stack
lua_gettable(L, -2); // get the member's entry from
self (via metamethod)
lua_remove(L, -2); // remove self
if (!lua_isnil(L, -1)) // test result
return true;
lua_pop(L, 1);
return false;
}
};

//-----
module(L)[
class_<MyCppObject>("MyLuabindObj")
]




------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.