In this post, I used "<>" symbol to denote something arbitrary. Start by reading the syntax of Lua error. Lua error is usually have syntax like this:
<filename>:<lineNumber>: <message>
<filename> is the script file. <lineNumber> is line number where it occured. That's very easy to remember, right? Now for the error message. The error message is usually very descriptive but sometimes it doesn't really tell you what exactly is wrong, so here are some lists of Lua errors that I'm aware of. If your Lua error is unlisted, that can mean I didn't add it yet or it's thrown by external program.
- attempt to call global '<name>' (a <non-function> value)
This caused when you're trying to call a global variable called '<name>' but '<name>' is not a function type. Example
print() -- works table() -- attempt to call global 'table' (a table value) _VERSION() -- attempt to call global '_VERSION' (a string value) anilvalue() -- attempt to call global 'anilvalue' (a nil value)
- attempt to call field '<field>' (a <non-function> value)
Similar to above, but this occurs when you try to call something within a table.
-- Note that 'math' is a global variable which is table math.abs(123) -- works math.pi() -- attempt to call field 'pi' (a number value)
- bad argument #<n> to '<name>' (<type1> expected, got <type2>)
This is caused when a function '<name>' expects value with type <type1> for n-th argument, but user passed something with type <type2> instead.
-- io.open expects string for the 1st argument local file = io.open(io.open) -- bad argument #1 to 'open' (string expected, got function) -- tonumber 2nd argument expects number if present tonumber("0xFF") -- works tonumber("0xFF", table) -- bad argument #2 to 'tonumber' (number expected, got table)
- table index is nil
To be honest, this is most undescriptive Lua error message. What it means that you try to assign a value to a table at index "nil" (I mean literal nil).
table[nil] = io -- table index is nil
- bad argument #<n> to '<name>' (invalid option '<something>')
This means you passed invalid option. Notable function that throw this is 'collectgarbage' and 'file:seek'.
print(collectgarbage("count")) -- works collectgarbage("asd") -- bad argument #1 to 'collectgarbage' (invalid option 'asd')
... unless you got a very rare "PANIC" error which is unhelpful. No, really.