RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Debug DrawingGPU Mesh StructsImGui FFIMath Structs (FFI)FFI C DefinitionsPID ControllersCSV LibraryDelay LineDequeDevelopment UtilitiesEvent ReferenceExtension SystemSignal FiltersGraph PathfindingUI BridgeInput Filter Constants2D Bilinear InterpolationIntrospectionJBeam Pretty PrinterJSON AST ParserSJSON ParserJSON Debug ParserJSON Pretty PrinterK-D Tree (2D Boxes)K-D Tree (3D)K-D Tree (3D)Lua SerializerC++/Lua BindingLua CoreLua ProfilerMath LibraryParticlesQuadtreeSettingsTCP ServerTimer SchedulerUtility Library

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

C++/Lua Binding

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++)

See Also

  • cdefDebugDraw Reference - Related reference
  • cdefGpuMesh Reference - Related reference
  • cdefImgui Reference - Related reference
  • Common Libraries Overview - Guide

Lua Serializer

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

Lua Core

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 NotesSee Also