lua-users home
lua-l archive

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

>> if pcall(debug.getlocal, 4, 1) then
> can you elaborate what 4 and 1 mean ?

It checks if there is anything in the 1st variable at the 4th level,
which would be the caller of the current module (if required) or
nothing in the case of the main script.

> how does it know we are testing mod.lua being required (or not) ?
> and not testing for something else ?
> ("mod" is never mentioned in above test)

It doesn't care about the name of the module; it only checks the stack.

> the stand-alone program might also require some other modules, which
> also might require others ... does above work all the time ?