ObjectPool main Reference
Module defined in `lua/objectpool/main.lua`. Object pool Lua VM that manages vehicle objects in a shared pool, providing spawn, get, move, set, and delete operations. Acts as the bridge between the Be
Module defined in lua/objectpool/main.lua. Object pool Lua VM that manages vehicle objects in a shared pool, providing spawn, get, move, set, and delete operations. Acts as the bridge between the BeamNG engine and individual vehicle Lua VMs.
Functions/Exports
Pool Operations (global)
getObject(objId)
Returns lpack-encoded object data for the given object ID.
moveObject(objId)
Removes object from pool and returns its lpack-encoded data (transfer ownership).
setObject(objId, objDataStr)
Stores lpack-decoded object data into the pool at the given ID.
deleteObject(objId)
Removes object from pool (sets to nil).
initPool()
No-op initialization function for the thread Lua VM.
Vehicle Lifecycle (global)
init(path, initData)
Called in the object Lua VM to initialize a vehicle:
- Decodes lpack
initDatastring - Loads vehicle via
jbeam/stage2.loadVehicleStage2() - Stores loaded object in pool keyed by
obj:getId() - Returns
trueon success,falseon failure (triggers Lua VM unload)
Event Handlers (global)
onNodeCollision(id1, pos, normal, nodeVel, perpendicularVel, slipVec, slipVel, slipForce, normalForce, depth, materialId1, materialId2)
Node collision callback (currently no-op with commented dump).
onVehicleReset(retainDebug)
Vehicle reset callback (empty).
onBeamBroke(id, energy)
Beam break callback (empty).
onBeamDeformed(id, ratio)
Beam deformation callback (empty).
Internal Management (global)
_setObj(objId, _obj)
Sets the current object context - sets obj, objectId, and objData globals via rawset.
__newIndexHandler(t, key, val)
Metatable __newindex handler - writes to current object's data table.
__indexHandler(t, key)
Metatable __index handler - reads from current object's data table.
Environment Setup
vmType = 'objectpool'- Package path includes: ge, gui, vehicle, common, libs, luasocket, core/scripts
- Requires:
luaCore,utils,devUtils,ve_utils,mathlib - Aliases:
float3 = vec3 - Overrides
printto uselog("A", "print", ...)
Usage
This module is loaded by BeamNG as the objectpool Lua VM. Not called directly by user scripts.
Internal Notes
- Uses
_Gmetatable to redirect global reads/writes to the current object's data table _setObjmust be called before any per-object operations to set contextlpackused for serialization between pool and vehicle VMsmoveObjectremoves from pool (ownership transfer), whilegetObjectis read-only- Vehicle init uses jbeam stage2 loader - expects
initData.vdatain the decoded table - Empty event handlers serve as extension points for future collision/damage logic