38 Commits

Author SHA1 Message Date
Celtic Minstrel
e2875f34b2 Fix a bunch of luadoc errors 2022-06-11 00:15:18 -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
Pentarctagon
370d03ccb7 Fix luacheck warnings and add to CI.
Note the `exclude_files` in .luacheckrc should be deleted once the eventual Ubuntu 22.04 base image has an updated luacheck that supports lua 5.4.
2021-11-28 14:26:02 -06:00
Celtic Minstrel
73983c7032 Lua: Fix nil-safety issues in location_set
Fixes #6231

(cherry picked from commit 1f32466782e9f6089825b26631002e4000b5f73e)
2021-10-29 11:56:43 +11:00
Celtic Minstrel
bedc25fb56 Lua API: location_set:to_pairs now returns named tuples 2021-09-04 22:20:28 -04:00
Celtic Minstrel
4837452dd7 Lua API: Add new location_set function to convert to or from a Lua map
This enables a location set to be passed to map functions in the functional module.
2021-09-04 22:20:28 -04:00
Celtic Minstrel
08e3a31979 Lua API: When creating a location set from triples, also support tables with x, y, and value keys 2021-07-30 19:22:57 -04:00
Celtic Minstrel
c59c3b9273 Lua API: Use a named tuple when converting a location set to triples 2021-07-30 19:22:57 -04:00
Celtic Minstrel
7d7b58e31e Lua API: Add an absolute complement option to location_set
- ls:invert(w,h,[border_size]) takes an absolute complement as if the map were the given size
- ls:invert(map) takes an absolute complement relative to the specified map
- ~ls is only available in the game kernel and takes an absolute complement relative to the real map
2021-07-30 19:22:57 -04:00
Celtic Minstrel
b4809e9ded fix whitespace 2021-07-02 18:51:48 -04:00
Celtic Minstrel
7c2d0c1c5d Lua API: Fix location_set.of_pairs including the location in the value
This is the real cause of the breakage in 5a9c24c4e79d624e34aa475949a4aa49b1984322 and d04bd2bf5d2ad932ca9bb3203f4ff9f91411e261.
A returned location now has both x/y and 1/2, so the location_set logic removed the x/y but kept the 1/2, causing it to break when converted to a config.
This makes it use rawget when the value is a table, which fixes it.
2021-07-02 16:55:42 -04:00
Celtic Minstrel
f5de3cca18 Lua API: Add a mode argument to locaton_set:to_wml_var
It has the same semantics as the mode in wml_utils.vwriter.init.
2021-07-02 14:04:54 -04:00
Celtic Minstrel
695eb8356d Lua API: Better error checking when converting a location set to a WML variable 2021-07-02 14:04:54 -04:00
Celtic Minstrel
c1304fb441 Lua: Add location_set.of_raw to ease working with AI functions that return raw location sets 2021-07-02 14:04:53 -04:00
Celtic Minstrel
96b5bf43ef Move shroud/fog ops to wesnoth.sides and change the API somewhat
- place_shroud and remove_shroud no longer accept a shroud data string or the special string "all"
- new functions are added to convert between lists of locations and shroud data strings
- place_fog, remove_fog, is_fogged, and is_shrouded aren't changed, only moved
2021-06-19 11:07:53 -04:00
Celtic Minstrel
1dccc3ad76 Update mainline content to use the mathx module 2021-05-08 17:20:49 -04:00
mattsc
44e279cb2f Lua location_set: fix a variable name 2021-03-06 10:53:02 -08:00
Celtic Minstrel
9d3bf196b0 Update everything to use the new wesnoth.map module
- get_terrain and set_terrain replaced with direct indexing operations
- get_map_size mostly replaced with either the iterator or an on_board call.
  Only a few cases really needed to know the size of the map for some other purpose.
- shroud and fog operations, village owner, time areas, and location filters
- get_terrain_info replaced with terrain_types table
- Map generation functions create_map and create_filter
2021-02-28 18:16:33 -05:00
Celtic Minstrel
51cf2621f7 Add a utility function to extract a location from the front of a variadic parameter pack
The purpose of this is to make it easy for functions implemented in Lua to handle locations
in the same way as functions implemented in C++.

The location_set module has been updated to make use of this functionality in its setter functions.

Usage example:

Imagine a function foo with the following signature:

foo(bar : string, home : location, mode : string, target : location, moo : boolean) -> boolean

With the new read_location function it could be implemented as follows:

function foo(...)
	-- First argument goes in bar
	local bar = ...
	-- Read location starting at the second argument
	local home, n = wesnoth.mP.read_location(select(2, ...))
	-- note: n will be 0 if a location wasn't found at that position
	-- This could be an error, or it could be handled as an optional parameter
	-- Next argument after that goes in mode
	local mode = select(n + 2, ...)
	-- Then read a location into target
	local target, m = wesnoth.map.read_location(select(n + 2, ...))
	-- Finally, read a parameter into moo
	local moo = select(m + n + 2, ...)
	-- Do stuff with all these parameters
	return true
end

With that code, all the following invocations of foo work:

foo('a', 'b', true) -- both optional locations omitted
foo('a', 1, 2, 'q', 5, 6, false) -- locations given as separate integer parameters
foo('a', 'm', {1, 7},  true) -- first location omitted, second given as 2-element array
foo('a', some_unit, 'z', {x = 5, y = 10}, false) -- a unit also functions as a location
foo('a', 7, 12, 'q', my_leader, true) -- mixing different forms also works
2021-02-28 18:16:30 -05:00
Celtic Minstrel
c366998021 Fix an issue with items and location sets
Fixes #4621
2019-12-07 17:21:03 -05:00
Celtic Minstrel
4b9f5d4485 Extend the location_set module to support set operators, custom index operators, and a tostring metamethod
Also adds set difference and symmetric difference functions, and a clone function.
2019-12-01 22:29:49 -05:00
mattsc
0e017d9f7c Lua code: replace deprecated wesnoth.set_variable() calls
(cherry-picked from commit ce7faae4f41f23f1d1f61d2b4f5ca95d4ce4f89a)
2018-10-07 03:21:07 +00:00
mattsc
05d5afa6a9 Lua code: replace deprecated wesnoth.get_variable() calls
(cherry-picked from commit f1764d182fe33c4e29c6bd42761be2e946cd0c94)
2018-10-07 03:21:06 +00:00
Celtic Minstrel
1ba783959e fixup 0539a68eb 2017-05-11 16:00:52 -04:00
Celtic Minstrel
0539a68eb4 Migrate ai_helper.LS_random_hex to location_set:random 2017-05-10 17:40:21 -04:00
Celtic Minstrel
9b635994e1 Add location_set.(of|to)_triples (migrated from ai_helper) 2017-05-10 17:40:14 -04:00
Celtic Minstrel
2dee1e5f96 Lua Cave Mapgen: Use stable iteration of location sets 2016-10-27 14:20:42 -04:00
Celtic Minstrel
46e31cb462 Refactor Lua cave map generator
This accomplishes two main things:
- Creates a mapgen_helper.lua module containing functions useful for Lua map generators
- Paves the way for allowing the cave generator to produce scenarios and accept user configuration
2016-10-27 14:20:18 -04: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
9fb47d7f1f negate the output of location_set:empty, fixing logic error and
ensuring that a boolean value is returned
2014-02-16 19:36:09 -05:00
jleldridge
4e6ecc81ce Fixed location_set().of_pairs() syntax to follow conventions. 2013-05-16 15:52:34 -04:00
jleldridge
0d8bd9fe03 Changed location_set.of_pairs() to work with different formats of x,y coordinate tables. 2013-05-16 00:21:40 -04:00
Anonymissimus
febb9da2ca Reverted 2011-09-21T21:44:58Z!thonsew@yahoo.com and 2011-09-20T21:21:21Z!thonsew@yahoo.com.
thonsew: The lua interface is not your playground. This is not the way
I want the lua files or its C++ interface to be modified. You are
invited to talk with me on IRC.

some of the main reasons:

-Your revisions contain lots of unneccessary changes, some of which
 break existing lua or wml without a reason. Do you ever look at the
 diffs?

-Your revisions pack a lot of unrelated stuff together into one.

2011-09-21T21:44:58Z!thonsew@yahoo.com makes sense in some parts and is what you should have
done in the first place.
2011-09-22 17:09:50 +00:00
Thonsew
e59dc97260 Added support for t_token to lua code.
1. Created a t_token metatable along with support code for indexing,
garbage collection, tostring, tonumber, comparison and concatenation.

2. Adjusted string comparison and lookup in lua code to work with
either t_token or string.

This addresses in part bug #18631, bug #18695.  Before this lua was
treating all t_token as either tstrings or strings.
2011-09-20 21:21:21 +00:00
Guillaume Melquiond
7e43fc0e3f Added a location_set:filter method. 2010-10-31 17:24:33 +00:00
Lari Nieminen
3bd47bcb15 This seems to fix a bug occurring when using of_wml_var.
Should be proofread by someone who knows what they're doing.
2010-10-26 14:42:22 +00:00
Guillaume Melquiond
930cd8fe63 Added location_set:size method. 2010-10-03 13:30:34 +00:00
Guillaume Melquiond
aa7e3e47d9 Added Lua library for location sets and maps. 2010-10-03 06:37:24 +00:00