lua-users home
lua-l archive

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


On Sun, May 14, 2006 at 09:36:26PM +0200, Mildred wrote:
> Hi,
> 
> I know in python it is possible to detect if a file is used as a module
> or used as the main programm. And if it is run as the main programm run
> a main function.
> Is it possible to do the same with lua ? I tried with some
> debug functions without success.

Check the stack height at the top of your file and set a flag. When
using the 'lua' binary, you're at the top level iff debug.getinfo(3)
== nil.

-- Jamie Webb