Bug in [for] missing step
https://forums.wesnoth.org/viewtopic.php?t=46450 reports a Lua crash if end is given but step is not. The wiki says the default step is 1. Note that if end is negative, the [for] does nothing (per sniity check).
This commit is contained in:
parent
0f44669e59
commit
468f07364e
1 changed files with 6 additions and 8 deletions
|
@ -99,19 +99,17 @@ wesnoth.wml_actions["for"] = function(cfg)
|
|||
local cfg_lit = helper.literal(cfg)
|
||||
first = cfg.start or 0
|
||||
loop_lim.last = cfg_lit["end"] or first
|
||||
if cfg.step then loop_lim.step = cfg_lit.step end
|
||||
loop_lim.step = cfg_lit.step or 1
|
||||
end
|
||||
loop_lim = wesnoth.tovconfig(loop_lim)
|
||||
if loop_lim.step == 0 then -- Sanity check
|
||||
helper.wml_error("[for] has a step of 0!")
|
||||
end
|
||||
if loop_lim.step ~= nil then
|
||||
if (first < loop_lim.last and loop_lim.step <= 0)
|
||||
or (first > loop_lim.last and loop_lim.step >= 0) then
|
||||
-- Sanity check: If they specify something like start,end,step=1,4,-1
|
||||
-- then we do nothing
|
||||
return
|
||||
end
|
||||
if (first < loop_lim.last and loop_lim.step <= 0)
|
||||
or (first > loop_lim.last and loop_lim.step >= 0) then
|
||||
-- Sanity check: If they specify something like start,end,step=1,4,-1
|
||||
-- then we do nothing
|
||||
return
|
||||
end
|
||||
local i_var = cfg.variable or "i"
|
||||
local save_i = utils.start_var_scope(i_var)
|
||||
|
|
Loading…
Add table
Reference in a new issue