要求模块中的Lua注册表

在模块int luaopen_foo(lua_State*)中,键是否设置在临时状态的注册表中,并在调用状态的注册表中被采用?

例如,假设我们有这个模块:

int luaopen_foo(lua_State* state) {
    lua_pushstring("foo");
    lua_pushnumber(10);
    lua_settable(state, LUA_REGISTRYINDEX);
}

然后这个模块被 Lua 代码所需要:

require "foo"

foo是否在状态state的注册表中,被采用在调用状态的注册表中?

点赞
用户1118964
用户1118964

如果你想要的话,可以把这个写入一个 Lua 文件

foo = require "foo"
2014-06-14 08:19:40