-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to make exported module non-global? #135
Comments
Please see the readme: https://github.com/SteveKChiu/lua-intf#integrate-with-lua-module-system |
I am not making a dll/so.
|
Shall I do it like this: int main()
{
...
LuaRef mod = LuaRef::createTable(L);
LuaBinding(mod).beginModule("c_util")
.addFunction("foo", []() { return 123; })
.endModule();
// set package.preload['c_util'] = mod to allow lua "require('c_util')"
LuaRef table(L, "package.preload");
table["c_util"] = mod;
...
} |
"package.preload" is a table of functions, thus you need to assign function, not module (which is table) https://github.com/SteveKChiu/lua-intf#integrate-with-lua-module-system And assume the module function is "open_my_module" (renamed from luaopen_modname example), all you need to do is:
|
Thanks. Let me try it. |
It works. From "Programming in Lua 3ed":
|
This makes c_util global.
Is there any way to make it not global, so I can use it like this?
The text was updated successfully, but these errors were encountered: