lua函数尝试调用global(零值)

时间:2018-02-01 08:03:38

标签: function lua null global

我是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

1 个答案:

答案 0 :(得分:1)

您需要在使用之前定义inputDocument

function inputDocument()
   ...
end

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