Skip to content

Commit

Permalink
Add a command-line option that makes deprecated Lua stuff evaporate
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 17, 2021
1 parent a87d1a0 commit 51abfbe
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/lua/core.lua
Expand Up @@ -251,7 +251,7 @@ local _ = wesnoth.textdomain "wesnoth"
---- elem: The actual element being deprecated
---- detail_msg: An optional message to add to the deprecation message
function wesnoth.deprecate_api(elem_name, replacement, level, version, elem, detail_msg)
if wesnoth.strict then return nil end
if wesnoth.game_config.strict_lua then return nil end
local message = detail_msg or ''
if replacement then
message = message .. " " .. (_"(Note: You should use $replacement instead in new code)"):vformat{replacement = replacement}
Expand Down
3 changes: 3 additions & 0 deletions doc/man/wesnoth.6
Expand Up @@ -104,6 +104,9 @@ information about command mode).
.B --debug-lua
enables some Lua debugging mechanisms
.TP
.B --strict-lua
disallow deprecated Lua API calls
.TP
.BI -D,--diff \ left-file \ right-file
diffs the two WML files; does not preprocess them first (to do that, run them through
.B -p
Expand Down
4 changes: 4 additions & 0 deletions src/commandline_options.cpp
Expand Up @@ -73,6 +73,7 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
, data_dir()
, debug(false)
, debug_lua(false)
, strict_lua(false)
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
, debug_dot_domain()
, debug_dot_level()
Expand Down Expand Up @@ -174,6 +175,7 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
("data-path", "prints the path of the data directory and exits.")
("debug,d", "enables additional command mode options in-game.")
("debug-lua", "enables some Lua debugging mechanisms")
("strict-lua", "disallow deprecated Lua API calls")
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
("debug-dot-level", po::value<std::string>(), "sets the level of the debug dot files. <arg> should be a comma separated list of levels. These files are used for debugging the widgets especially the for the layout engine. When enabled the engine will produce dot files which can be converted to images with the dot tool. Available levels: size (generate the size info of the widget), state (generate the state info of the widget).")
("debug-dot-domain", po::value<std::string>(), "sets the domain of the debug dot files. <arg> should be a comma separated list of domains. See --debug-dot-level for more info. Available domains: show (generate the data when the dialog is about to be shown), layout (generate the data during the layout phase - might result in multiple files). The data can also be generated when the F12 is pressed in a dialog.")
Expand Down Expand Up @@ -346,6 +348,8 @@ commandline_options::commandline_options(const std::vector<std::string>& args)
debug = true;
if (vm.count("debug-lua"))
debug_lua = true;
if (vm.count("strict-lua"))
strict_lua = true;
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
if (vm.count("debug-dot-domain")) {
debug_dot_domain = vm["debug-dot-domain"].as<std::string>();
Expand Down
2 changes: 2 additions & 0 deletions src/commandline_options.hpp
Expand Up @@ -74,6 +74,8 @@ class commandline_options
bool debug;
/** True if --debug-lua was given in the commandline. Enables some Lua debugging mechanisms. */
bool debug_lua;
/** True if --strict-lua was given in the commandline. Disallows use of deprecated APIs. */
bool strict_lua;
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
/** Non-empty if --debug-dot-domain was given on the command line. */
std::optional<std::string> debug_dot_domain;
Expand Down
1 change: 1 addition & 0 deletions src/game_config.cpp
Expand Up @@ -98,6 +98,7 @@ std::vector<server_info> server_list;
bool
debug_impl = false,
debug_lua = false,
strict_lua = false,
editor = false,
ignore_replay_errors = false,
mp_debug = false,
Expand Down
2 changes: 1 addition & 1 deletion src/game_config.hpp
Expand Up @@ -59,7 +59,7 @@ namespace game_config
/** Default percentage gold carried over to the next scenario. */
extern const int gold_carryover_percentage;

extern bool debug_lua, editor, ignore_replay_errors, mp_debug,
extern bool debug_lua, strict_lua, editor, ignore_replay_errors, mp_debug,
exit_at_end, no_delay, disable_autosave, no_addons;

extern const bool& debug;
Expand Down
1 change: 1 addition & 0 deletions src/scripting/lua_kernel_base.cpp
Expand Up @@ -897,6 +897,7 @@ int lua_kernel_base::impl_game_config_get(lua_State* L)
return_string_attrib("version", game_config::wesnoth_version.str());
return_bool_attrib("debug", game_config::debug);
return_bool_attrib("debug_lua", game_config::debug_lua);
return_bool_attrib("strict_lua", game_config::strict_lua);
return_bool_attrib("mp_debug", game_config::mp_debug);
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/wesnoth.cpp
Expand Up @@ -426,6 +426,10 @@ static int process_command_args(const commandline_options& cmdline_opts)
game_config::debug_lua = true;
}

if(cmdline_opts.strict_lua) {
game_config::strict_lua = true;
}

if(cmdline_opts.gunzip) {
const std::string input_file(*cmdline_opts.gunzip);
if(!filesystem::is_gzip_file(input_file)) {
Expand Down

0 comments on commit 51abfbe

Please sign in to comment.