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

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

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, and quat.


Exports

Functions

M.encode(v)

Encodes a Lua value into a compact packed text format.

  • Parameters:
    • v - any - Value to encode (table, number, string, boolean, vec3, quat)
  • Returns: string - Packed encoding (starts with 'a')

M.decode(is)

Decodes a packed or binary-encoded string back to a Lua value. Auto-detects format.

  • Parameters:
  • Returns: table - Parsed result
  • Returns: any - Decoded Lua value

M.encodeBin(v)

Encodes a Lua value into binary format using string.buffer.

  • Parameters:
    • v - any - Value to encode
  • Returns: string - Binary encoding (starts with 'b')

M.encodeBinWorkBuffer(v)

Like encodeBin but returns the work buffer directly (avoids a string copy).

  • Parameters:
    • v - any - Value to encode
  • Returns: buffer - String buffer object

M.encodeLua(v)

Encodes a Lua value as valid Lua source code that can be loadstring'd.

  • Parameters:
    • v - any - Value to encode
  • Returns: string - Lua source string

M.decodeLua(s)

Decodes a Lua source string by executing it.

  • Parameters:
    • s - string|nil - Lua source (from encodeLua)
  • Returns: any - Decoded value

M.encodeDoubleArray(tbl)

Encodes a Lua number array as raw binary double array via FFI.

  • Parameters:
    • tbl - table - Array of numbers
  • Returns: string - Raw binary data (8 bytes per number)

M.decodeDoubleArray(sda, tbl)

Decodes a raw binary double array back to a Lua table.

  • Parameters:
    • sda - string - Binary data from encodeDoubleArray
    • tbl - table|nil - Optional table to populate
  • Returns: table - Array of numbers

Internal Notes

  • Three encoding formats: packed text ('a' prefix), binary ('b' prefix), and Lua source
  • decode() auto-detects format by checking the first byte
  • Packed format uses dispatch tables keyed by character codes for fast encoding/decoding
  • Binary format leverages LuaJIT string.buffer encode/decode for native type serialization
  • Temporarily stops GC during decode for performance
  • Type markers in packed format: - (positive number), = (negative number), [ (array), { (dict), | (true), ~ (false), ^ (vec3), & (quat), A-J (strings by length digits)

See Also

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

K-D Tree (3D)

Module defined in `lua/common/kdtreepoint3d.lua`. K-d tree implementation for 3D points with range queries AND nearest-neighbor (closest point) queries.

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.

On this page

ExportsFunctionsM.encode(v)M.decode(is)M.encodeBin(v)M.encodeBinWorkBuffer(v)M.encodeLua(v)M.decodeLua(s)M.encodeDoubleArray(tbl)M.decodeDoubleArray(sda, tbl)Internal NotesSee Also