[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Function source
- From: alan@... (Alan Watson)
- Date: Sat, 20 Dec 1997 19:08:05 -0600
I have been thinking about writing a replacement for lua_getobjname
that scans tables recursively as well as globals. I want to use this
to print better function names in error messages.
It just occured to me that a nicer alternative would be very simple
with the kind of function method that has been discussed. What I would
do is extract the function name of a function as it is compiled, and
keep a table of these names; lua_getobjname becomes, for functions at
least, a simple table access.
Actually, I would not need quite such a general function method.
Anticipating 3.1, I could do with one that took a function name and a
closure, so that:
function aaa (...) ... end
function aaa.bbb (...) ... end
function aaa.bbb.ccc (...) ... end
would become:
functionmethod(function (...) ... end, "aaa")
functionmethod(function (...) ... end, "aaa", "bbb")
functionmethod(function (...) ... end, "aaa", "bbb", "ccc")
The draw backs that I can see are that functions would then never be
garbage collected and, I think, my method would never see functions
defined in pre-compiled chunks.
Just a thought.
Alan