RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

cdefDebugDraw ReferencecdefGpuMesh ReferencecdefImgui ReferencecdefMath Referencecdefs ReferencecontrolSystems Referencecsvlib ReferencedelayLine Referencedequeue ReferencedevUtils ReferenceEvent Referenceextensions Referencefilters Referencegraphpath Referenceguihooks ReferenceinputFilters ReferenceinterpolatedMap Referenceintrospection ReferencejbeamWriter Referencejson-ast Referencejson ReferencejsonDebug ReferencejsonPrettyEncoderCustom Referencekdtreebox2d Referencekdtreebox3d Referencekdtreepoint3d Referencelpack ReferenceluaBinding ReferenceluaCore ReferenceluaProfiler Referencemathlib Referenceparticles Referencequadtree Referencesettings ReferencetcpServer ReferencetimeEvents Referenceutils Reference

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API Referencecommon

luaBinding Reference

Module defined in `lua/common/luaBinding.lua`. Core C++/Lua binding infrastructure implementing property getters/setters, inheritance chains, and SimObject field access for engine-bound classes.

Module defined in lua/common/luaBinding.lua. Core C++/Lua binding infrastructure implementing property getters/setters, inheritance chains, and SimObject field access for engine-bound classes.


Exports

All exports are global functions (called by the C++ binding system).

Functions

__luaBindIndex(t, k)

Metatable __index handler for C++-bound instance objects. Searches: metatable → getters → super chain.

  • Parameters:
    • t - userdata - The bound object
    • k - string - Property/method name

__luaBindIndexStatic(t, k)

Metatable __index handler for C++-bound static classes. Similar to __luaBindIndex but calls getters without self.

__luaBindNewindex(t, k, v)

Metatable __newindex handler for C++-bound instance objects. Searches setters in current and super metatables.

  • Parameters:
    • t - userdata - The bound object
    • k - string - Property name
    • v - any - Value to set

__luaBindNewindexStatic(t, k, v)

Metatable __newindex handler for static classes (no self parameter).

__finalizeLuaBindings(classes, luaVMname)

Called after all C++ classes are registered. Optimizes metatables: flattens SimObject hierarchies, sets up field accessors, removes unnecessary indirection.

  • Parameters:
    • classes - table - Map of class names to metatable tables
    • luaVMname - string - Lua VM type (e.g., "vlua", "game")

testBindings()

Unit test for the binding system using TestNamespace.TestClassA/B.

Internal Notes

  • Metatable structure: mt[1] = getters table, mt[2] = setters table, mt[3] = super metatable
  • Getter/setter functions are cached in the origin metatable after first lookup for O(1) subsequent access
  • SimObject types (identified by isSubClassOf and key starting with 'd') get special handling:
    • Flattened metatable (all super methods/getters merged)
    • Custom __index/__newindex that falls through to getStaticDataFieldbyName/getDynDataFieldbyName
    • Fields mt[4-7] store data field accessor functions
  • Optimization pass: when a class has no super, no getters, or no setters, unnecessary metatable entries are removed
  • Function names are hardcoded and must not be changed (referenced from C++)

lpack Reference

Module defined in `lua/common/lpack.lua`. Fast Lua de/serializer supporting three formats: packed text, binary (using `string.buffer`), and Lua source. Handles tables, numbers, strings, booleans, vec3

luaCore Reference

Module defined in `lua/common/luaCore.lua`. Adds core language features and polyfills used throughout the codebase - optional require, module reload, table utilities, and FFI initialization.

On this page

ExportsFunctions__luaBindIndex(t, k)__luaBindIndexStatic(t, k)__luaBindNewindex(t, k, v)__luaBindNewindexStatic(t, k, v)__finalizeLuaBindings(classes, luaVMname)testBindings()Internal Notes