[英]Attempt to call global function is nil, but function is not shown in debugger?
我正在使用 Eclipse LDT 进行开发,使用打包的 Lua EE 和 Lua 5.2 的解释器。 我需要从我的 main 方法调用commandDatabase()
方法,但是当我尝试时,我收到错误:
“尝试调用全局‘commandDatabase’(一个零值)”。
我已经查看了这个错误,据我所知,我正在以正确的顺序定义方法。 Lua - 尝试调用全局“包含”(零值)
当我在调试器中查看它时,解释器似乎没有找到我在commandSystem
和commandHelp
之间定义的任何方法。 它在变量区域中相互显示 function 例如["commandSystem"] = function()
但commandDatabase()
没有出现
我试过像这样调用包装器方法:
function commandDatabaseStep()
return commandDatabase()
end
...但这也不起作用(同样的错误)
相关代码:
-- System command
function commandSystem()
...
end
-- Database command
function commandDatabase()
if arguments[2] == "no_arg1" then
print("The 'database' command must have at least one argument: [generate, wipe, dump, delete, get <system_name>]", true)
return 2
elseif arguments[2] == "generate" then
local file = io.open(database, "w+")
file:write("#ssmhub database")
file:close(file)
return 1
elseif arguments[2] == "dump" then
print("= DUMP START =")
for line in io.lines(database) do
print(line)
end
print("= DUMP END =")
return 1
-- 1+
elseif arguments[2] == "get" then
-- 2+
if isEmpty(arguments[3]) then
print("The 'database get' command must have a <name> parameter")
return 0
-- 2-
else -- 3+
local file = io.open(database, "r")
for line in io.lines(file) do -- 4+
local state = ""
local id = ""
local dividersFound = 0
line:gsub(".", function(c) -- 5+
if c == "|" then -- 6+
if dividersFound == 0 then -- 7+
state = state .. c
end -- 7-
if dividersFound == 1 then -- 8+
id = id .. c
end -- 8-
dividersFound = dividersFound + 1
end -- 6-
end) -- 5-
io.close(file)
end -- 4-
end -- 3-
else -- 9+
print("Illegal argument for command. Use 'help' for a list of commands and arguments.")
return 0
end -- 9-
end -- 2-
end -- 1-
function commandHelp()
...
end
-- Main
function main()
arguments = readProgramArguments()
commandArgument = arguments[1]
commandCompleteCode = 0
-- Process help and system commands
if commandArgument == "database" then
commandCompleteCode = commandDatabase()
end
end main()
正如@luther 指出的那样,我在commandDatabase
中有一个太多的结尾。
这没有在我的 IDE 中标记,因为我没有结束commandSystem
,所以commandSystem
嵌套在其中。
修复:在commandSystem
添加一个结尾,并删除我标记为“-- 1-”的结尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.