我使用Eclipse LDT进行开发,使用打包的Lua EE和Lua 5.2的解释器。我需要从我的主方法调用commandDatabase()
方法,尽管当我尝试时,我收到错误:
"尝试调用全局"commandDatabase"(零值(;。
我已经查找了这个错误,据我所知,我正在以正确的顺序定义方法。Lua-尝试调用global';包含';(零值(
当我在调试器中查看它时,解释器似乎找不到我在commandSystem
和commandHelp
之间定义的任何方法。它在变量区域中显示每个其他函数,例如["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-"的端点。