Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua - Reflection - Get list of functions/fields on an object?

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?

like image 959
luanoob Avatar asked Apr 12 '10 07:04

luanoob


2 Answers

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++.

like image 188
Frank Schwieterman Avatar answered Sep 28 '22 10:09

Frank Schwieterman


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 
like image 20
u0b34a0f6ae Avatar answered Sep 28 '22 08:09

u0b34a0f6ae