我有一个简单的Lua函数,我从一个修改另一个Lua文件中特定行的在线源中获取并修改了该函数。该函数似乎试图在我的控制台上弹出PANIC: unprotected error in call to Lua API (attempt to call a nil value)
时调用nil值。此函数由另一个C ++函数调用。我对Lua几乎没有任何经验,也不知道发生了什么。
剧本:
function ModLine(value, line)
print("Modding...")
local file = io.open("Image/DM2240_HighScore.lua", "r")
sContents = file:read() -- capture file in a string
file:close()
tContents = textutils.unserialize(sContents) -- convert string to table
--Print a specific line
print(tContents[line])
--Modify a specific line
table.remove(tContents, line) -- will remove line so we can insert the new line
table.insert(tContents, line, value) -- inserts value on line in the table.
--Convert table to string and save the file
sContents = textutils.serialize(tContents)
file = io.open("Image/DM2240_HighScore.lua", "w")
file:write(sContents)
file:close()
end
提前致谢!
编辑: 我检查了一些函数,发现问题出在这个函数中,
void LuaInterface::ModLine(const int value, const int line) {
cout << "Modded" << endl;
lua_getglobal(theLuaState, "ModLine");
lua_pushinteger(theLuaState, value);
lua_pushinteger(theLuaState, line);
lua_call(theLuaState, 2, 0);
}