[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Modules with standalone main program
- From: albertmcchan <albertmcchan@...>
- Date: Sat, 24 Feb 2018 09:46:29 -0500
On Feb 24, 2018, at 9:05 AM, "Soni \"They/Them\" L." <fakedme@gmail.com> 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 ...
else
-- standalone program
end
so, even if lua had mod.lua "require" by default, above
can test for mod.lua running as stand-alone program