lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2015-07-28 11:47 GMT+02:00 Rob Kendrick <rjek@rjek.com>:
> On Tue, Jul 28, 2015 at 09:44:46AM +0000, Laurent FAILLIE wrote:
>> Hello,
>> I'm looking for a way to find out a function from it's name.
>> I understood from the documentation that function are handled as "normal" object, so with my test code, I'm expecting to find it in global variable table.So I'm calling lua_getglobal() on the function name but it fails and returns a NIL.
>
> Functions, much like other values such as 42, "spatula" and false do not
> have names, they are values.
>
> A function may have any number of variables that have names assoicated
> with it; including zero.
>
> The best you can hope for is to spider the entire environment looking
> for a variable that contains the same function you're looking for and
> also hope that it's a usefully named one.

If the function name is not found by lua_getglobal it may be a local
function or an upvalue. You can query those names via lua_getlocal and
lua_getupvalue, but you'll have to loop through the possibilities;
there
is no name-based access.