Commit graph

65 commits

Author SHA1 Message Date
Charles Dang
24577e117d Merge pull request #716 from wesnoth/boost_trimming
Boost-related cleanups
2016-07-30 15:51:30 +11:00
Charles Dang
d778db8af6 Convert uses of boost integer types to their stdlib equivalents 2016-07-29 23:18:10 -04:00
gfgtdf
6f021631e1 replace some std::bind with lambdas 2016-07-29 14:36:22 +02:00
Charles Dang
05092ba2f6 Refactor most boost pointer related stuff to use their stdlib counterparts
This constitutes drop-in replacements for:

* boost::shared_ptr
* boost::scoped_ptr
* boost::weak_ptr
* boost::enable_shared_from_this
* boost::static_pointer_cast
* boost::dynamic_pointer_cast

This excludes boost::intrusive_ptr, except for stray includes. Refactoring that is more complicated.
2016-07-25 09:28:42 +11:00
Celtic Minstrel
7286ea8e0f Merge pull request #661 from spixi/name_and_map_generator
Improvements in the name and map generators
2016-07-18 01:10:46 -04:00
Celtic Minstrel
7e04c7f8e9 Fix issues with constructing name generators from Lua 2016-07-12 11:08:34 -04:00
Celtic Minstrel
c39af95a44 Move name generator and formula API to base Lua kernel 2016-07-12 11:08:33 -04:00
gfgtdf
bbc32856f1 handle [args] also in [lua] tags outside events. 2016-07-09 21:42:10 +02:00
Charles Dang
0ca4e6c943 Convert uses of boost functional to standard library variants
This commit converts the following function calls:

* boost::bind                          -> std::bind
* boost::function and boost::functionN -> std::function
* boost::ref and boost::cref           -> std::ref and std::cref
* boost::bad_function_call             -> std::bad_function_call

In the process, it was discovered that std::bind has trouble with overloaded
functions. There were two such cases in the code:

* gui2::twindow had an ancient unused overload to draw(). The overload was removed.
* gui2::trepeating_button was binding tdispatcher::fire. This case was converted
  to a lambda.
2016-04-04 02:20:52 +11:00
Celtic Minstrel
86b4680371 Use vector/templating for Lua-like bulk registration functions 2016-03-31 02:13:38 -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
gfgtdf
9c59311b41 add function wesnoth.read_file
It can for example used to read map files.
2016-02-18 23:08:39 +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
Celtic Minstrel
376020097f Port [object] ActionWML tag from C++ to Lua
Lua API additions:
- wesnoth.show_popup_dialog()
- optional write_to_mods parameter to wesnoth.add_modification
2015-09-19 12:13:25 -04:00
Celtic Minstrel
91ac90db11 Lua API: Add wesnoth.show_message_dialog() 2015-09-18 00:23:54 -04:00
Ignacio R. Morelle
b4de73f83b Add wesnoth.set_dialog_visible function
Sets a given widget's visibility property.
2015-08-22 23:07:03 -03:00
Ignacio R. Morelle
ba6257129a Add wesnoth.set_dialog_focus function
Gives keyboard focus to the given widget.
2015-08-22 22:12:02 -03:00
gfgtdf
90ee0a2e9b add wesnoth.remove_dialog_item
a function to remove items from gui2 lists
2015-05-26 03:28:19 +02:00
Chris Beck
bce5fb22e5 fixup HEAD^
use tab characters between lua print arguments, and no trailing tab
2015-04-29 17:18:03 -04:00
Chris Beck
c095029d68 lua print: put a space between items 2015-04-29 13:35:11 -04:00
Chris Beck
1bd5cfb756 fixup lua dofile to use a protected call
thanks to gfgtdf for pointing this out earlier, it can cause a
lua kernel panic if an error occurs which is not what we want.
2015-04-11 22:55:30 -04:00
Chris Beck
9812e14acd change member function registration to use templates and extraspace
This is used instead of the boost::bind and boost::function method
introduced before. It's a bit simpler than the boost::function code
in lua_cpp_function, and a bit faster / less can go wrong when we
don't use boost::fucntion.

It also fixes a potential future use-case -- if a lua state is
copied, but many of the functions in the environment are made with
boost bind, they become bad pointers since they point to the old
lua state, and there is no easy way to retrieve them. Using lua
extra space instead of bind ties the lua_State more tightly to our
C++ representation of it.
2015-04-10 15:02:12 -04:00
gfgtdf
7dc59fcab5 Enable tree_view gui2 widget for lua
wesnoth.add_dialog_tree_node to add nodes to a tree_value
wesnoth.set_dialog_callback support for tree_views (triggers when the
selected node was changed)
wesnoth.get_dialog_value support for tree_views returns an array of
integers that describe the path to the currebntly selected node.
2015-04-08 16:35:10 +02:00
Chris Beck
7a870f016a fixup lua print with null strings 2015-04-05 12:31:34 -04:00
gfgtdf
38ed3a3c97 Use given seed in lua random map generator
Thew seed can be passed in the editor in the generate map dialog, just
like for the other generators.
2015-03-30 00:58:15 +02:00
gfgtdf
6655b186b1 LUAI_EXTRASPACE
We use LUAI_EXTRASPACE to add a pointer to the lua_kernel_base in the lua_State
stucture, this makes is very easy to get a reference to the lua_kernel in
functions that take a lua_State* as an argument.
2015-03-30 00:58:14 +02: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
Elvish_Hunter
6c47130adf Lua: enabled support for the bit32 (bitwise operations) library 2015-01-14 12:22:44 +01:00
Ignacio R. Morelle
57ae45387a New Year copyright update 2015-01-01 19:07:35 -03:00
Chris Beck
0f9bd0a929 lua: move gettext metatable registration to lua_common 2014-12-25 14:11:12 -05:00
Chris Beck
93fe16a832 lua: move metatable registration for lua_common
this gives better encapsulation
2014-12-25 13:42:54 -05:00
Chris Beck
06ca78fec4 bugfix: intf_require would segfault if a thread called it
The problem was that intf_require would assume use the wrong
lua_State* since it finds it using the kernel's this pointer. This
commit gives a version of "protected_call" which allows to use the
callback's lua_State*.
2014-12-19 19:47:20 -05:00
Chris Beck
3e73ec2f68 fixups: don't construct string from NULL, avoid complicated API
In the error handling routines for compiling and running a script
at runtime, don't construct a string directly from lua_tostring,
because if it is null that is a runtime error. Instead check for
this scenario.

In intf_require, when getting the "wesnoth" global, luaW_getglobal
is unnecessary and lua_getglobal should be prefered.
2014-12-19 19:47:20 -05:00
Chris Beck
96ad22069f add error reporting to try to understand wesnoth.require error 2014-12-19 19:47:19 -05:00
Chris Beck
6032372e4a add plugins context, manager, create lua thread object
This collection of classes provides a framework whereby the engine
may provide scripting capabilities in any "context". A C++
function may declare a plugin context by providing a list of names
function objects, then may call "play_slice()" on this context to
transfer control to lua. A lua script may generate some arguments
and request to call some of these, then yield to the engine. C++
will run them until one of them signals an error, or that the
context is now invalid (using a boolean return value).

The intended semantics is that lua may only make requests
corresponding to the current context. As soon as a new context
is used (play_slice() is called again) the old context is invalid
from lua's point of view -- calling those functions is a lua
error but not undefined behavior. This should be the case even if
the old context has not been destroyed yet in C++, for instance
if a lua request resulted in a new context being created. There is
a system of locks in place to ensure that when old contexts are
invalidated, stale requests are discarded.

We also add the coroutine library to our lua base. This because
threads are run as coroutines, and writing them requires the use
of coroutine yield from the standard library.
2014-12-19 19:47:17 -05:00
Chris Beck
bae61e944f fixup wesnoth.require after commit HEAD^
It was implicitly assuming that loadfile takes arguments from the
bottom of the stack.
2014-12-05 15:26:15 -05:00
anonymissimus
5ad0e47eab fix warning about unreferenced variable 2014-11-30 23:45:57 +01:00
Chris Beck
84f5677155 add wesnoth.show_lua_console, as a debugging aide
This allows some sort of "drop into debug" mode for lua if your
script detects an error.

We could consider to actually add an "option to attach debugger"
as an error handling mechanism, but it might be complicated
because of wesnoth exceptions which must go through lua and be
treated as lua errors, and we cannot handle two exceptions at once
obviously, so the lua interpreter is probably not safe to run that
way in general. Anyways this commit does not do that.
2014-11-28 18:11:32 -05:00
Chris Beck
99678ef29a refactor lua file ops: use fileops::load, but use kernel pcall 2014-11-24 23:13:36 -05:00
Chris Beck
9eaba64651 refactor game_lua_kernel not to use resources:: for gamestate
This commit changes the majority of the wesnoth callback functions
for the game lua kernel to be private methods of the game lua
kernel. The game lua kernel is given direct access, via it's ctor,
to references of many of the things provided by resources. The
call back functions are modified to access these private reference
variables instead of resources, and they are added to the
scripting environment using the lua cpp function mechanism.

This greatly improves encapsulation and will eventually lead to
eliminating the resources pointers from the game lua kernel
entirely.
2014-11-24 17:13:03 -05:00
Chris Beck
48a14ddadf move lua fcn 'wesnoth.tovconfig' to lua kernel base / lua common
there was no reason for it to only be in the game kernel, most
other vconfig functions were already in lua common.
2014-11-24 01:12:25 -05:00
Chris Beck
3b1c52f3c8 move lua boost::function wrapper to scripting/lua_cpp_function.?pp 2014-11-23 20:24:47 -05:00
Chris Beck
93becab0ac clean up some comments, improve type-safety in lua boost function 2014-11-23 19:11:41 -05:00
Chris Beck
f0fac7f367 add a "__tostring" method for boost functions
It makes it easier to realize that they are functions when in the
console.
2014-11-23 19:02:07 -05:00
Chris Beck
8adfd3a38c fixup lua <-> boost function binding system
The solution in place was working but it was flawed in that unlike
with normal lua callbacks, the callbacks would find the userdata
with a pointer to themselves as the first item on the stack. This
breaks the normal lua stack discipline for callback functions.

This commit makes it work normally, removing the stack entry for
the function before it is called, and also making a local copy
of the function pointer in case the lua garbage collector should
deallocate and destroy it when it is removed from the stack.
2014-11-23 18:27:05 -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
4a2eb88607 allow lua console to handle expressions
Implemented using ilua, and "experimental compilation" technique.
2014-11-21 23:01:10 -05:00
Chris Beck
ba4276ea31 add "ilua" helper functions for lua interpreter 2014-11-21 22:22:43 -05:00
Chris Beck
e89383d1aa move lua Rng wrapper to the lua kernel base 2014-11-20 16:58:12 -05:00