lua-users home
lua-l archive

Re: Modules with standalone main program

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


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

AltStyle によって変換されたページ (->オリジナル) /