Closed ojb500 closed 2 years ago
After some more investigations I found that this should assign to the local:
local f
function g()
function f()
return 'Hello'
end
end
g()
print(_G['f'] == nil) -- expected 'true'
print(f()) -- expected 'Hello'
So we should be able to assign a function to a local variable in any enclosing scope.
I will take a closer look on this, in the next days. But it looks really good.
Thank you!
Thank you. Good job.
I pushed a prerelease, for tests.
Hi @neolithos
I had some problems with forward-declaration of local functions like this:
This is required to support local mutual recursion. Similar code is given as an example in Programming in Lua and this seems to work ok in luac 5.3.3: https://www.ideone.com/JD0aKj
I think I have fixed this by being able to assign to an existing local when parsing a
function
statement.This change also means that local functions can be redeclared, which wasn't possible before:
Now a
function
statement will not escape into the global scope if we have a local:The only thing I'm not sure about is if it is correct to pass
true
toscope.LookupExpression
, or whether we could also bind to a local in a deeper scope.Thank you @neolithos for your work on this excellent project!
best regards
Oliver