【问题标题】:lua function attempt to call global (a nil value)lua 函数尝试调用全局(一个 nil 值)
【发布时间】:2018-07-11 11:52:07
【问题描述】:

我是 lua 新手,我正在尝试制作一个接收文档并输出表格的函数,但我收到了上述错误。为什么??

io.write("How many documents are we evaluating? \nInput: ")
local total_documents=io.read("*n")
io.read()
local docTable = {}
inputDocument()

function inputDocument()
   local input
   local file
   local inputFile = {filename = nil, contents = nil, wordcount = nil}
   repeat
      io.write("Please enter document (filename.extension): ")
      input = io.read()
      file =io.open(input)
      if file == nil then
         print("File does not exist try again")
      end
   until(file ~=nil)
   inputFile.filename = input
   return inputFile
end

【问题讨论】:

    标签: function lua null global


    【解决方案1】:

    使用前需要定义inputDocument

    function inputDocument()
       ...
    end
    
    io.write("How many documents are we evaluating? \nInput: ")
    ...
    inputDocument()
    

    【讨论】:

    • 抱歉跑题了,@lhf,你能解释一下伊利丹在that 答案下的评论中描述的观察吗?
    猜你喜欢
    • 2014-05-06
    • 2014-11-05
    • 1970-01-01
    • 2019-03-01
    • 2013-12-15
    • 1970-01-01
    • 2019-06-13
    • 2017-04-03
    • 2019-08-21
    相关资源
    最近更新 更多