From 2ea92baa1331de2725683a9ae84fea765408b68a Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 5 Mar 2021 13:58:16 -0500 Subject: [PATCH] Move some more functions to the wml module - eval_conditional and fire - the internal set|get_variable functions --- data/lua/core/wml.lua | 17 +++++++++-------- src/scripting/game_lua_kernel.cpp | 18 +++++++++++------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/data/lua/core/wml.lua b/data/lua/core/wml.lua index d3073f69f3a..371d830a53a 100644 --- a/data/lua/core/wml.lua +++ b/data/lua/core/wml.lua @@ -189,14 +189,14 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then --- Calling wesnoth.fire isn't the same as calling wesnoth.wml_actions[name] due to the passed vconfig userdata --- which also provides "constness" of the passed wml object from the point of view of the caller. --- So please don't remove since it's not deprecated. - function wesnoth.fire(name, cfg) + function wml.fire(name, cfg) wesnoth.wml_actions[name](wml.tovconfig(cfg or {})) end --[========[Basic variable access]========] -- Get all variables via wml.all_variables (read-only) - local get_all_vars_local = wesnoth.get_all_vars + local get_all_vars_local = wml.get_all_vars setmetatable(wml, { __metatable = "WML module", __index = function(self, key) @@ -214,9 +214,8 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then end }) - -- So that definition of wml.variables does not cause deprecation warnings: - local get_variable_local = wesnoth.get_variable - local set_variable_local = wesnoth.set_variable + local get_variable_local = wml.get_variable + local set_variable_local = wml.set_variable -- Get and set variables via wml.variables[variable_path] wml.variables = setmetatable({}, { @@ -440,7 +439,9 @@ wesnoth.debug = wesnoth.deprecate_api('wesnoth.debug', 'wml.tostring', 1, nil, w wesnoth.wml_matches_filter = wesnoth.deprecate_api('wesnoth.wml_matches_filter', 'wml.matches_filter', 1, nil, wml.matches_filter) if wesnoth.kernel_type() == "Game Lua Kernel" then - wesnoth.get_variable = wesnoth.deprecate_api('wesnoth.get_variable', 'wml.variables', 1, nil, wesnoth.get_variable) - wesnoth.set_variable = wesnoth.deprecate_api('wesnoth.set_variable', 'wml.variables', 1, nil, wesnoth.set_variable) - wesnoth.get_all_vars = wesnoth.deprecate_api('wesnoth.get_all_vars', 'wml.all_variables', 1, nil, wesnoth.get_all_vars) + wesnoth.get_variable = wesnoth.deprecate_api('wesnoth.get_variable', 'wml.variables', 1, nil, wml.get_variable) + wesnoth.set_variable = wesnoth.deprecate_api('wesnoth.set_variable', 'wml.variables', 1, nil, wml.set_variable) + wesnoth.get_all_vars = wesnoth.deprecate_api('wesnoth.get_all_vars', 'wml.all_variables', 1, nil, wml.get_all_vars) + wesnoth.fire = wesnoth.deprecate_api('wesnoth.fire', 'wml.fire', 1, nil, wml.fire) + wesnoth.eval_conditional = wesnoth.deprecate_api('wesnoth.eval_conditional', 'wml.eval_conditional', 1, nil, wml.eval_conditional) end diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index c37726f5993..77d64244d9e 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -3964,7 +3964,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports // Put some callback functions in the scripting environment. static luaL_Reg const callbacks[] { { "add_known_unit", &intf_add_known_unit }, - { "eval_conditional", &intf_eval_conditional }, { "get_era", &intf_get_era }, { "get_resource", &intf_get_resource }, { "get_traits", &intf_get_traits }, @@ -3986,11 +3985,9 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports { "find_vision_range", &dispatch<&game_lua_kernel::intf_find_vision_range > }, { "fire_event", &dispatch2<&game_lua_kernel::intf_fire_event, false > }, { "fire_event_by_id", &dispatch2<&game_lua_kernel::intf_fire_event, true > }, - { "get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars > }, { "get_end_level_data", &dispatch<&game_lua_kernel::intf_get_end_level_data > }, { "get_time_of_day", &dispatch<&game_lua_kernel::intf_get_time_of_day > }, { "get_max_liminal_bonus", &dispatch<&game_lua_kernel::intf_get_max_liminal_bonus > }, - { "get_variable", &dispatch<&game_lua_kernel::intf_get_variable > }, { "log_replay", &dispatch<&game_lua_kernel::intf_log_replay > }, { "log", &dispatch<&game_lua_kernel::intf_log > }, { "message", &dispatch<&game_lua_kernel::intf_message > }, @@ -4003,7 +4000,6 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports { "set_end_campaign_credits", &dispatch<&game_lua_kernel::intf_set_end_campaign_credits > }, { "set_end_campaign_text", &dispatch<&game_lua_kernel::intf_set_end_campaign_text > }, { "set_next_scenario", &dispatch<&game_lua_kernel::intf_set_next_scenario > }, - { "set_variable", &dispatch<&game_lua_kernel::intf_set_variable > }, { "simulate_combat", &dispatch<&game_lua_kernel::intf_simulate_combat > }, { "synchronize_choice", &intf_synchronize_choice }, { "synchronize_choices", &intf_synchronize_choices }, @@ -4087,10 +4083,18 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports lua_setfield(L, -2, "current"); lua_pop(L, 1); - // Add tovconfig to the WML module + // Add functions to the WML module lua_getglobal(L, "wml"); - lua_pushcfunction(L, &lua_common::intf_tovconfig); - lua_setfield(L, -2, "tovconfig"); + static luaL_Reg const wml_callbacks[] { + {"tovconfig", &lua_common::intf_tovconfig}, + {"eval_conditional", &intf_eval_conditional}, + // These aren't actually part of the API - they're used internally by the variable metatable. + { "get_variable", &dispatch<&game_lua_kernel::intf_get_variable>}, + { "set_variable", &dispatch<&game_lua_kernel::intf_set_variable>}, + { "get_all_vars", &dispatch<&game_lua_kernel::intf_get_all_vars>}, + { nullptr, nullptr } + }; + luaL_setfuncs(L, wml_callbacks, 0); lua_pop(L, 1); // Add functions to the map module