[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Is there a similar way to do if __name__ == '__main__' as in python ?
- From: Niklas Frykholm <niklas@...>
- Date: Thu, 08 Feb 2007 09:14:08 +0100
I want to write lua modules and put some self testing
code at the end of the script which got executed only
if it is run as its own and not through "require".
In python, this is usually done through
if __name__ = "__main__":
How should I do it in lua ?
A dead simple but not very robust solution is
if arg == 'menu.lua' then
Slightly more robust:
if arg:match("[.%w]*$") == 'menu.lua' then
Replace "menu.lua" with the name of your file. Still not 100 % robust
(you could have files named menu.lua in different directories), but
maybe enough to cover your needs.