Jump to content

JLuaVM

From Advanced Computers Wiki
Revision as of 12:17, 22 August 2026 by GHXX (talk | contribs)

The JLuaVM, is the runtime that executes the Lua code that is running on computers in Advanced Computers. The source can be found on GitHub. While we try to keep things very similar, there are a few tiny differences, listed below. In the remainder of this article, LuaC refers to PUC-Rio's implementation of Lua.

LuaC deviations

In these cases JLuaVM (referred to as 'we') behaves differently than LuaC, but we still fulfill the Lua specification.

Area Description
Indexing of strings In LuaC indexing a string, where the index value someIndex can be an arbitrary value, always evaluates to nil. We argue that this is inconsistent and is almost never wanted behaviour. Therefore we instead throw an error just like indexing any other non-indexable type.
("someString")[someIndex]
Length of strings We intentionally return the number of characters instead of the length in bytes.
assert Produces a slightly different error message. Further, the message argument (second argument) is tostring()'ed before printing. This means that when the second argument happens to be a boolean, we properly print the value instead of simply stating that it was a boolean.
assert(false, true)
ipairs In our case, ipairs only allows iterating over tables. LuaC would return nil when operating on a string and error when passing a type that is neither a string nor a table. For robustness we throw on all non-table arguments as it seems very unlikely that a string is passed intentionally.
pairs The order in which the items are returned may differ from LuaC.
table.insert In LuaC this function seems to behave differently depending on whether the table is a sequence or an actual dictionary. In our case table.insert behaves identical in both cases.
table.remove behaviour differs slightly as the table-length operator behaves differently.
Printing numbers We print numbers with a few more digits of precision.
Stacktraces are formatted differently Due to the lack of a loadfile function, the chunkname is directly fed into stacktraces, allowing for specifying filenames, etc. without being surrounded by quotes. Also some things are named slightly different within the stacktrace. This indirectly also affects the error(msg [, level]) function when msg is directly a string and level == nil or level > 0, and thus, part of the stacktrace is appended.

Lua language spec deviations

Lua language spec extensions