Typical Compiler Error Messages
The messages below are typical of errors you may commonly find in your scripts. These cases were obtained by perturbing the sample files for the CMyClass script. You can find these in the installed files [Mira]\Scripts\CMyClass Test.lua and [Mira]\Scripts\Classes\CMyClass.lua.
In the cases below, [...] refers to error-specific text that would appear in the actual message you receive.
[...] expected to close {
This occurs when the compiler encounters an extra { of a table (or class) definition or the class definition is missing an = sign for a class member. For example
`}' expected (to close `{' at line 20) near `s'
indicates that an error occurred when an unexpected s was encountered inside the table that began on line 20. In this case, the s was attached to the left of an = sign.
unfinished string near [...]
This occurs when the compiler encounters an extra " that is unmatched to end a string before the end of the file. For example,
23: `unfinished string near `"'
tells you that the string begun with " on line 23 was never terminated by another " character.
[...] expected near [...]
This error arises when Lua expects a particular keyword but encounters text that it does not recognize. For example,
14: `then' expected near `dthen'
tells you that line 14 has something else in place of the expected word then at the beginning of a block. Here is the problem:
if not CMyClass dthen should be if not CMyClass then
Here is another example:
14: `then' expected near `ot'
tells you that an unrecognized word ot was encountered on line 14. Here is the problem:
if n ot CMyClass then which should read if not CMyClass then
Lua interprets n as a test value that evaluates true or false, which must be followed by then to start a block.
= expected near [...]
This error arises when Lua thinks you are defining a variable, which would be followed by an = sign. The error usually means that you have misspelled a keyword before another token (which might itself be a keyword). For example,
`=' expected near `not'
identifies a problem in the word before not, since not is recognized as a standard Lua element. This error was caused by
ifn not CMyClass then which should read if not CMyClass then
Here is another example:
`=' expected near `ot'
This was caused by inserting the space between words at the wrong place.
ifn ot CMyClass then was supposed to read if not CMyClass then
attempt to call global [...]
This error is raised when there is an undefined variable name to the right of an = sign. Lua tries to interpret the token rightward of the equals sign as a global variable. If it is the name of a previously defined global, then you will have a script bug but no error message! Otherwise, the current error will be thrown.
For example,
attempt to call global `w' (a nil value)
was produced by
CMyClass = w { in place of the intended CMyClass = {
As noted in the error message, w is a nil value, This occurs because w has not been defined.
Here is another example:
attempt to call global `Printfs' (a nil value)
In this case, we misspelled the name of the global function Printf.
attempt to index global [...]
Whenever you see the word "index", think of a table. Indexing a global means that you are attempting to access a member of a table and that member has not been defined. In Lua, a class is actually a form of table, so this message might also indicate that the script has tried to reference a class name that has not been defined. The error may occur on the stated line number or it mat be on a prior line where the name was assigned to a class.
For example,
attempt to index global `CMyClass' (a nil value)
was caused by the class definition earlier in the script:
CMyClasss = followed by a function definition function CMyClass:new()
Notice that the class name is not spelled the same way in the class definition. When the compiler attempted to define the function it had not yet seen a class by the same name.
attempt to call global [...]
This error is raised when Lua attempts to call a function that has not been defined. For example,
attempt to call global `GetNumbefr' (a nil value)
Obviously, GetNumber was the intended function and GetNumbefr is not defined.
attempt to call field [...]
This error arises when the script references a field of a table and the named field does not exist. Usually, this refers to a package supplied with Lua, such as math or io. For example,
attempt to call field `gmax' (a nil value)
was caused by using the wrong function name from the math package:
math.gmax was used instead of the correct function name math.max
Compiler Error Messages, Overview of Mira Pro x64 Script
Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics,
Inc. All Rights Reserved.