Commit graph

77 commits

Author SHA1 Message Date
Celtic Minstrel
09d35947f4 Fix Lua-invoked dialogs not showing before prestart
Instead of passing the video object to the Lua kernel, the game now simply
fetches the video singleton when displaying dialogs. This means there is
no longer any need to store a reference to the video object.
2016-10-18 12:48:15 -04:00
GregoryLundberg
8839a5ee8e Only on gcc
Use #if guard to prevent gcc pragma being seen elsewhere.
2016-10-17 10:34:43 -05:00
Gregory A Lundberg
fb82f6a259 Add Lua utf8 library
Safe for scripting. Let the users have it.
2016-10-17 10:34:42 -05:00
Gregory A Lundberg
8e7b28cde2 Move local changes to proper place
luaconf.h provides a place for us to make changes, avoiding the need to change the original definitions. Move everything down there. This encompases the following changes:

1) Disable compatibility with old versions of Lua in the C++. Compatability is maintained only for the Lua runtime. Only one correction was needed: in application_lua_kernel.cpp

2) Change how the backpointer is defined, for forward compatability with Lua 5.3. This effected only one line: in lua_kernel_base.cpp. Using the Lua 5.3 macro caused a GCC warning, suppressed it for that line.

3) Certain Windows-only features are no longer available in the Lua runtime. These features are all in the Lua io module, which we don't allow access to, so this is a non-change for the runtime.

4) Lua will behave as if it is a standard C environment. This, again, mainly effects the Windows environment and features we don't allow access to in the runtime.
2016-10-17 10:34:41 -05:00
Chris Beck
4dea265113 add code comments and minor fixups in lua_kernel_base
adds code comments for a number of method declarations in header,
and in the implementation file, prefixes many method calls with
`this->`. This convention disambiguates whether the call is a method
of the class or a function at global scope. On some projects like
gcc, it is part of the coding standard to do this to avoid subtle
bugs -- I have come to believe that it makes your code more easily
readable, even if it is a little more typing.
2016-10-07 19:35:02 -04:00
Chris Beck
d82d8c9137 fixup previous commit: don't compare std::function with nullptr 2016-10-07 19:15:03 -04:00
Jyrki Vesterinen
c2d3607d49 Restrict preference access to plugins
@gfgtdf pointed out that preferences contain MP passwords. We can't allow
untrusted code to access them. Since we only need preference access from
plugins for now, the simplest way to avoid security issues is to block Lua
code outside of plugins from accessing preferences at all.
2016-09-24 18:16:55 +03:00
Jyrki Vesterinen
76d407e733 Expose preferences to Lua 2016-09-24 18:16:41 +03:00
Celtic Minstrel
144ce315c3 Lua GUI2: Support stacked widgets and unit preview pane, and add show_menu function 2016-08-28 00:24:19 -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
797613f760 Refactor some duplicate code in Lua API 2016-08-20 20:38:46 -04:00
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