[Add] More faction validity checking.
This commit is contained in:
parent
a9780b6c4d
commit
871a57ecd7
@ -58,6 +58,10 @@ int faction_get(const char* name) {
|
|||||||
|
|
||||||
/* Return the faction's name. */
|
/* Return the faction's name. */
|
||||||
char* faction_name(int f) {
|
char* faction_name(int f) {
|
||||||
|
if((f < 0) || (f >= faction_nstack)) {
|
||||||
|
WARN("Faction id '%d' is invalid.", f);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return faction_stack[f].name;
|
return faction_stack[f].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,10 +347,12 @@ static int systemL_faction(lua_State* L) {
|
|||||||
/* Return result in table. */
|
/* Return result in table. */
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
for(i = 0; i < sys->s->nplanets; i++) {
|
for(i = 0; i < sys->s->nplanets; i++) {
|
||||||
|
if(sys->s->planets[i].faction > 0) { /* Faction must be valid. */
|
||||||
lua_pushboolean(L, 1); /* Value. */
|
lua_pushboolean(L, 1); /* Value. */
|
||||||
lua_setfield(L, -2, faction_name(sys->s->planets[i].faction)); /* Key. */
|
lua_setfield(L, -2, faction_name(sys->s->planets[i].faction)); /* Key. */
|
||||||
/* Allows syntax foo = space.faction("foo"); if foo["bar"] then ... end */
|
/* Allows syntax foo = space.faction("foo"); if foo["bar"] then ... end */
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user