Commit graph

108 commits

Author SHA1 Message Date
Gregory A Lundberg
fc21ebf1be Respect lua_next constraints
The key value returned by lua_next, on the Lua stack, cannot be modified.

Certain tests such as lua_isstring will convert the value.

The solution is, instead of testing if they key can be converted to a string, test if it actually is a string by using lua_type.
2017-11-12 20:48:57 -05:00
gfgtdf
d5148f2532 fix missing linebreak in erromessage 2017-09-14 21:36:21 +02:00
gfgtdf
dac782925a vconfig optimisation 2017-08-27 21:57:41 +02:00
Celtic Minstrel
9f0c677d02 Remove the optional second argument to wesnoth.get_variable
It was only used in one place and didn't even function as advertised.
2017-05-22 17:31:21 -04:00
Charles Dang
96ea0eb6b9 Removed trailing tabs and whitespaces from C++ source
[ci skip]

I ran the command used in 9b7b1751fd, excluding results in lua/ and spirit_po/.

Also, once again, for some reason actions/vision.hpp gets registered as massively changed
(similar to f11fa0652a) despite nothing really having changed at all.
2017-05-16 06:46:43 +11:00
Celtic Minstrel
396de67211 Lua: Allow using the length operator on translatable strings 2017-05-10 18:33:28 -04:00
Celtic Minstrel
6000d644d8 Add a second version of luaW_type_error
This can make some Lua error messages more helpful.
Unfortunately it's rather difficult to deploy, as most
calls to luaW_type_error are within "check" functions,
where the info needed for the new version is unknown.
2017-05-10 17:40:12 -04:00
Charles Dang
323516d3d8 Avoid copy initialization of arrays (use direct instead) 2017-04-21 03:10:07 +11:00
Celtic Minstrel
69a7d5a755 Use fallthrough annotation attributes where applicable
This commit also has some random reformatting. Please ignore it.
2017-04-19 03:50:55 -04:00
Celtic Minstrel
b4dc11ce36 Belated 2017 copyright update 2017-03-19 10:05:38 -04:00
Charles Dang
e22c8967ee Cleaned up global.hpp includes 2016-12-17 15:21:04 +11:00
Celtic Minstrel
e0614251c4 Rename exception classes to avoid t- prefix 2016-11-09 01:13:17 -05:00
Charles Dang
8c92a9ee8e Formatting cleanup: moved const qualifiers before type names 2016-10-31 01:04:18 +11:00
gfgtdf
806a388b9d fix lua crashing after an lua error
This fixes 797613f760

which changed the luaW_pcall code from.

 if(lua_pcall(..)) {
   ...
   lua_pop(L, 2);
   return;
 }
 lua_remove(L, error_handler_index);

to

 int r = lua_pcall(..);
 lua_remove(L, error_handler_index);
 if(r) {
   ...
   lua_pop(L, 2);
   return;
 }

so that three values were removed from the stack in case of an error which caused random segfaults later.
2016-10-22 15:28:03 +02:00
Chris Beck
e9d72ad7ed partially revert 797613f760
attempts to fix bug reported by tad_carlucci

discussed on #wesnoth-dev 10-19-2016
2016-10-19 20:56:51 -04:00
Gregory A Lundberg
86adfc47f8 GCC complains about float/double and useless cast 2016-10-16 10:55:09 -05:00
Gregory A Lundberg
1528a8bb5a Refactor luaL_typerror
Lua deprecated luaL_typerror. Wesnoth needs it. Traditionally this was handled as a by-hand edit to the Lua source kit. Refactored into Wesnoth as luaW_type_error.
2016-10-10 10:19:41 -05:00
gfgtdf
296faefa20 remove gamemap.border_size_
This also fixes a msvc compile warning in src/scripting/lua_common.cpp
2016-09-16 22:35:42 +02:00
gfgtdf
553ac0fd05 add wml_x/y() getter & setter in map_location 2016-09-16 22:35:41 +02:00
Celtic Minstrel
b8b1e8a223 Store unit methods in metatable instead of doing linear search 2016-09-11 17:05:51 -04:00
Celtic Minstrel
f866039e81 Add support for gettext plurals to Lua API 2016-08-29 16:47:17 -04:00
Celtic Minstrel
496a523fa2 Fix crash when starting a campaign 2016-08-28 00:24:23 -04:00
Celtic Minstrel
9dbae39448 Minor code cleanup regarding special map locations 2016-08-24 18:45:40 -04:00
Celtic Minstrel
e821e508c3 Merge pull request #744 from lua_refactor
Refactor some Lua stuff and reduce const_cast usage

Conflicts:
	src/scripting/game_lua_kernel.cpp
	src/scripting/lua_unit.cpp
2016-08-24 03:13:38 -04:00
Celtic Minstrel
f6974f01f6 fixup! When creating units in Lua from a vconfig, don't parse any contained [filter_recall] or [event] 2016-08-23 23:07:13 -04:00
Celtic Minstrel
1e575480a4 When creating units in Lua from a vconfig, don't parse any contained [filter_recall] or [event] 2016-08-23 17:48:14 -04:00
Celtic Minstrel
39477b40a7 Fix Lua metatables by using lauxlib to manage them 2016-08-22 14:13:53 -04:00
Celtic Minstrel
30b7ab8b2d Reduce use of const_cast 2016-08-20 20:38:46 -04:00
Celtic Minstrel
4dd99b881f Implement Lua placement new 2016-08-20 20:38:46 -04:00
Celtic Minstrel
1521f326df Move Lua unit wrapper to own file 2016-08-20 20:38:46 -04:00
gfgtdf
16f5980a3c config::all_children_range(), attribute_range() now return iterator_range
This also fixed compilation with boost veryion < 1.56 by using
iterator_range::pop_front() instead of iterator_range::drop_front()
which was added in boost 1.56

This also makes config::all_children_iterator a random access iterator.
2016-08-14 15:50:22 +02:00
Elvish_Hunter
e83d1de05e Lua: make wesnoth.set_variable() return nil if a variable doesn't exist
Fixes bug #24740.
2016-06-10 12:01:15 +02:00
Celtic Minstrel
ca382018b7 BOOST_FOREACH -> range for 2016-04-02 09:38:29 -04:00
Celtic Minstrel
4c45683d4d Modernize luaW_getglobal
The variadic form now uses a variadic template, and a vector form has been added.
Since the nullptr sentinel argument is no longer required, it has been removed from all calls.
2016-03-31 02:13:39 -04:00
Celtic Minstrel
3ac7f8d970 NULL -> nullptr
A few cases of NULL were missed, since changing them led to errors
(Mainly instances where it was passed to a boost::function)
2016-03-31 00:42:38 -04:00
Celtic Minstrel
d250e04566 Now luaW_tolocation accepts units and vconfigs 2016-03-16 12:51:29 -04:00
Celtic Minstrel
a84500fb8f Add functions for transferring map locations to and from Lua stack
This also changes nearly all API functions taking locations to use the new functions.
As a result, these functions can now accept their location arguments in any of three formats:
- An array of two integers
- A table with x and y keys
- Two separate, consecutive integer arguments

Functions that return locations mostly still use whatever format they used before.
This is because changing return values is a more compatibility-breaking change.

This temporarily breaks compatibiliy for the following AI functions:
- ai.get_targets()
- ai.get_avoid()
- ai.get_attacks()
2016-03-16 12:50:54 -04:00
Celtic Minstrel
0f39cc3fe0 Fix function case 2016-03-14 13:15:33 -04:00
Celtic Minstrel
7d9a0d90b9 Allow array attribute values in Lua config syntax
These are converted to a comma-separated string.
It does NOT insert parentheses if an element contains a comma.
2016-03-14 13:15:33 -04:00
gfgtdf
bcb06e4a7a fix lua string and tstring comparision
lua string now use a locale indpenedent comparision, this prevents OOS.

This commit also implements comparision operators for lua tstring which
use a language dependend collate facet from boost locale. (which usually
uses an icu or a winapi backend)
2016-02-24 18:07:00 +01:00
Chris Beck
ba51524f6e update copyright to year 2016
using this shell script:

find src -type f -print0 | xargs -0 sed -i "s|Copyright (C) \([[:digit:]]*\)\([ ]*\)-\([ ]*\)2015|Copyright (C) \1\2-\32016|g"
2016-01-02 23:59:31 -05:00
Elvish_Hunter
9b7b1751fd Removed trailing tabs and whitespaces from C++ source
I used this command line: find <source directory> -name \*.\[ch\]pp -print0 | xargs -0 sed -i 's/[[:blank:]]*$//'
2015-12-21 20:39:46 +01:00
gfgtdf
a77fada784 add access to tables via unit.variables
unit.variables now uses the same functionality as
wesnoth.get/set_variable (just for the unit variable instead of the game
variables) which makes it possible to access table values. Its also
posible to access subvariables as
unit.variables["list1[2].list2.length"]
2015-10-08 21:37:29 +02:00
Celtic Minstrel
2c337d4115 Use ipairs() for helper.child_range 2015-09-29 14:46:41 -04:00
Celtic Minstrel
376b8ac76b Use userdata instead of indices for the vconfig iterator upvalues 2015-09-26 02:44:02 -04:00
Celtic Minstrel
8e228edc34 Lua API: Fix ipairs(vconfig) to match ipairs(config) 2015-09-26 02:44:01 -04:00
Celtic Minstrel
e46070fdbe Lua API: Add iteration metamethods for vconfig 2015-09-26 02:43:58 -04:00
gfgtdf
b892e16b94 include lua/... files after others
headers from lua/..  contain macros that can break other headers in
wesnoth, boost or other libraries.

In this case it was a macro
#define cast(t, exp) ((t)(exp))
defined in lua/llimits.h that broke a boost header.
2015-03-27 00:54:22 +01:00
gfgtdf
280dd8e7ed fix some indention 2015-03-22 01:39:55 +01:00
Ignacio R. Morelle
57ae45387a New Year copyright update 2015-01-01 19:07:35 -03:00