lua-users home
lua-l archive

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

On Feb 26, 2018, at 2:35 AM, Dirk Laurie <> wrote:

> 2018-02-26 5:43 GMT+02:00 Paul K <>:
>>> what if later versions of dofile allow optional command-line args ?
>> We'll cross this bridge when we get there. For now this logic should
>> work with all Lua 5.1+ versions.
> Why is it better to use debug.getlocal than "'..."?

using ... from unknown source is dangerous, ... can be anything

A.lua: loadfile "B.lua" "A"  -- running B standalone
          if package.loading(...) then print "requiring A" else print "standalone A"end

B.lua: if package.loading(...) then print "requiring B" else print "standalone B" end

lua> require "A"
requiring "B"   -- wrong !!! tested package.loading "A"
requiring "A"

-- replaced (...) with actual modname, we get
lua> require "A"
standalone B
requiring A