lua-users home
lua-l archive

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


> 
> if __name__ == '__main__':
>    print "running code standalone"
> 
> my lua equivalent:
> 
> if not package.loading "mod" then
>    print "running code standalone"
> end

This looks like a fail to me:

  package.loading = function () return true end; dofile("mod.lua")


> It is more likely some code not meant to be cached, and he
> wanted to run the stand-alone code.  Example:
> 
> lua> loadfile "stat.lua" "stat"  -- print statistics of file "stat"

The question is to know whether a *module* was called by require,
not a stand-alone code that expects regular arguments to work.
Why anyone would call that with 'require'?


> what is your recommendation for "fool-proof" method ?

What Dirk suggested since the beginning: check whether the first
argument is the module name.

-- Roberto