[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 15:15:29 -0500
I now know why require "mod" set package.loaded.mod to some userdata
the userdata "sentinel" is used to check for errors during require,
and provide a default true if mod.lua does not return anything.
we can use sentinel to test mod.lua currently being required:
patch: in loadlib.c luaopen_package()
< lua_pushlightuserdata(L, sentinel);
< lua_setfield(L, -2, "loading");
with above 2 lines patch, we can now do this:
if package.loaded.mod == package.loading then
return mod_func
end
-- code below for running stand-alone