lua-users home
lua-l archive

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


On 21/09/2014, at 7:15 pm, Philipp Janda <siffiejoe@gmx.net> wrote:

> Am 21.09.2014 um 04:45 schröbte Ashish Ranjan:
>> FEATURE REQUEST: In python , we have a construct
>>         if __name__ == “__main__”:
>> so that if a module .lua file is executed by itself then this code block executes, but if this module is imported(required() as in lua) by other script file, then this code blosk is not executed.
>> Can we have this construct in lua. This will be an important step in life of a lua module.
> 
> Can already be done, e.g. like this[1]. I don't like the idea of an extra special upvalue, and the chunk arguments are already used in both cases ...

I use this:

if arg and debug.getinfo(1, "S").short_src == arg[0] then
  …
end

But your code makes me wonder if it isn’t sufficient just to check the depth of the stack?