Lua API: Make wml.tostring a lossless conversion

This means that wml.parse(wml.tostring(cfg)) now returns a perfect clone of the original config.

Addresses #3696
This commit is contained in:
Celtic Minstrel 2018-11-11 19:23:18 -05:00
parent 45689305eb
commit e692294532
2 changed files with 6 additions and 4 deletions

View file

@ -35,6 +35,7 @@
### Lua API
* 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.
### User Interface
* Don't show in the sidebar the time of day schedule of a shrouded hex. (issue #3638)
### Packaging

View file

@ -392,10 +392,11 @@ static int intf_format_list(lua_State* L)
* - Arg 1: wml table or vconfig userdata
* - Ret 1: string
*/
static int intf_debug(lua_State* L) {
static int intf_wml_tostring(lua_State* L) {
const config& arg = luaW_checkconfig(L, 1);
const std::string& result = arg.debug();
lua_pushstring(L, result.c_str());
std::ostringstream stream;
write(stream, arg);
lua_pushstring(L, stream.str().c_str());
return 1;
}
@ -559,7 +560,7 @@ lua_kernel_base::lua_kernel_base()
static luaL_Reg const callbacks[] {
{ "compare_versions", &intf_compare_versions },
{ "debug", &intf_debug },
{ "debug", &intf_wml_tostring },
{ "deprecated_message", &intf_deprecated_message },
{ "have_file", &lua_fileops::intf_have_file },
{ "read_file", &lua_fileops::intf_read_file },