[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: tolua
- From: "Peter Prade" <prade@...>
- Date: Fri, 18 Oct 2002 13:52:14 +0200
> how can i get a list of members from a tolua object. tolua.foreach
> only shows me the members that were added via lua. for example, i
> have a .pkg file that looks like:
hi,
this is a bit tricky to do.
you need access to the registry (a special lua table not directly accessable
by lua).
here's how you access this table from C:
static int GetRegistry(lua_State* pLuaState)
{
lua_getregistry(pLuaState);
return 1;
}
lua_register(pLuaState, "GetRegistry", GetRegistry);
now you can get that table in lua scripts. i've used it to add a
tolua.info() function:
-- tolua info helps dumping info on tolua objects
tolua.info = function(x)
if x then
if type(x) == "userdata" then
x = tolua.type(x)
end
local i = tfind(GetRegistry().tolua_tbl_itype, x)
if i then
print(x) -- print class name
-- and all member functions
foreach(GetRegistry().tolua_tbl_class[i], function(i,v) if type(v) ==
"function" then print(":" .. i .. "()") end end)
-- and all member variables
foreach(GetRegistry().tolua_tbl_class[i][".get"], function(i,v) print("."
.. i) end)
end
end
end
(talking about Lua 4.0 and tolua 4.0a here)
i hope this helps,
Peter