【发布时间】:2013-01-09 13:45:08
【问题描述】:
背景:
我正在尝试自学 Lua,但我很难理解为什么一个表在其中包含数据时被视为 nil。谁能帮我分析一下,为什么我从下面的代码 sn-p 中收到此错误消息?这是我的第一个程序之一,在开始我的实际项目之前,我真的需要了解这些概念。谢谢!
错误信息:
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
【问题讨论】:
标签: printing lua runtime-error null lua-table