lua-users home
lua-l archive

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


2018-02-26 16:10 GMT+02:00 albertmcchan <albertmcchan@yahoo.com>:
> On Feb 26, 2018, at 2:35 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>
>> 2018-02-26 5:43 GMT+02:00 Paul K <paul@zerobrane.com>:
>>>> 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

All of whch TL;DR attempts to demonstrate why "..." may fail, but does
not answer my question, which is "why is debug.getlocal better?"