config returns a value, so we can assert corrrect JSON syntax

This commit is contained in:
Enno Rehling 2014-06-27 07:36:18 -07:00
parent 7012740172
commit 9b01b71a19
3 changed files with 15 additions and 8 deletions

View File

@ -3,8 +3,8 @@ $#include "bind_config.h"
module eressea { module eressea {
module config { module config {
void config_reset @ reset(void); void config_reset @ reset(void);
void config_read @ read(const char *filename); int config_read @ read(const char *filename);
void config_parse @ parse(const char *json); int config_parse @ parse(const char *json);
} }
} }

View File

@ -64,10 +64,11 @@ static int tolua_config_eressea_config_read00(lua_State* tolua_S)
{ {
const char* filename = ((const char*) tolua_tostring(tolua_S,1,0)); const char* filename = ((const char*) tolua_tostring(tolua_S,1,0));
{ {
config_read(filename); int tolua_ret = (int) config_read(filename);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
} }
} }
return 0; return 1;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'read'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'read'.",&tolua_err);
@ -90,10 +91,11 @@ static int tolua_config_eressea_config_parse00(lua_State* tolua_S)
{ {
const char* json = ((const char*) tolua_tostring(tolua_S,1,0)); const char* json = ((const char*) tolua_tostring(tolua_S,1,0));
{ {
config_parse(json); int tolua_ret = (int) config_parse(json);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
} }
} }
return 0; return 1;
#ifndef TOLUA_RELEASE #ifndef TOLUA_RELEASE
tolua_lerror: tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'parse'.",&tolua_err); tolua_error(tolua_S,"#ferror in function 'parse'.",&tolua_err);

View File

@ -3,7 +3,7 @@ require "lunit"
module("tests.ships", package.seeall, lunit.testcase) module("tests.ships", package.seeall, lunit.testcase)
function setup() function setup()
eressea.free_game() eressea.game.reset()
eressea.settings.set("nmr.removenewbie", "0") eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0") eressea.settings.set("nmr.timeout", "0")
eressea.settings.set("rules.ships.storms", "0") eressea.settings.set("rules.ships.storms", "0")
@ -39,11 +39,16 @@ function setup()
"de" : { "de" : {
"move" : "NACH" "move" : "NACH"
} }
},
"strings" : {
"de" : {
"harbour" : "Hafen"
}
} }
}]] }]]
eressea.config.reset() eressea.config.reset()
eressea.config.parse(conf) assert(eressea.config.parse(conf)==0)
end end
function test_sail_oceans() function test_sail_oceans()