asobi_lua_match (asobi v0.72.5)
View SourceAn asobi_match implementation that delegates all callbacks to Lua scripts
via Luerl.
Game developers write their match logic in Lua. This module bridges the
asobi_match behaviour to Luerl function calls.
Configuration
In game_modes config, use {lua, ScriptPath} instead of a module name:
{asobi, [
{game_modes, #{
~"arena" => #{module => {lua, "priv/lua/match.lua"}, match_size => 4}
}}
]}The Lua script must define these functions:
function init(config) -- return initial game state table
function join(player_id, state, ctx) -- ctx is the client join context; return updated state
function leave(player_id, state) -- return updated state
function handle_input(player_id, input, state) -- return updated state
function tick(state) -- return state, or state + finished flag
function get_state(player_id, state) -- return state visible to player
-- Optional:
function vote_requested(state) -- return vote config or nil
function vote_resolved(template, result, state) -- return updated state
function phases(config) -- return list of phase definitions
function on_phase_started(phase_name, state) -- return updated state
function on_phase_ended(phase_name, state) -- return updated state
Summary
Functions
Join carrying the client-supplied join context (asobi's optional join/3).
The context is passed to the Lua join as a third argument, so a script
declaring function join(player_id, state) keeps working unchanged - Lua
discards extra arguments - and one declaring
function join(player_id, state, ctx) receives it.
Without this, ctx would reach asobi, find no join/3 on the Lua bridge,
fall back to join/2 and be silently discarded - so every Lua game would
be unable to implement join codes, invites or passwords despite the docs
saying otherwise.