views:

352

answers:

2

I'm new to Lua and dealing with Lua as a scripting language in an alpha release of a program. The developer is unresponsive and I need to get a list of functions provided by some C++ objects which are accessible from the Lua code.

Is there any easy way to see what fields and functions these objects expose?

+3  A: 

In Lua, to view the members of a object, you can use:

for key,value in pairs(o) do
    print("found member " .. key);
end

Unfortunately I don't know if this will work for objects imported from C++.

Frank Schwieterman
Wow, so simple. It works 100%, thanks so much! You have no idea how helpful this is. :)One more thing - can you also get a list of arguments for the functions?
luanoob
Not that I know. I wonder what you could find doing a dll export on the compiled c++.
Frank Schwieterman
I have tried that, but searching through the function names didn't even find the functions that I know exist, unfortunately.
luanoob
A DLL based module will often only export the single function `luaopen_modulename()` which constructs the module's table and returns it to the machinery that implements `require()`. The code implementing the actual functions in the module is usually not exported because it can only be called within the context of a running Lua interpreter state.
RBerteig
+2  A: 

If allowed in the environment, looking at the metatable of the exported C++ object can help:

for key,value in pairs(getmetatable(o)) do
    print(key, value)
end
kaizer.se