[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 16:56:05 -0500
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