Hi, I have a question about what happens internally, when variables are declared without actually assigning a value, e.g., if I have a function like
function myfunc() local x end
does this actually create a variable or does it just tell the compiler “Should a variable x be accessed within this scope, it should be a local variable” ?
After all, if I try to access this variable, e.g., by
function myfunc() local x x end myfunc()
I obtain an
UndefVarError, which indicates that the variable has not actually been declared.
The fact that the actual position of
local x in the method does not play a role seems to support this thesis, i.e., that the following code still throws an error:
x = 2 function myfunc() x local x end myfunc()
Maybe I am lacking some understanding here. I would appreciate any clarifications that help understanding what is actually happening under the hood.