[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Function Source
- From: Matthew Paul Del Buono <delbu9c1@...>
- Date: Mon, 15 Sep 2008 18:03:17 -0400 (EDT)
> I'm looking for a way to get the source string of a
> function from Lua, but I'd rather not have to parse
> it myself.
>
> Using the debug library, I see that I could get the
> source filename, and line numbers of where the
> function was defined...But I was hoping there was a
> way for me to ask the debug library to give me
> exactly the string that was used to define the
> function, and nothing more. This would only be for
> named functions.
>
You will find that debug.getinfo() does have the source used to create the chunk when you use loadstring()
> loadstring[[function foo() print("Hello World!"); end; function bar() end]]() print(debug.getinfo(foo).source)
function foo() print("Hello World!"); end; function bar() end
However this isn't quite what you asked for. It may be a usable workaround, though. If not, I don't think that it should be incredibly difficult to add in (though it seems too expensive to me for something that would be provided in Vanilla Lua)
Regards,
-- Matthew P. Del Buono