lua-users home
lua-l archive

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


On Feb 24, 2018, at 2:46 PM, Paul K <paul@zerobrane.com> wrote:

>> Unfortunately, the conclusion was that there seems to be no fail-proof method.
> 
> I already suggested a method earlier that works with Lua 5.1+ and
> handles command line parameters as well as require/dofile calls:
> 
> if pcall(debug.getlocal, 4, 1) then
>  print("package")
> else
>  print("main script")
> end
> 
> Paul.
> 

can you elaborate what 4 and 1 mean ?

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)

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