[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Get Lua code from a function reference?
- From: "Alexander Gladysh" <agladysh@...>
- Date: Sun, 23 Jul 2006 18:13:28 +0400
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.