Author: anonymissimus
Date: Wed Mar 16 01:41:29 2011
New Revision: 48921

URL: http://svn.gna.org/viewcvs/wesnoth?rev=48921&view=rev
Log:
Made modify_unit substitute variables as late as possible and provide reference 
to the unit being currently modified via $this_unit.

Modified:
    trunk/data/lua/wml-tags.lua

Modified: trunk/data/lua/wml-tags.lua
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/lua/wml-tags.lua?rev=48921&r1=48920&r2=48921&view=diff
==============================================================================
--- trunk/data/lua/wml-tags.lua (original)
+++ trunk/data/lua/wml-tags.lua Wed Mar 16 01:41:29 2011
@@ -486,8 +486,8 @@
        local unit_variable = "LUA_modify_unit"
 
        local function handle_attributes(cfg, unit_path)
-               for current_key, current_value in pairs(cfg) do
-                       if type(current_value) ~= "table" then
+               for current_key, current_value in 
pairs(helper.shallow_parsed(cfg)) do
+                       if type(current_value) ~= "table" and current_key ~= 
"type" then
                                wesnoth.set_variable(string.format("%s.%s", 
unit_path, current_key), current_value)
                        end
                end
@@ -497,7 +497,7 @@
                local children_handled = {}
                handle_attributes(cfg, unit_path)
 
-               for current_index, current_table in ipairs(cfg) do
+               for current_index, current_table in 
ipairs(helper.shallow_parsed(cfg)) do
                        local current_tag = current_table[1]
                        local tag_index = children_handled[current_tag] or 0
                        handle_child(current_table[2], 
string.format("%s.%s[%u]",
@@ -507,14 +507,14 @@
        end
 
        local filter = helper.get_child(cfg, "filter") or helper.wml_error 
"[modify_unit] missing required [filter] tag"
-       local cfg = helper.parsed(cfg)
-       local type = cfg.type; cfg.type = nil
+       local type = cfg.type
        local function handle_unit(unit_num)
                local children_handled = {}
                local unit_path = string.format("%s[%u]", unit_variable, 
unit_num)
+               wesnoth.set_variable("this_unit", 
wesnoth.get_variable(unit_path))
                handle_attributes(cfg, unit_path)
 
-               for current_index, current_table in ipairs(cfg) do
+               for current_index, current_table in 
ipairs(helper.shallow_parsed(cfg)) do
                        local current_tag = current_table[1]
                        if current_tag == "filter" then
                                -- nothing
@@ -546,6 +546,7 @@
                handle_unit(current_unit)
        end
 
+       wesnoth.set_variable("this_unit")
        wesnoth.set_variable(unit_variable)
 end
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to