簡體   English   中英

嘗試調用全局 function 為 nil,但調試器中未顯示 function?

[英]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 - 嘗試調用全局“包含”(零值)

當我在調試器中查看它時,解釋器似乎沒有找到我在commandSystemcommandHelp之間定義的任何方法。 它在變量區域中相互顯示 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM