Overview
LandSandBoat uses sol2 to expose C++ game objects to Lua scripts. The binding layer lives insrc/map/lua/ and consists of:
CLua*wrapper classes — thin wrappers around C++ game objects that expose methods to Luasol_bindings.h/cpp— macro infrastructure andsol_lua_pushoverloads that allow C++ to pass objects to Lualuautils.h/cpp— the global Lua state, event dispatch functions, and utility helpers
sol::state lua is declared in luautils.h and is the single Lua VM that all scripts share.
How bindings work
Each C++ game class that Lua scripts can touch has a correspondingCLua* wrapper:
sol_bindings macros
sol_bindings.h defines convenience macros for registering types and their inheritance:
Pushing objects from C++ to Lua
When C++ needs to pass a game object to a Lua callback,sol_lua_push overloads handle the conversion. The SOL_BIND_DEF macro generates these:
CCharEntity*, it automatically arrives in Lua as a BaseEntity with all CLuaBaseEntity methods available.
Binding files reference
lua_baseentity — base entity methods
lua_baseentity — base entity methods
Files:
lua_baseentity.h/cppThe largest binding file. CLuaBaseEntity wraps CBaseEntity and provides methods available to all entity types (characters, mobs, NPCs, pets, trusts):- Identity:
getID(),getName(),getEntityType() - Position:
getPos(),setPos(),getZone() - Stats:
getHP(),getMP(),getTP(),getMainJob(),getMainLvl() - Status effects:
addStatusEffect(),delStatusEffect(),hasStatusEffect() - Inventory:
addItem(),hasItem(),delItem() - Flags and variables:
getCharVar(),setCharVar() - Events:
startEvent(),updateEvent(),release()
CCharEntity) and mob subtype (CMobEntity) both arrive in Lua as BaseEntity.lua_zone — zone methods
lua_zone — zone methods
Files:
lua_zone.h/cppCLuaZone wraps CZone and provides:- Local variables:
getLocalVar(),setLocalVar(),resetLocalVars() - Trigger areas:
registerCuboidTriggerArea(),registerCylindricalTriggerArea() - Entity queries via the zone object
lua_item — item methods
lua_item — item methods
Files:
lua_item.h/cppCLuaItem wraps CItem and its subtypes (CItemEquipment, CItemWeapon, CItemUsable, CItemFurnishing, etc.):- Item identity:
getID(),getName(),getStackSize() - Equipment: slot, level requirements, jobs allowed
- Usable items: charges, cast time, recast time
lua_spell — spell methods
lua_spell — spell methods
Files:
lua_spell.h/cppCLuaSpell wraps CSpell:getID(),getName(),getSkillType()- Target and AoE information
- Element, MP cost, cast and recast times
- Interrupted and reflected state
lua_statuseffect — status effect methods
lua_statuseffect — status effect methods
Files:
lua_statuseffect.h/cppCLuaStatusEffect wraps CStatusEffect:getStatusID(),getPower(),getTick(),getDuration()setDuration(),setPower(),setSubPower()- Source entity, tier, and flag access
lua_battlefield — battlefield methods
lua_battlefield — battlefield methods
Files:
lua_battlefield.h/cppCLuaBattlefield wraps CBattlefield (BCNM/ISNM/ENM content):getID(),getStatus(),setStatus()getTimeLimit(),getTimeInside()addEnemy(),getLocalVar(),setLocalVar()- Win/loss/time-limit condition triggers
lua_instance — instance methods
lua_instance — instance methods
Files:
lua_instance.h/cppCLuaInstance wraps CInstance (instanced zone content):getID(),getStage(),setStage()- Progress tracking, time remaining
- Entity spawning within the instance
lua_ability, lua_mobskill, lua_weaponskill
lua_ability, lua_mobskill, lua_weaponskill
CLuaAbility— job ability methods (ID, type, range, area)CLuaMobSkill— mob skill methods (ID, range, target type)CLuaWeaponSkill— weapon skill methods (ID, skill type, TP cost)CLuaPetSkill— pet skill methods
lua_trade_container — trade container methods
lua_trade_container — trade container methods
Files:
lua_trade_container.h/cppCLuaTradeContainer wraps CTradeContainer:getItem(),getItemCount(),hasItemQty()- Trade slot iteration
luautils — C++ to Lua dispatch
luautils.h/cpp is the bridge that allows C++ to call Lua functions. It declares the global sol::state lua and provides:
callGlobal — calling Lua from C++
callGlobal logs the error and returns a default value.
Event dispatch
Theluautils namespace exposes C++ functions for every game event that Lua scripts can handle:
Calling C++ from Lua
From a Lua script, C++-bound methods are called directly on the object:sol_bindings.cpp — registration
sol_bindings.cpp contains the actual sol_lua_push function bodies generated by the SOL_BIND_DEF and SOL_BIND_DEF_SUB macros. These are the functions that sol2 calls when C++ code passes a C++ pointer into a Lua function call. They ensure null pointers become nil in Lua and that subclass pointers are correctly presented as the base Lua type.