[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Script filename introspection
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 21 Feb 2001 08:42:10 -0300 (EST)
>Is there a (preferred) way to determine inside a script what file it was
Yes, use "getinfo(1)". This returns a table. The "source" field contains
the file name (after a '@'). See below:
$ cat i
$ lua 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.