lua-users home
lua-l archive

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


>I was wondering: is it possible to print the function name (in
>luac/print.c PrintHeader(...) ) when listing information (the current
>implementation only displays the starting line number of the function in
>the lua source file, but not the function name itself so you still need
>to look at the source and see what function you're actually looking
>at)..

Functions in Lua are really all anonymous.
A statement such as
	function f() ... end
is just sugar for
	f = function () ... end
as mentioned in the manual.

The only way to get the 'name' of the function is to look in the code at
the given line.
On the other hand, it may be possible to get the 'name' from the bytecode,
by looking at what comes after CLOSURE. If it's a SETGLOBAL or SETLOCAL,
then the name can be extracted. But this does not work for more complex
expressions, such as
	A[g(x)] = function () ... end
Early versions of luac did try to extract function names from the bytecode,
but it got too complicated.
--lhf