diff --git a/src/bind_config.c b/src/bind_config.c index 537dd1501..4e3ba38db 100644 --- a/src/bind_config.c +++ b/src/bind_config.c @@ -4,9 +4,27 @@ #include #include #include +#include #include #include +#include "kernel/building.h" +#include "kernel/race.h" +#include "kernel/ship.h" +#include "kernel/spell.h" +#include "kernel/spellbook.h" +#include "kernel/terrain.h" + +void config_reset(void) { + default_locale = 0; + free_locales(); + free_spells(); + free_buildingtypes(); + free_shiptypes(); + free_races(); + free_spellbooks(); +} + int config_parse(const char *json) { cJSON * conf = cJSON_Parse(json); @@ -26,8 +44,8 @@ int config_parse(const char *json) strncpy(buffer, xp, sizeof(buffer)); buffer[9] = 0; log_error("json parse error in line %d, position %d, near `%s`\n", line, ep-lp, buffer); - return 1; } + return 1; } int config_read(const char *filename) diff --git a/src/bind_config.h b/src/bind_config.h index cae19a485..27f59f853 100644 --- a/src/bind_config.h +++ b/src/bind_config.h @@ -4,6 +4,7 @@ extern "C" { #endif +void config_reset(void); int config_parse(const char *json); int config_read(const char *filename); diff --git a/src/config.pkg b/src/config.pkg index d892a2f1b..e73d11602 100644 --- a/src/config.pkg +++ b/src/config.pkg @@ -2,6 +2,7 @@ $#include "bind_config.h" module eressea { module config { + void config_reset @ reset(void); void config_read @ read(const char *filename); void config_parse @ parse(const char *json); } diff --git a/src/config.pkg.c b/src/config.pkg.c index 44beb9577..d1f3aa0c6 100644 --- a/src/config.pkg.c +++ b/src/config.pkg.c @@ -25,6 +25,30 @@ static void tolua_reg_types (lua_State* tolua_S) { } +/* function: config_reset */ +static int tolua_config_eressea_config_reset00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isnoobj(tolua_S,1,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + { + config_reset(); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'reset'.",&tolua_err); + return 0; +#endif +} + /* function: config_read */ static int tolua_config_eressea_config_read00(lua_State* tolua_S) { @@ -88,6 +112,7 @@ LUALIB_API int luaopen_config (lua_State* tolua_S) tolua_beginmodule(tolua_S,"eressea"); tolua_module(tolua_S,"config",0); tolua_beginmodule(tolua_S,"config"); + tolua_function(tolua_S,"reset",tolua_config_eressea_config_reset00); tolua_function(tolua_S,"read",tolua_config_eressea_config_read00); tolua_function(tolua_S,"parse",tolua_config_eressea_config_parse00); tolua_endmodule(tolua_S); diff --git a/src/kernel/config.c b/src/kernel/config.c index 45301077e..85e83bf6e 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -2927,13 +2927,6 @@ void free_gamedata(void) free_units(); free_regions(); free_borders(); - default_locale = 0; - free_locales(); - free_spells(); - free_buildingtypes(); - free_shiptypes(); - free_races(); - free_spellbooks(); for (i=0;i!=MAXLOCALES;++i) { if (defaults[i]) { diff --git a/src/tests.c b/src/tests.c index f3dcaf312..c95d30fbe 100644 --- a/src/tests.c +++ b/src/tests.c @@ -60,6 +60,13 @@ void test_cleanup(void) test_clear_resources(); global.functions.maintenance = NULL; global.functions.wage = NULL; + default_locale = 0; + free_locales(); + free_spells(); + free_buildingtypes(); + free_shiptypes(); + free_races(); + free_spellbooks(); free_gamedata(); } diff --git a/tests/config.lua b/tests/config.lua index 9e0beae01..9739d5113 100644 --- a/tests/config.lua +++ b/tests/config.lua @@ -4,6 +4,7 @@ module("tests.eressea.config", package.seeall, lunit.testcase ) function setup() eressea.free_game() + eressea.config.reset(); end function test_read_race() diff --git a/tests/ships.lua b/tests/ships.lua index 763492d3c..1c58547f7 100644 --- a/tests/ships.lua +++ b/tests/ships.lua @@ -40,6 +40,7 @@ function setup() } }]] + eressea.config.reset() eressea.config.parse(conf) eressea.locale.create("en") end