我目前正在尝试更新 Dungeon Crawl: Stone Soup 中使用的 Lua 版本,由于 luaL_openlib 函数被大量使用并且已被弃用,因此我遇到了问题。目前,我将其替换为以下代码(根据位置使用不同的参数):
//luaL_openlib(ls, nullptr, lr, 0); //OLD CALL
//New call
lua_getglobal(ls, "NULL");
if (lua_isnil(ls, -1)) {
lua_pop(ls, 1);
lua_newtable(ls);
}
luaL_setfuncs(ls, lr, 0);
lua_setglobal(ls, "NULL");
代码全部编译,但是当我尝试运行游戏时,出现以下错误:
./crawl
/mnt/d/Google Drive/Jon/UK/Spring 2021/CS 498/Crawl/crawl/crawl-ref/source/dat/des/00init.des:18: ...CS 498/Crawl/crawl/crawl-ref/source/dat/dlua/dungeon.lua:255: global 'setfenv' is not callable (a nil value)
任何人都可以就为什么会发生这种情况提供任何建议,或者任何人都可以就替换所有对 luaL_openlib 的调用的更好方法提供建议吗?我正在处理的代码可以在这里找到,并且在提交中它显示了我为更新对 luaL_openlib 的引用所做的所有最新更改。
编辑: 正如评论中提到的,这里是 dungeon.lua 中实际引发错误的代码:
-- Given a list of map chunk functions, runs each one in order in that
-- map's environment (wrapped with setfenv) and returns the return
-- value of the last chunk. If the caller is interested in the return
-- values of all the chunks, this function may be called multiple
-- times, once for each chunk.
function dgn_run_map(...)
local map_chunk_functions = { ... }
if #map_chunk_functions > 0 then
local ret
if not g_dgn_curr_map then
error("No current map?")
end
local env = dgn_map_meta_wrap(g_dgn_curr_map, dgn)
for _, map_chunk_function in ipairs(map_chunk_functions) do
if map_chunk_function then
ret = setfenv(map_chunk_function, env)()
end
end
return ret
end
end