lua-users home
lua-l archive

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

>Is there a (preferred) way to determine inside a script what file it was
>loaded from? 

Yes, use "getinfo(1)". This returns a table.  The "source" field contains
the file name (after a '@'). See below:

$ cat i

$ lua i
what    main
linedefined     0
nups    0
currentline     1
source  @i
short_src       file `i'
func    function: 0x80604c8

>Somewhat related, is there a way to mimic Python's "if name=='__main__'"?

Same answer. Check whether the field "what" is "main", as above.

The manual says that "getinfo" is part of the debug API and that you should
avoid it. I think that using it for information purposes is ok (ie., avoid
"setlocal"!). Perhaps we can change the wording in the manual.