and for [store_locations] [store_starting_location] [store_unit_type]
see comment for 201d83f608 (fix [store_side] to allow explicit indexes)
As a side effect, this commit now also alows mode="replace"/"append"/default for
[store_locations] [store_starting_location] [store_side] [store_unit_type] which was
previously only possible for store_unit
After this commit, the "strict mode" lua variable errors may be
disabled with
ilua.strict = false
and reenabled with
ilua.strict = true
There will typically be no noticeable performance difference from
previously to this commit.
This is a bit simpler than the other methods described which
include using pcall or resetting the metatable of _G.
[store_side] variable= some_variable[0] ... [/store_side] would result in a wesnoth.set_variable(some_variable[0][0]. ...) call which we don't allow in master after https://github.com/wesnoth/wesnoth/pull/231. 1.12 would just ignore the second index in this case. I decided to rather fix [store_side] than to restore the 1.12 behaviour of set_variable (which wouldn't be harder).
This commit changes occurrences of the pattern `tostring(x) or y` to
`tostring(x or y)` in the following Lua scripts:
- `data/lua/wml-tags.lua`
- `data/lua/wml/items.lua`
`tostring(x) or y` is unlikely to do what the author intended (and is
pointless unless `x` is an object of a custom type with unusual
behavior), because `tostring` returns a string (`"false"` or `"nil"`)
if `x` is a falsy value (`false` or `nil`), and all strings are truthy
in Lua — thus, `tostring(x) or y` will (unless `x` is of a custom
type) *always* evaluate to `tostring(x)`, never to `y`.
`tostring(x or y)` should, I expect, give the intended behavior.
the ilua `_pretty_print` feature has the property that it sets _
to be what was printed, as an interpreter feature so that _
represents the results of the previous expression. However it
appears that this may conflict with some parts of our api, for
instance the _ is used to hold the return value of
wesnoth.textdomain in the lua implementation of [harm_unit].
Note that there is no actual bug that I have observed, I merely
anticipate that this _ feature won't be compatible with our
established gettext conventions.
the [endlevel] tag does alot of things that could quite comfortably
be split into several parts, like setting the next scenario, the
end level text, message duration, credits. this commit adds
separate lua api for each of these, leaving the rest in end_level,
and the lua tag implementation calls these variously.
This commit moves [event] to be implemented in lua/wml-tags.lua.
It turns out that because of some questionable ordering in
data/core/_main.cfg, none of the tags defined in
data/lua/wml-tags.lua are actually defined at the time that core
is read, instead they are defined right after this. This is broken,
the entire wml library should be defined before core is read. Thus
we reorder some directives in data/core/_main.cfg to ensure this.
This commit adds lua callbacks `wesnoth.add_event_handler`,
`wesnoth.remove_event_handler` as well.
variable v does not exist... the function is not commented so I
can't be sure of the intention, but the most backwards-compatible
fix is to not pass argument v, so that it will be nil as before.
this bug was revealed by enabling lua "strict mode"
Enables an ilua feature called "strict mode" in all of our lua
environments. This change causes lua to report an error if a global
variable is used before it is assigned. The benefits of this are:
- Improved maintainability of lua-based add-ons, since you get
better error reporting in case of a typo.
- Improved behavior of the lua interpreter console, since mistyped
or gibberish lines resolve to an error rather than "nil", which
the console treats as a legal return value.
It is possible to disable this or work around it in individual
scripts. For more info see release notes.
The logic is supposed to be, if (x,y) == (prev_x, prev_y), then
skip the "find_vacant_hex" function because we don't have to move.
Instead we effectively had, if (x == prev_x OR y == prev_y), then
we can skip the check.
This revises a commit
72f138c544
in the hopes to fix a bug reported here:
http://forums.wesnoth.org/viewtopic.php?f=4&t=41084
Modified the lua script for wml_action.move_unit. In the
loop to check for vacant tile, if the current location
is equal to the previous location we don't look for a
vacant tile since our location is free (where we are).