Skip to content

Commit

Permalink
Move some more functions to the wml module
Browse files Browse the repository at this point in the history
- eval_conditional and fire
- the internal set|get_variable functions
  • Loading branch information
CelticMinstrel committed Mar 23, 2021
1 parent cb25541 commit de4a59d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
15 changes: 8 additions & 7 deletions data/lua/core/wml.lua
Expand Up @@ -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)
Expand All @@ -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({}, {
Expand Down Expand Up @@ -431,7 +430,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_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, wesnoth.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
17 changes: 10 additions & 7 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -3920,7 +3920,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 },
Expand All @@ -3941,11 +3940,9 @@ game_lua_kernel::game_lua_kernel(game_state & gs, play_controller & pc, reports
{ "find_vacant_tile", &dispatch<&game_lua_kernel::intf_find_vacant_tile > },
{ "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 > },
Expand All @@ -3958,7 +3955,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 },
Expand Down Expand Up @@ -4039,10 +4035,17 @@ 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>},
};
luaL_setfuncs(L, wml_callbacks, 0);
lua_pop(L, 1);

// Add functions to the map module
Expand Down

0 comments on commit de4a59d

Please sign in to comment.