Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Differenciate user created functions from library functions

edited April 2012 in Questions Posts: 13

Is there a way to differenciate user created functions from library functions in _G table ?

Thanks for your help.

Tagged:

Comments

  • SimeonSimeon Admin Mod
    Posts: 5,030

    I don't think so, what are you attempting to do?

    We insert the global functions into Lua (from C) as follows:

    lua_pushcfunction(L, func)
    lua_setglobal(L, name)
    

    I expect this adds the name to _G as normal.

  • JohnJohn Admin Mod
    Posts: 575

    One thing you could do is add some code to the start of your left-most tab that makes a shallow copy of the _G table. I say the left most, because tabs are executed left to right. So your shallow copy would be 'unpolluted' by user variables. You can then filter the list by type to get all functions, etc.

  • Posts: 146

    @Leon_levy I am not quite sure why you would want to do that, but there is a way to distinguish functions written in Lua from functions written in C. If you call debug.getinfo() on the function, that returns a table with info about that function. In this table, there is a field 'what', which is "C" for low level (C) functions, and has other values for functions written in Lua. So basically, for builtins, you would look for the value "C" in that field.

  • Posts: 13

    Thank you Gunnar, it worked well.
    Nice to have help so fast from all of you.
    Leon

Sign In or Register to comment.