バックグラウンド:
Lua を独学しようとしていますが、データが含まれているときにテーブルが nil と見なされる理由を理解するのに苦労しています。以下のコード スニペットからこのエラー メッセージが表示されるのはなぜですか? これは私の最初のプログラムの 1 つであり、実際のプロジェクトに移る前に、これらのいくつかの概念を理解する必要があります。ありがとう!
エラーメッセージ:
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