背景:
我正在尝试自学 Lua,但我很难理解为什么当一个表里面有数据时它被认为是 nil。谁能帮我分析一下,为什么我会从下面的代码片段中收到此错误消息?这是我的第一个程序之一,在开始我的实际项目之前,我真的需要了解这些概念。谢谢!
错误信息:
C:\Users\<user>\Desktop>lua luaCrap.lua
lua: luaCrap.lua:7: attempt to call global 'entry' (a nil value)
stack traceback:
luaCrap.lua:7: in main chunk
[C]: ?
代码:
--this creates the function to print
function fwrite (fmt, ...)
return io.write(string.format(fmt, unpack(arg)))
end
--this is my table of strings to print
entry{
title = "test",
org = "org",
url = "http://www.google.com/",
contact = "someone",
description = [[
test1
test2
test3]]
}
--this is to print the tables first value
fwrite(entry[1])
--failed loop attempt to print table
-- for i = 1, #entry, 1 do
-- local entryPrint = entry[i] or 'Fail'
-- fwrite(entryPrint)
-- end