Compare commits

...

1 Commits

Author SHA1 Message Date
Enno Rehling 7cab158af8 try to fix some binding errors 2021-03-14 19:13:05 +01:00
4 changed files with 52 additions and 29 deletions

View File

@ -51,16 +51,18 @@ int eressea_read_orders(const char * filename) {
} }
int eressea_export_json(const char * filename, int flags) { int eressea_export_json(const char * filename, int flags) {
FILE *F = fopen(filename, "w"); if (filename) {
if (F) { FILE *F = fopen(filename, "w");
stream out = { 0 }; if (F) {
int err; stream out = { 0 };
fstream_init(&out, F); int err;
err = json_export(&out, flags); fstream_init(&out, F);
fstream_done(&out); err = json_export(&out, flags);
return err; fstream_done(&out);
return err;
}
perror(filename);
} }
perror(filename);
return -1; return -1;
} }

View File

@ -125,6 +125,16 @@ static int tolua_ship_set_display(lua_State * L)
static int tolua_ship_get_units(lua_State * L) static int tolua_ship_get_units(lua_State * L)
{ {
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
if (
!tolua_isusertype(L,1,"ship",0,&tolua_err) ||
!tolua_isuserdata(L,2,0,&tolua_err) ||
!tolua_isnoobj(L,3,&tolua_err)
) goto tolua_lerror;
else
#endif
{
ship *sh = (ship *)tolua_tousertype(L, 1, NULL); ship *sh = (ship *)tolua_tousertype(L, 1, NULL);
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *)); unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
unit *u = sh->region->units; unit *u = sh->region->units;
@ -138,6 +148,12 @@ static int tolua_ship_get_units(lua_State * L)
lua_pushcclosure(L, tolua_unitlist_nexts, 1); lua_pushcclosure(L, tolua_unitlist_nexts, 1);
return 1; return 1;
}
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(L, "#ferror in function 'export'.", &tolua_err);
return 0;
#endif
} }
static int tolua_ship_create(lua_State * L) static int tolua_ship_create(lua_State * L)

View File

@ -760,17 +760,20 @@ static int tolua_unit_clear_attribs(lua_State *L) {
} }
static int tolua_unit_has_attrib(lua_State *L) { static int tolua_unit_has_attrib(lua_State *L) {
unit *u = (unit *)tolua_tousertype(L, 1, 0); unit *u = (unit *)tolua_tousertype(L, 1, NULL);
const char *name = tolua_tostring(L, 2, 0); const char *name = tolua_tostring(L, 2, NULL);
attrib * a = u->attribs; if (u && name) {
while (a) { attrib * a = u->attribs;
if (strcmp(a->type->name, name) == 0) { while (a) {
break; if (strcmp(a->type->name, name) == 0) {
break;
}
a = a->nexttype;
} }
a = a->nexttype; lua_pushboolean(L, a != NULL);
return 1;
} }
lua_pushboolean(L, a != NULL); return 0;
return 1;
} }
static int tolua_unit_get_key(lua_State * L) static int tolua_unit_get_key(lua_State * L)

View File

@ -293,17 +293,19 @@ static int tolua_create_curse(lua_State * L)
ap = &target->attribs; ap = &target->attribs;
} }
if (ap) { if (ap) {
const char *cname = tolua_tostring(L, 3, 0); const char *cname = tolua_tostring(L, 3, NULL);
const curse_type *ctype = ct_find(cname); if (cname) {
if (ctype) { const curse_type *ctype = ct_find(cname);
float vigour = (float)tolua_tonumber(L, 4, 0); if (ctype) {
int duration = (int)tolua_tonumber(L, 5, 0); float vigour = (float)tolua_tonumber(L, 4, 0);
float effect = (float)tolua_tonumber(L, 6, 0); int duration = (int)tolua_tonumber(L, 5, 0);
int men = (int)tolua_tonumber(L, 7, 0); /* optional */ float effect = (float)tolua_tonumber(L, 6, 0);
curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men); int men = (int)tolua_tonumber(L, 7, 0); /* optional */
if (c) { curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men);
tolua_pushboolean(L, true); if (c) {
return 1; tolua_pushboolean(L, true);
return 1;
}
} }
} }
} }