Lua API: Add wml.clone()

This commit is contained in:
Celtic Minstrel 2018-11-11 19:37:49 -05:00
parent e692294532
commit 3016d92811
2 changed files with 22 additions and 0 deletions

View file

@ -36,6 +36,7 @@
* Allow specifying custom flags (in particular teleport) when using a custom cost function in wesnoth.find_path
* Add wml.load() and wml.parse() functions
* wml.tostring() now outputs a string that can be parsed back to WML without loss of data.
* Add wml.clone() function that performs a deep copy of a config or vconfig.
### User Interface
* Don't show in the sidebar the time of day schedule of a shrouded hex. (issue #3638)
### Packaging

View file

@ -465,6 +465,26 @@ static int intf_parse_wml(lua_State* L)
return 1;
}
/**
* Returns a clone (deep copy) of the passed config, which can be either a normal config or a vconfig
* If it is a vconfig, the underlying config is also cloned.
* - Arg 1: a config
* - Ret: the cloned config
*/
static int intf_clone_wml(lua_State* L)
{
const vconfig* vcfg = nullptr;
const config& cfg = luaW_checkconfig(L, 1, vcfg);
if(vcfg) {
config clone_underlying = vcfg->get_config();
vconfig clone(clone_underlying);
luaW_pushvconfig(L, clone);
} else {
luaW_pushconfig(L, cfg);
}
return 1;
}
// End Callback implementations
// Template which allows to push member functions to the lua kernel base into lua as C functions, using a shim
@ -613,6 +633,7 @@ lua_kernel_base::lua_kernel_base()
static luaL_Reg const wml_callbacks[]= {
{ "load", &intf_load_wml},
{ "parse", &intf_parse_wml},
{ "clone", &intf_clone_wml},
{ nullptr, nullptr },
};
lua_newtable(L);