lua-users home
lua-l archive

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

OK I looked more closely at the debug API and ran an experiment.

If I have this:

return {

        _onA_ = function(x)
            return doSomething(x)

        _onA_ = function(x)
            return doSomethingElse(x)
        _onB_ = function(x)
            return doAnotherThing(x)


Then if I store the result in t, and I use debug.getinfo(t[1].onA, 'L'), I get info.activelines containing keys which are the "valid" lines of the function. In this case, they are the two lines containing "return doSomething(x)" and "end,".

If I make the assumption that the first line of the function immediately precedes, then I can tell which are the original source file lines containing the function. I can use those to recover the source code for each function.

I think this would be good enough for my needs.

However, if I provide flag 'S' I get fields 'lastlinedefined' ("end,") and 'linedefined' ("_onA_ = function(x)") which is perfect.

'S' also has fields 'source' and 'short_src' which I thought might contain the actual source code of the function, but they just have the name of the file. Otherwise that would be even more convenient.

So the solution is to use 'S' to get the first and last defined line number for each handler function, then extract them from the original source file when round-tripping.


On Fri, Nov 8, 2013 at 6:39 PM, Paul Merrell <> wrote:
On Fri, Nov 8, 2013 at 11:13 AM, Marc Lepage <> wrote:

> I'm going to take a crack at some kind of solution this weekend, so keep the
> ideas flowing.

I misunderstood and thought you wanted to create a new file each time.
Given that you're writing back to the same file, you could park the
functions in a library file and load the functions using dofile.


[Notice not included in the above original message:  The U.S. National
Security Agency neither confirms nor denies that it intercepted this