lua-users home
lua-l archive

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

On Feb 24, 2018, at 6:03 PM, Paul K <> 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
> add:
> if pcall(debug.getlocal, 4, 1) then
>  if select('#', ...) == 0 then
>    print("dofile package")
>  else
>    print("require package")
>  end
> else
>  print("main script")
> end
> Paul.

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