尝试调用全局函数为nil,但在调试器中未显示函数?

我正在使用Eclipse LDT进行开发,使用打包的Lua EE和Lua 5.2解释器。我需要从我的主方法调用commandDatabase()方法,但是当我尝试时,我收到错误:

"尝试调用全局'commandDatabase'(一个nil值)"。

我已查看此错误,并且根据我所知,使用正确的顺序定义方法。 Lua - 尝试调用全局'contains'(一个nil值)

当我在调试器中查看它时,解释器似乎找不到我在commandSystemcommandHelp之间定义的任何方法。在变量区域中显示每个其他函数,例如["commandSystem"] = function(),但是commandDatabase()不会出现

我尝试通过以下方式调用包装器方法:

function commandDatabaseStep()
  return commandDatabase()
end

...但这也没有起作用(相同的错误)

相关代码:


--系统命令
function commandSystem()
  ...
end

--数据库命令
function commandDatabase()

  如果arguments [2]=="no_arg1" then
    print"'database'命令必须至少有一个参数:[生成,擦除,转储,删除,get)<system_name>] ",真实的)
    返回2

  elseif arguments[2]=="generate" then
    local file = io.open(database,"w +")
    file:write"#ssmhub数据库")
    file:close(file)
    返回1

  elseif arguments [2]=="dump" then
    print"=转储开始="for line in io.lines(database)do
      print(line)
    end
    print"= TRANSFER END =")
    返回1

  - 1 + -
  elseif arguments [2]=="get" then

    - 2 + -
    如果isEmpty(arguments [3])则
      print"'database get'命令必须具有\u003cname\u003e参数")
      返回0
      - 2- 
    别的-- 3 +
      local file = io.open(database,"r ")

      对于line in io.lines(file)do-4 +
        local state = ""
        local id = ""
        local dividersFound = 0

        line:gsub"。"functionc) - 5 +

          如果c == "| "则-6 +

            如果dividersFound == 0 then -7 +
              state = state .. c
        end - 7- 
            如果dividersFound == 1 then-- 8 +
              id = id .. c
        end - 8- 
            dividersFound = dividersFound +1

          end - 6- 

         end) - 5 - 

        io.close(文件)

      end-4- 
    end-3- 
  别else-- 9 +
      print(“命令的非法参数。使用'help'获取命令和参数列表。”)
      返回0
    end - 9 -
  end- 2 -
end- 1 -

function commandHelp()
  ...
end

-- Main
function main()
  arguments = readProgramArguments()

  commandArgument = arguments [1]

  commandCompleteCode = 0

  --处理帮助和系统命令

  如果commandArgument == "database"则
    commandCompleteCode = commandDatabase()
  end
end main() 
点赞
用户13111872
用户13111872

正如 @luther 指出的那样,在 commandDatabase 中我有一个多余的 end-s

这在我的 IDE 中没有被标记,因为我没有把 commandSystem 完全闭合,所以 commandSystem 嵌套在其中。

解决方法:在 commandSystem 中添加一个 end,并删除我标记为“-- 1-”的 end

2021-01-08 12:56:52