lua-users home
lua-l archive

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




2015-01-21 16:18 GMT-08:00 Dibyendu Majumdar <mobile@majumdar.org.uk>:
Hi,

Is my understanding correct that luaY_parser() creates an implicit
function to wrap all the code it parses?

Yes. And that function is named "chunk".

Lua document section 3.3.2: Lua handles a chunk as the body of an anonymous function with a variable number of arguments (see §3.4.11).
 
Thus an assumption is that
LexState is used for a single parse of a function - which may of
course contain function definitions within.

Sort of. But I think a "chunk" is a "chunk". You could consider it as a function in some contexts. But there are always subtle differences between chunks and functions in certain contexts. LexState is too vague a context here. And I don't see any conceptual advantage here to consider a chuck a function in terms of the purpose of LexState.
 

Another question I have is to do with lexical scopes of variables
within the parse run.  Can I assume that LocVar.startpc and
LocVar.endpc define the boundary within where a particular variable is
available - and that if LexState.dyd contains a reference to a
variable register then the corresponding variable scope is as defined
in LocVar?

Maybe I'm wrong. I think "startpc" and "endpc" are mainly, if not completely, for debugging information. They reflect the effective scope of a local variable. But you could hardly say they "define" one. The scope of local variable is defined by FuncState::nactvar, BlockCnt:: nactvar, and the generated code that maintaining Lua stack.
 

Lastly I have tried to document in the link below my understanding of
the expdesc structure's state transitions - would appreciate if any
errors in my description are highlighted so that I can correct them.

https://github.com/dibyendumajumdar/ravi/wiki/Lua-Internals


Thanks and Regards
Dibyendu