Possible Duplicate:
“main” function in Lua?
In Python, you can check if a script is being called direcly (and call some functions if it is, usually for testing) pretty easily:
if __name__ == "__main__":
main()
Is there a way to do the same in Lua, to detect if it is run directly (lua foo.lua) or included in another script (dofile('foo.lua')).
There is always the trivial (and ugly) way of defining some dummy global variable in the main script file before dofile('foo.lua'), and checking in foo.lua if it is defined or not, but it would be great if there was a better way to do this.
At the top level you can check if
debug.getinfo(2)is nilFrom http://www.lua.org/manual/5.1/manual.html#pdf-debug.getinfo