Commit graph

21 commits

Author SHA1 Message Date
Celtic Minstrel
9e79a627c3 [Lua] Fix some accidental global warnings 2024-08-13 08:54:04 -04:00
Celtic Minstrel
c7741907c2 [LuaDoc] Fix several errors in the inline documentation 2024-02-06 19:04:00 -05:00
gfgtdf
955a8bc445
use game_events.add in on_event.lua (#8082)
use game_events.add in on_event.lua

previously on_event.lua and game_events.add had separate priority lists, so that independent of the priority parameter (which both game_events.add and on_event.lua now support) on_event.lua events were always executed first. 

The set_undoable(true) call is there to match the previous behavior of on_event.lua where events implemented via on_event were undoable by default.
The higher default priority of 0.5 is there to match the previous behavior of on_event.lua where events implemented via on_event.lua were always run before wml events.
2023-12-15 21:28:45 +01:00
Celtic Minstrel
857d7e120a Undeprecate on_event() for now 2023-10-14 19:26:36 -04:00
Celtic Minstrel
10d67aa82a Implement a new Lua API to the undo system 2023-10-14 19:26:36 -04:00
Steve Cotton
e3deff8bfd Make undo work again, undeprecate on_event()
Fixes #6898. The issue is that non-WML events added through the new events API
always disable undo with no equivalent of WML's `[allow_undo]`. The long-term
fix is to add a way to do that; however until that's available then listeners
for `moveto` need to use the old `on_event` API. The old `on_event` API can't
be deprecated yet, and this is enforced by our unit tests (the build fails if
there are unexpected deprecation warnings during the tests).

Reverts most of 7e234f8833. Does not revert files
that only listen for non-undoable events such as `die` or `new turn`.

Reverts the deprecation part of #5663's 8cd1332630.
2022-11-19 05:23:30 +01:00
Celtic Minstrel
5a184bbb40 Split wesnoth.game_events.add into multiple functions
Basically this means each of the call modes of the old function is now a separate function.

- add_repeating and add_menu take an ID and a function
- add_wml takes variable substitution setting and a config
- add takes the full options table
2022-07-18 21:56:42 -04:00
Celtic Minstrel
8cd1332630 Enable setting an arbitrary Lua function as an event handler.
Unlike the old wesnoth.game_events.on_event hook and the "convenient" on_event() wrapper for it, this new functionality supports all of the features of WML events, with the sole exception of serialization, since it's not possible to reliably serialize a Lua function.

This commit also divorces menu items from the event that they trigger. The undocumented wesnoth.interface.set_menu_item function no longer adds an event for the menu item; the caller needs to separately register an event using the new functionality.
2022-07-18 21:56:42 -04:00
Celtic Minstrel
e1300e29b0
Lua API: Add inline documentation for pretty much everything and convert existing docs (#6483)
The new format is EmmyLua-based and can be used with (at least) Visual Studio Code.
2022-02-17 13:43:31 -05:00
Celtic Minstrel
7a1390adf7 Remove "wml-utils" require from files that no longer use it 2019-12-04 08:48:53 -05:00
Celtic Minstrel
d9b5e3c4df Replace uses of wml_utils.split with stringx.split 2019-12-04 08:46:04 -05:00
V N
20177dbe5e prevent double execution of on_event.lua
makes it safe to dofile("on_event.lua")

(cherry-picked from commit 6010ffe98e)
2018-10-07 03:25:18 +00:00
Celtic Minstrel
8d74b72031 fixup! Fix missing return in on_event() 2018-03-17 17:21:20 -04:00
Celtic Minstrel
d4e08359dd Fix missing return in on_event() 2018-03-17 16:48:04 -04:00
vgaming
8ba6e5f40e fix code problems found by luacheck (#2380)
actual bugs found:
* backwards_compatibility.lua (undeclared global "helper")
* core.lua (use of undeclared global "helper")
* wml_tags.transform_unit had wrong code to deal with recall_cost
* wrong variable name in cave_map_generator
2018-01-20 23:05:58 -05:00
Celtic Minstrel
8d4cf3cf62 Shorten requires where possible 2017-05-03 02:42:25 -04:00
gfgtdf
1d168bce9a fixup on_event.lua 2016-07-16 20:34:33 +02:00
gfgtdf
d73d32e8e2 fixup on_event.lua 2016-07-11 15:12:12 +02:00
gfgtdf
9a5eabb207 fixup on_event.lua 2016-07-11 15:09:25 +02:00
gfgtdf
ac717f70b8 improve on_event.lua
Added some features:
1) on_event now supports a comma separated list of event names in its first parameter

2) on_event now supports a number as second parameter that specifies in which order the event handlers are called.

3) on_event now passes wesnoth.current.event_context to the handler function, since the handler function will most likeley need it.
2016-07-11 14:01:04 +02:00
gfgtdf
2fa8bc0350 cleanup lua feeding implementation. 2016-05-22 19:41:54 +02:00