forked from github/server
Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Enno Rehling | 7cab158af8 |
|
@ -51,16 +51,18 @@ int eressea_read_orders(const char * filename) {
|
|||
}
|
||||
|
||||
int eressea_export_json(const char * filename, int flags) {
|
||||
FILE *F = fopen(filename, "w");
|
||||
if (F) {
|
||||
stream out = { 0 };
|
||||
int err;
|
||||
fstream_init(&out, F);
|
||||
err = json_export(&out, flags);
|
||||
fstream_done(&out);
|
||||
return err;
|
||||
if (filename) {
|
||||
FILE *F = fopen(filename, "w");
|
||||
if (F) {
|
||||
stream out = { 0 };
|
||||
int err;
|
||||
fstream_init(&out, F);
|
||||
err = json_export(&out, flags);
|
||||
fstream_done(&out);
|
||||
return err;
|
||||
}
|
||||
perror(filename);
|
||||
}
|
||||
perror(filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,16 @@ static int tolua_ship_set_display(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);
|
||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||
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);
|
||||
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)
|
||||
|
|
|
@ -760,17 +760,20 @@ static int tolua_unit_clear_attribs(lua_State *L) {
|
|||
}
|
||||
|
||||
static int tolua_unit_has_attrib(lua_State *L) {
|
||||
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
attrib * a = u->attribs;
|
||||
while (a) {
|
||||
if (strcmp(a->type->name, name) == 0) {
|
||||
break;
|
||||
unit *u = (unit *)tolua_tousertype(L, 1, NULL);
|
||||
const char *name = tolua_tostring(L, 2, NULL);
|
||||
if (u && name) {
|
||||
attrib * a = u->attribs;
|
||||
while (a) {
|
||||
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 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_unit_get_key(lua_State * L)
|
||||
|
|
|
@ -293,17 +293,19 @@ static int tolua_create_curse(lua_State * L)
|
|||
ap = &target->attribs;
|
||||
}
|
||||
if (ap) {
|
||||
const char *cname = tolua_tostring(L, 3, 0);
|
||||
const curse_type *ctype = ct_find(cname);
|
||||
if (ctype) {
|
||||
float vigour = (float)tolua_tonumber(L, 4, 0);
|
||||
int duration = (int)tolua_tonumber(L, 5, 0);
|
||||
float effect = (float)tolua_tonumber(L, 6, 0);
|
||||
int men = (int)tolua_tonumber(L, 7, 0); /* optional */
|
||||
curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men);
|
||||
if (c) {
|
||||
tolua_pushboolean(L, true);
|
||||
return 1;
|
||||
const char *cname = tolua_tostring(L, 3, NULL);
|
||||
if (cname) {
|
||||
const curse_type *ctype = ct_find(cname);
|
||||
if (ctype) {
|
||||
float vigour = (float)tolua_tonumber(L, 4, 0);
|
||||
int duration = (int)tolua_tonumber(L, 5, 0);
|
||||
float effect = (float)tolua_tonumber(L, 6, 0);
|
||||
int men = (int)tolua_tonumber(L, 7, 0); /* optional */
|
||||
curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men);
|
||||
if (c) {
|
||||
tolua_pushboolean(L, true);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue