Commit graph

21 commits

Author SHA1 Message Date
Celtic Minstrel
744cdb2085 Lua API: Correct __metatable for wesnoth.preferences 2024-10-07 08:42:41 -04:00
Pentarctagon
971073055e
Refactor the preferences into a proper singleton. (#8930)
The current preferences handling is a mess:
* it's essentially a global config object that anything can modify in any way the caller wants, which is managed across multiple source files which have their own oddities and interdependencies.
* the general preferences has its own bit of SDL event handling and while I get the idea behind `events::sdl_handler` there's no reason to have SDL events handled in the preferences instead of just calling the relevant preferences setter for each event when it happens.
* the general preferences is where most of the preferences are handled and has its `base_manager` struct, which is part of the `manager` struct in the game preferences, which is then implicitly initialized as part of game_launcher's constructor.
* the editor preferences are the only preferences in a sub-namespace `preferences::editor` while all other preferences are just in the `preferences` namespace.
* the display, editor, and lobby preferences are all dependent on including the game preferences, the credentials are dependent on including the general preferences (but not the game preferences), the game preferences are dependent on including the general preferences, and the advanced preferences are entirely their own thing which is dependent on none of the other preference functionality and manages its own singleton.
* nothing checks whether the preferences file has actually been loaded before allowing values to be read from or written to the preferences config - if you attempt to get a value too early in wesnoth's initialization it will silently just give you whatever the default value for that preference happens to be.

With this there is instead a single access point (with exceptions handled via friend functions/classes), all predefined preferences are accessed via their own setter/getter, and all mainline preferences are defined in a single file (preference_list.hpp) so it's easily findable what preferences exist and where they're used. Having the list of all mainline preferences listed out also allows the lua preferences API to provide that full list rather than just the list of the preferences that have been set so far. Also it now checks for whether the location of the preferences file is known before attempting to load the preferences file and asserts if someone attempts to use the preferences too early.
2024-06-09 11:34:09 -05: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
Celtic Minstrel
e5d5180b61 Enable dir() on wesnoth.colors and wesnoth.preferences
Note that using it on wesnoth.preferences only returns preferences that are currently set and may omit some preferences that are possible but currently unset. However, it DOES include all registered advanced preferences even if they are unset.
2022-06-20 20:54:28 -04: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
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
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
Gregory A Lundberg
b5f76eff79
Bump copyright to 2018 2018-01-19 00:02:20 -06:00
Charles Dang
e4f03fe459 Moved all preferences source files into a single folder 2017-05-04 11:04:19 +11:00
Celtic Minstrel
b4dc11ce36 Belated 2017 copyright update 2017-03-19 10:05:38 -04:00
Gregory A Lundberg
d31555f8cf Pedantic includes
Change all includes to start at the base instead of assuming the directory where included from.

This makes it more apparent exactly which header has been included, since many have the same name.

This also allows moving all header files out of the src directory.
2016-11-11 11:00:22 -06:00
Gregory A Lundberg
465ab8fda2 Fix errors: #include <> should be "" 2016-11-11 10:57:48 -06:00
Jyrki Vesterinen
9200fc8dba Add two copyright blocks 2016-10-16 19:25:48 +03:00
Jyrki Vesterinen
02b2ac5a17 Address feedback
* Changed the plugin preference API to use luaW_pushscalar() and
luaW_toscalar() to handle preference values.
* Set the __metatable field in the "preferences" table, which blocks Lua
code from changing the metatable and allows developers to query where the
metatable originates.
* Added empty lines to the end of new files.
2016-09-24 18:30:35 +03:00
Jyrki Vesterinen
76d407e733 Expose preferences to Lua 2016-09-24 18:16:41 +03:00