From 58354874a447b74273f46fa548051479c3d78b5c Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Tue, 28 Dec 2010 15:09:39 +0000 Subject: [PATCH] Improved [command] tag so that it can cope with WML... ...from [insert_tag] containing code that is either self-modified or modified by its siblings. --- data/lua/wml-tags.lua | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index da902e0bf34..9ea9ffd7043 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -216,13 +216,43 @@ function wml_actions.music(cfg) end local function handle_event_commands(cfg) - for i = 1, #cfg do - local v = cfg[i] + -- The WML might be modifying the currently executed WML by mixing + -- [insert_tag] with [set_variables] and [clear_variable], so we + -- have to be careful not to get confused by tags vanishing during + -- the execution, hence the manual handling of [insert_tag]. + local cmds = helper.shallow_literal(cfg) + for i = 1,#cmds do + local v = cmds[i] local cmd = v[1] + local arg = v[2] + local insert_from + if cmd == "insert_tag" then + cmd = arg.name + local from = arg.variable + arg = wesnoth.get_variable(from) + if type(arg) ~= "table" then + -- Corner case: A missing variable is replaced + -- by an empty container rather than being ignored. + arg = {} + elseif string.sub(from, -1) ~= ']' then + insert_from = from + end + arg = wesnoth.tovconfig(arg) + end if not string.find(cmd, "^filter") then cmd = wml_actions[cmd] or helper.wml_error(string.format("[%s] not supported", cmd)) - cmd(v[2]) + if insert_from then + local j = 0 + repeat + cmd(arg) + j = j + 1 + if j >= wesnoth.get_variable(insert_from .. ".length") then break end + arg = wesnoth.tovconfig(wesnoth.get_variable(string.format("%s[%d]", insert_from, j))) + until false + else + cmd(arg) + end end end -- Apply music alterations once all the commands have been processed.