lua-users home
lua-l archive

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


If I define a function thus:

foo = function()
       print("foo called")
end

Then set

bar = foo

Is there any way later in the execution of the program that I can
retrieve the source Lua code of foo from bar?

If you need to save the function back to disk, and don't care about
readability, look at string.dump()
(http://www.lua.org/manual/5.1/manual.html#pdf-string.dump).

If you need readability, you probably should use debug.getinfo(), it
provides some source file/line information. But you'll need to have
foo source text at hand, and would have to not strip debug information
from the compiled code.
(http://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo)

HTH,
Alexander.