[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Trying to resolve name of a function inside an argument list
- From: "W. C. Bubel" <inmatarian@...>
- Date: Sun, 7 Oct 2007 23:32:40 -0400
Lua's Tables can use any type, except nil, as both key and value. If you want a way to get a function's name, you can build your own lookup table matching functions to names. That is to say, in addition to saying this:
my_table["my_func"] = my_func
You could also say this:
my_table[my_func] = "my_func"
That way, when faced with a function whose name you don't know, my_table[unknown_func] should yield it's name. This only works with functions you've written yourself and explicitly added to the lookup table. You could probably write something to ease that for you...
function my_table:addfunc( func_name, func_body )
self[func_body] = func_name
end
The result would be my_table:addfunc( "foo", function print("bar") end )