Tuesday, 27 August 2013

Lua source code manipulation: get innermost function() location for a given line

Lua source code manipulation: get innermost function() location for a
given line

I've got a syntactically correct file with Lua 5.1 source code.
I've got a position (line and character offset) inside that file.
I need to get an offset in bytes to the closing parenthesis of the
innermost function() body that contains that position (or figure out that
the position belongs to the main chunk of the file).
I.e.:
local function foo()
^ result
print("bar")
^ input
end
local foo = function()
^ result
print("bar")
^ input
end
local foo = function()
return function()
^ result
print("bar")
^ input
end
end
...And so on.
How do I do that robustly?

No comments:

Post a Comment