Getting API info from C to Lua?

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?

Answers


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


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.


for i,v in pairs(getmetatable(g_gameRules).__index) do 
    System.LogAlways(i.." : "..v); 
end

OR

    for i,v in pairs(g_gameRules) do 
    System.LogAlways(i.." : "..v); 
end

Need Your Help

How to add 'Notification', 'Warning' and 'Error' icons on Prism 6.2 WPF modal dialog?

c# wpf mvvm modal-dialog prism

In my Prism 6.2 WPF MVVM application I use notification and confirmation modal dialogs. Below is a definition of the View of a notification modal dialog used in my application: