Commit graph

57 commits

Author SHA1 Message Date
Celtic Minstrel
f971705548 Lua API: The plugin events list is now a proper WML table, with the tags being named tuples 2024-10-07 08:42:40 -04:00
shijie.chen
d88ddec6f1
Remove unnecessary header files (#8531)
Co-authored-by: shijie.chen <shijie.chen@goland.cn>
2024-03-12 00:07:48 -04:00
P. J. McDermott
b5d073a2ad Rename src/lua/*.h to src/lua/wrapper_*.h
These will be changed to conditionally include system Lua headers,
e.g. "lua.h", instead of submodule Lua headers, e.g. "module/lua/lua.h".
If a header named "lua.h" includes "lua.h", the build will fail due to
recursion.

This can't be solved using angle brackets to include system headers,
because macos builds won't find them:

    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/registry.cpp:30:
    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/composite/aspect.hpp:24:
    In file included from /Users/runner/work/wesnoth/wesnoth/src/ai/lua/lua_object.hpp:25:
    /Users/runner/work/wesnoth/wesnoth/src/lua/lua.h:4:14: error: 'lua.h' file not found with <angled> include; use "quotes" instead
        #include <lua.h>
                 ^~~~~~~
                 "lua.h"

Renamed with (requires GNU sed):

    $ for f in src/lua/*.h; do
    >     git mv "${f}" "src/lua/wrapper_${f#src/lua/}";
    > done
    $ git grep -El -- '#[ \t]*include[ \t]+"lua/[^"]+[.]h"' src | \
    > xargs sed -Ei -- '
    > s|(#[ \t]*include[ \t]+"lua/)(lua[.]h")(            )?|\1wrapper_\2|;
    > s|(#[ \t]*include[ \t]+"lua/)(lualib[.]h")(         )?|\1wrapper_\2|;
    > s|(#[ \t]*include[ \t]+"lua/)(lauxlib[.]h")(        )?|\1wrapper_\2|;
    > '
2024-02-11 23:21:15 -06:00
pentarctagon
970163813d 2024 copyright update 2024-01-20 22:22:23 -06:00
Pentarctagon
c44cc2742e Copyright update.. 2023-04-29 10:48:11 -05:00
Tommy
a02709e0ff Remove \n from log lines with it as suffix on the final string 2022-07-20 15:20:57 +12:00
Tommy
6ace55e063 Remove << "\n"; from log lines 2022-07-20 15:20:57 +12:00
Tommy
1c25ebdfa2 Remove std::endl from log lines, now that it's added automatically 2022-07-20 15:20:57 +12:00
Tommy
6a1cda1f28 Remove newline from PLAIN_LOG entries, or use STREAMING_LOG 2022-07-20 15:20:57 +12:00
Pentarctagon
c8e948a62b std::cerr -> PLAIN_LOG, to stop bypassing the logging system 2022-07-06 20:11:11 -05:00
Pentarctagon
1a3498cbf3 Rename nowarn/ to lua/
Also cleanup the includes.
2022-03-09 15:01:37 -06:00
Pentarctagon
dd947db289 Avoid lua build warning without altering source code. 2022-03-09 15:01:37 -06:00
Pentarctagon
340023921d
2022 copyright update. 2022-03-06 19:07:13 -06:00
Pentarctagon
c4c292fa3b Replace all remaining usages if MAKE_ENUM. 2022-03-03 21:23:02 -06:00
Pentarctagon
57ce449af8
Re-add attribution to copyright notices.
These are mostly useless and outdated/wrong, but apparently it's probably illegal to remove them.
2021-07-27 20:21:38 -05:00
Pentarctagon
ba75e1af50
Copyright update.
This additionally:
* Makes all copyright notices identical aside from the starting year for Wesnoth-specific source files. Files not included: mariadbpp, lua, spirit po, xbrz, and bcrypt (crypt_blowfish).
* Removes all attribution from the files, since the vast majority of them are outdated or seemingly just outright incorrect. For example, I would guess that Dave is no longer the sole author of the majority of Wesnoth's current code.
2021-07-26 11:38:03 -05:00
Charles Dang
561cc33dc4
Upgrade to Lua 5.4.2 (#5535)
The change to static_cast for the definition of  LUAL_BUFFERSIZE replaces the fix previously used (d0100758f8) for Lua 5.3. 5.4 removes the static alternative for LUAL_BUFFERSIZE. A better solution would probably be to disable the old-style-cast warning for luaconf.h, but I can't figure out how to do that so using static_cast is the easiest solution. Do note that change will have to be applied each Lua update like the aforementioned commit.
2021-02-14 02:07:12 +11:00
Charles Dang
6e2f3e099e Removed utils/functional.hpp 2020-12-04 15:30:46 +11:00
Charles Dang
30c7a747ab Explicitly specify std::placeholders namespace for all bind placeholders
Apparently, even on Boost 1.73 without Boost placeholders specialized as is_placeholder, they were somehow
getting used in the global namespace. Would explain all the "Boost placeholders in the global namespace is
deprecated" warnings I was getting after 23d1db043f.

When testing with BOOST_BIND_NO_PLACEHOLDERS, even though I had `using namespace std::placeholders` in utils/functional.hpp,
compilation still failed in places. This confirms even more that Boost global placeholders were being used. Honestly,
it was simplest just to specify std::placeholders for everything. This also means we can remove the hack in utils/functional.hpp
designed to allow Boost placeholders to work with `std::bind`.
2020-12-04 15:28:15 +11:00
Charles Dang
2470984af3 Prepend 'SDL2/' to all SDL includes
This was needed to get the build working with vcpkg's version of SDL, where all the SDL files are
in their own SDL folder. However, our cmake config also has a note saying it was a deliberate choice
to move our SDL files *out* of their SDL2 folder due to certain distros (FreeBSD is mentioned) not
putting the files in said folder in the first place.
2019-07-22 15:35:55 +11:00
gfgtdf
120e8d9911 disallow loading lua bytecode via load/dofile (CVE-2018-1999023)
This could otherwise be used to escape the lua sandbox, as described in
multiple sources. For example one can use it to reenable the os.execute
function to do shell commands

The affected functions were
load,loadstring,wesnoth.dofile,wesnoth.require and various places in the
wesnoth source where lua chunks were loaded for example by the ai code.

This commit also changes the lua source to change luas load (which is
the same as loadstring), alternatively we could add a wrapper around the
original load function that always passes "t" as third parameter, i went
this way mostly because it was easier to implement, but also because i
was not 100% sure that is is impossible to query the upvalues of a
function via lua (wesnoth disables debug.getupvalue but still).

There is also an occurance in the application_lua_kernel that was not fixed
because i assumed that umc cannot contian application lua scipts.

As further security measure we might want to disable printing the function
adress in luas tostring for c functions, this cannot be exploited by itself
but it can be used to defeat ASLR in some cases.

(cherry-picked from commit 2554c166dd)
2018-10-07 03:23:45 +00:00
Martin Hrubý (hrubymar10)
674fda85b7 Migrate links to https if available - Fwd c18537edc0
(cherry-picked from commit bc4d22dc72)
2018-10-07 03:23:36 +00:00
Charles Dang
45f871067f Use std::size_t everywhere instead of plain size_t
Excludes:
* spirit_po/
* xBRZ/

(cherry-picked from commit fc2a58f693)
2018-10-07 03:17:59 +00:00
Gregory A Lundberg
b5f76eff79
Bump copyright to 2018 2018-01-19 00:02:20 -06:00
Charles Dang
c67f5c352a Cleaned up more unnecessary CVideo function arguments and class members
* Dropped unused CVideo class member references.
* Replaced the lone usecase of the CVideo member in loadgame with the singleton and removed said member.
* Removed CVideo references from a bunch of addon management functions.
* Cleaned up a *lot* of now-unnecessary forward CVideo declarations.
2017-11-21 03:07:23 +11:00
Charles Dang
2a6ca6cd9e Deployed more emplace_back (how do I keep missing these...)
Covers more cases of:

* push_back(std::pair
* push_back(std::make_pair
* push_back(std::make_tuple
* push_back(T) where T is an empty object of type T

Small thing I noticed: this does mean the numbers in font::subset_descriptor are no longer 'cast' to size_t before being
added to the vector, but that shouldn't matter (hopefully).
2017-04-28 17:15:13 +11: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
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
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
Gregory A Lundberg
b8244b0694 Correct the calls instead
Do not change the released Lua source code. Lua is written as standard C, but we compile it as C++ so we can use exceptions. Change the call sites to avoid the warnings about using a C cast instead of static_cast<int>().

NB: The changes to Wesnoth C++ code will be required to upgrade to Lua 5.3, anyway.

This reverts:

commit cee3ab2084
Author: Mark de Wever <koraq@xs4all.nl>
Date:   Sun Feb 5 19:55:32 2012 +0000

    Fix compiler warnings.
2016-10-17 10:34:41 -05:00
Jyrki Vesterinen
9811ad334b Fix: the plugin version of wesnoth.delay() didn't wait with --nogui
CVideo::delay() is a no-op when --nogui is used.
2016-09-28 06:57:13 +03:00
Jyrki Vesterinen
296902d426 Add a "simulate lobby activity" plugin
This is the first step towards creating artificial load and testing if the
GUI2 lobby still performs well under load.

I also implemented ability to leave the game in the GUI2 MP staging dialog.
Previously the server continued to believe that the player remains in the
game when he/she closed the MP staging dialog.
2016-09-27 22:52:07 +03: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
Celtic Minstrel
30b7ab8b2d Reduce use of const_cast 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
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
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
ca382018b7 BOOST_FOREACH -> range for 2016-04-02 09:38:29 -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
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
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
Ignacio R. Morelle
57ae45387a New Year copyright update 2015-01-01 19:07:35 -03:00
Chris Beck
95b2c41a19 lua: get rid of lua "currentscriptKey" from an old branch
This key was created in the first attempt at application scripting
but it was reappropriated to be used as the key for the
"thread table" when the present solution based on coroutines was
found. The key has been renamed and moved to its site of usage now.
2014-12-26 00:19:56 -05:00
Adam Leffew
3453afc069 Fix syntax usage for stringstream line
str() function is not being used to get data out of stringstream line.  This causes the build to fail.
2014-12-21 02:19:15 -05:00
Chris Beck
0035522bd0 add "find_level" accessor to the create engine 2014-12-19 19:47:22 -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
96ad22069f add error reporting to try to understand wesnoth.require error 2014-12-19 19:47:19 -05:00
Chris Beck
f75f40f6b2 add "describe_plugins()" to the application lua kernel 2014-12-19 19:47:19 -05:00
Chris Beck
2a8759126a add accessor functions to plugins contexts
This allows scripts to request more info from the engine.
2014-12-19 19:47:17 -05:00