lua-users home
lua-l archive

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

On Feb 24, 2018, at 9:05 AM, "Soni \"They/Them\" L." <> wrote:

> Why does nobody support renaming modules, it's 2018 :(
> local function compareargs(...)
>     local vargs = table.pack(...)
>     for i=1,vargs.n do
>         if arg[i] ~= vargs[i] then return false end
>     end
>     return true
> end
> if package.loaded[...] and not compareargs(...) then -- be nice to ppl
>     -- (probably? with about a 99.999% chance) loaded from require
> else
>     -- do whatever you want just don't screw with the [...] above >.>
> end
> -- 
> Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.

I got an idea to take care of remaining 0.001% case.

have require set package.loaded.mod to false before it were fully loaded.
(it were currently set to some userdata anyway)

if package.loaded.mod == false then
  -- loading from require, but not yet finish ...
  -- standalone program

so, even if lua had mod.lua "require" by default, above
can test for mod.lua running as stand-alone program