Commit graph

739 commits

Author SHA1 Message Date
Charles Dang
b4614de149 Fixup ee868fc82b. Forgot to remove an 'end' key
Also re-added the parens around the get_child call
2015-01-09 22:11:56 +11:00
Charles Dang
ee868fc82b Misc code cleanup 2015-01-09 21:53:36 +11:00
gfgtdf
9cde1af9c8 fix explicit indexes for [store_unit]
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
2015-01-09 00:51:41 +01:00
Chris Beck
748f872091 lua: make it easier to disable strict mode global variables
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.
2015-01-05 14:58:09 -05:00
gfgtdf
486fc8ed71 fixup HEAD 2015-01-05 17:29:46 +01:00
gfgtdf
201d83f608 fix [store_side] to allow explicit indexes
[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).
2015-01-05 17:11:27 +01:00
Charles Dang
e1e5169c95 Get [time_area] id from the config instead of passing it as a lua arg
This fixes [time_area] id= inadvertently becoming required, when it should be optional
2015-01-04 23:25:49 +11:00
Charles Dang
778c840483 Misc cleanup 2014-12-30 16:52:50 +11:00
Charles Dang
3acb30e1ca Cast arg as string in trim() and split() 2014-12-30 16:05:41 +11:00
8573
e23ff7009c Lua: Fix uses of tostring calls as LHSs to or
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.
2014-12-29 10:09:48 +00:00
Charles Dang
f8c811fa4f Simplified syntax for wml_actions.chat() 2014-12-29 17:28:06 +11:00
Charles Dang
c762937e74 Simplified object:method syntax for trim() and split() 2014-12-29 15:47:44 +11:00
Charles Dang
fa079a1b3f Return first value of trim() within the function as opposed to at the call 2014-12-29 15:44:19 +11:00
Charles Dang
e35c301ff4 Fixed clear_variable by only calling first argument of of trim() 2014-12-29 15:31:05 +11:00
Chris Beck
497ed6f516 move wml [heal_unit] impl to lua 2014-12-28 17:39:39 -05:00
Charles Dang
95c94bc192 Allowed a comma separated id list for [remove_event] and [event] remove=yes 2014-12-28 20:31:45 +11:00
Charles Dang
ec985105ef Eliminate local var from trim() 2014-12-28 19:15:21 +11:00
Charles Dang
9b6f357a27 Put split-string-at-comma code into a function 2014-12-28 19:14:30 +11:00
Chris Beck
53b1309691 Merge branch 'lua' 2014-12-26 17:18:22 -05:00
Charles Dang
8a3572a62b Added [remove_event] (equivalent to [event] id= remove=yes) 2014-12-26 22:33:09 +11:00
Chris Beck
017050df70 ilua: eliminate the "_" holds last executed command feature
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.
2014-12-26 00:06:05 -05:00
Chris Beck
e73c57ead7 move wml [endlevel] impl to lua, and split into many lua funcs
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.
2014-12-24 16:17:24 -05:00
Chris Beck
d7bf5be356 move wml [animate_unit] to lua 2014-12-24 15:15:25 -05:00
Chris Beck
171f92a6a5 move wml [open_help] impl to lua
also fixes an issue where the help topic was being cast
unnecessarily to a tstring
2014-12-24 14:42:58 -05:00
Chris Beck
75767d3a77 move WML [kill] impl to lua 2014-12-24 05:43:37 -05:00
Chris Beck
9922b98fa3 move wml [inspect] impl to lua (and lua_gui2 namespace) 2014-12-24 05:00:44 -05:00
Chris Beck
ca58a71793 move WML [modify_side] implementation to lua 2014-12-24 04:44:25 -05:00
Chris Beck
0246026940 move WML [event] impl to lua, fixup core wml vs lua loading order
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.
2014-12-24 04:21:58 -05:00
Chris Beck
0e365efc1a move WML [label] impl to lua 2014-12-24 03:16:49 -05:00
Chris Beck
29da15e1c0 move wml [end_turn] impl to lua 2014-12-24 03:07:49 -05:00
Chris Beck
177b4d5da1 move WML [color_adjust] impl to lua 2014-12-24 02:57:42 -05:00
Chris Beck
96c35f6560 move WML [redraw] impl to lua 2014-12-24 02:44:31 -05:00
Chris Beck
2cc38505dc move WML [scroll] implementation to lua 2014-12-24 01:06:44 -05:00
Chris Beck
defb9e5051 move replace_schedule impl to lua 2014-12-23 23:35:10 -05:00
Chris Beck
fa32be5602 add time_area registration impl to lua 2014-12-23 23:05:02 -05:00
Chris Beck
09ce8b5774 move clear_menu_item to lua implementation 2014-12-23 22:23:22 -05:00
Chris Beck
41e54fd009 move allow_undo, allow_end_turn impl's to lua 2014-12-23 22:08:45 -05:00
Chris Beck
0d76ac3be7 move the place, remove shroud WML tags to lua implementation 2014-12-23 21:04:45 -05:00
Chris Beck
eb71fc4d3b move "set_menu_item" to be implemented via lua rather than C++ 2014-12-23 19:34:17 -05:00
Chris Beck
1d7e45db23 lua [find_path]: always declare max_cost as a local
this is faster since it avoids repeated global lookup, and
suppresses lua_strict errors.
2014-12-20 21:10:25 -05:00
Chris Beck
3740b24b28 fixup ilua _pretty_print function
had some global vs local problems after making this a module loaded
with require rather than a dofile script
2014-11-23 18:33:50 -05:00
Chris Beck
d31253f585 bugfix: invalid variable reference
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"
2014-11-22 16:43:27 -05:00
Chris Beck
a65d168317 enable "strict mode" in wesnoth lua
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.
2014-11-22 15:19:19 -05:00
Chris Beck
ba4276ea31 add "ilua" helper functions for lua interpreter 2014-11-21 22:22:43 -05:00
Bär Halberkamp
db028708c4 Added a lua implementation for FULL_HEAL and PUT_TO_RECALL_LIST 2014-10-21 19:41:36 +02:00
Chris Beck
b75f417982 fix a check in move_unit
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
2014-10-18 15:37:38 -04:00
Chris Beck
8308f7d3b9 fix whitespace at end of line 2014-09-05 16:52:03 -04:00
unknown
72f138c544 Fix bug #22306: move_unit moves a unit even when it shouldn't
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).
2014-08-07 10:59:38 -04:00
Chris Beck
762efc278f add error reporting to [insert_tag] if it has no variable= field
The lack of reporting here is somewhat annoying so i patched it.
2014-06-21 18:13:42 -04:00
aquileia
1715ab3145 gitignore: Include more rules from subdirectories
That is: data/lua/, scons/, and utils/
2014-06-09 01:00:45 +02:00