tags:

views:

70

answers:

2

Hello, how can I get a list of all C API functions with Lua? For example, there are plenty C functions in a game(Crysis) which can be called with

Lua: g_gameRules.game:FunctionInC()

There are many functions I know but how can I get all available functions?

+1  A: 

If g_gameRules.game is a table, traverse it looking for functions. If it is a userdata, look inside its metatable. (Also if it is a table.)

lhf
+1  A: 

There may or may not be an easy way to enumerate all of the C functions.

The g_gameRules.game may actually contain the functions, but this would be unusual. Something like the following will list these functions.

for k,v in pairs(g_gameRules.game) do if print(k,v) end

More likely g_gameRules.game will have a meta-table with an __index entry that is either a table or a a function. If the __index entry is a table the following will list all the functions.

for k,v in pairs(getmetatable(g_gameRules.game).__index) do print(k,v) end

This will only determine the names of the functions, the parameter list will still be an unknown.

If however, the __index value for the meta-table is a function, then there will be no easy way to list the functions.

gwell