lua-users home
lua-l archive

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


On Feb 26, 2018, at 12:46 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

> I must confess I do not understand what "fail-proof method" means in this
> discussion.

my guess to a fail-proof method is similar to python:

if __name__ == '__main__':
   print "running code standalone"

my lua equivalent:

if not package.loading "mod" then
   print "running code standalone"
end

> If someone does 'loadfile "mod.lua" "mod"', it seems clear it wants
> to mimic 'require'. What is wrong with that?

I would guess that he did not wanted to mimic require.
Otherwise, he would do (require "mod").func "mod"

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"


> I can understand the need for a "fool-proof" method, instead of a
> "fail-proof" method. So, will anyone do 'loadfile "mod.lua" "mod"'
> without noticing the extra unrequested argument? Would that be
> a realistic concern?
> 
> -- Roberto

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