lua-users home
lua-l archive

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


On Feb 24, 2018, at 3:30 PM, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:

> albertmcchan> I now know why require "mod" set package.loaded.mod to
> albertmcchan> some userdata
> 
> 5.1 does this, but 5.2+ do not.
> 
> -- 
> Andrew.

I just read require implementation (in lua) for lua 5.1 and 5.2

https://github.com/pygy/require.lua/blob/master/require.lua

lua 5.2 does not use sentinel, and does less error checking.
From inside mod.lua, there is no way to know if it were "required"

I guess this is a lua 5.1 "feature":

-- lua 5.1 test for require "mod" inside mod.lua

if package.loaded.mod then return mod_func end