About Lua

Lua use two type of Virtual Machine, one for the Game Engine and one per vehicles.

Modules that are in the common folder and C++ bindings are available for both.

How to Code

Lua 5.3 reference manual

Lua Terms

  • Array: A Lua table that contains only integer keys from 1 to infinity. Can be counted correctly with #tbl
  • Dictionary (dict): A lua table that contains all kinds of keys. Cannot be counted with #tbl.
  • Module: The traditional Lua module is deprecated. Do not use it
  • Package: the normal Lua package. Used, but please use Extensions if possible. See also here. See here also.
  • Extensions: BeamNG’s module system. Includes serialization, events and Lifetime management.

Lua Syntactic Sugar

tabl.ident is equivalent to tabl['ident']
v:name(args) is syntactic sugar for v.name(v,args)
func{fields} is syntactic sugar for func({fields})
func'string' (or func"string" or func[[string]]) is syntactic sugar for func('string')
function t.a.b.c:foobar(params) body end is syntactic sugar for t.a.b.c.foobar = function(self, params) body end

Lua code style

  • Folder naming example: ge/someFolderHere/lowerCamelCase/
  • File naming example: lowerCamelCase.lua
  • Indenting: 2 spaces (not tabs)
  • Trim trailing spaces ON
  • Function and variable names, camelCase
  • “Class” names, upper camel case (PascalCase), example: MyCoolClass

Vehicle Scripting Classes and Functions