[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Modules with standalone main program
- From: albertmcchan <albertmcchan@...>
- Date: Sat, 24 Feb 2018 19:07:42 -0500
On Feb 24, 2018, at 6:03 PM, Paul K <email@example.com> wrote:
> Hi Dirk,
>> I.e. "doflile" is treated just like "require'.
>> I want "require" to return and all other ways of running the file to continue.
> It wasn't clear from your question that you want to distinguish
> between require and dofile calls, but it shouldn't be too difficult to
> if pcall(debug.getlocal, 4, 1) then
> if select('#', ...) == 0 then
> print("dofile package")
> print("require package")
> print("main script")
why does dofile package have zero argument ?
without actually testing for require "mod.lua", it seems kinda leap of faith.
P.S. just noticed a bug in require, it will accept false from mod.lua
as valid value, defeating the purpose of package.loaded cache table
--> fix: patched require to use false as sentinel, with a guarantee
that package.loaded.mod always eval to true (after require)
--> new test for require "mod", invalid false as sentinel
if package.loaded.mod == false then return mod_func end