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?  I'm trying to make scripts load what they need themselves,
so they become self-contained.  Python has __file__, while Tcl has [info
source] for this.  With that, one can do the equivalent of "dofile('../a-
file-next-to-this-one')", regardless of how the first script was loaded.

Somewhat related, is there a way to mimic Python's "if name=='__main__'"?
 This makes it easy to include tests and sample code in any source file,
yet also use the same file for loading common scripts needed in other
contexts.  One solution I can think of, is that if the first issue is
solved, then scripts can achieve this effect by having code of the form:
    if the_name_of_this_script==the_name_of_the_main_script then
      ... tests, demos, etc ...
    end

-jcw