forked from github/server
solve helpers.c without bsdstring
This commit is contained in:
parent
5576ef37b6
commit
686bbdbf69
1 changed files with 72 additions and 76 deletions
|
@ -17,7 +17,6 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/gamedata.h>
|
||||
|
@ -52,13 +51,12 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o
|
|||
{
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
int result = -1, len;
|
||||
const char *iname = itype->rtype->_name;
|
||||
|
||||
assert(s != NULL);
|
||||
strlcpy(fname, iname, sizeof(fname));
|
||||
strlcat(fname, "_give", sizeof(fname));
|
||||
|
||||
len = snprintf(fname, sizeof(fname), "%s_give", iname);
|
||||
if (len > 0 && (size_t)len < sizeof(fname)) {
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, s, TOLUA_CAST "unit");
|
||||
|
@ -80,19 +78,18 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *o
|
|||
log_error("unit %s trying to call '%s' : not a function.\n", unitname(s), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int limit_resource_lua(const region * r, const resource_type * rtype)
|
||||
{
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
int result = -1, len;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_limit", sizeof(fname));
|
||||
|
||||
len = snprintf(fname, sizeof(fname), "%s_limit", rtype->_name);
|
||||
if (len > 0 && (size_t)len < sizeof(fname)) {
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
|
@ -111,7 +108,7 @@ static int limit_resource_lua(const region * r, const resource_type * rtype)
|
|||
log_error("limit(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -120,10 +117,10 @@ produce_resource_lua(region * r, const resource_type * rtype, int norders)
|
|||
{
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
int len;
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_produce", sizeof(fname));
|
||||
|
||||
len = snprintf(fname, sizeof(fname), "%s_produce", rtype->_name);
|
||||
if (len > 0 && (size_t)len < sizeof(fname)) {
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
|
@ -139,6 +136,7 @@ produce_resource_lua(region * r, const resource_type * rtype, int norders)
|
|||
log_error("produce(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void push_param(lua_State * L, char c, spllprm * param)
|
||||
|
@ -216,12 +214,11 @@ static int
|
|||
lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
|
||||
{
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
int result = -1;
|
||||
int len, result = -1;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_changeresource", sizeof(fname));
|
||||
|
||||
len = snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name);
|
||||
if (len > 0 && (size_t)len < sizeof(fname)) {
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
|
@ -241,7 +238,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
|
|||
log_error("change(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -250,13 +247,12 @@ static int
|
|||
use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord)
|
||||
{
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
int result = 0;
|
||||
int len, result = 0;
|
||||
char fname[64];
|
||||
int (*callout)(unit *, const item_type *, int, struct order *);
|
||||
|
||||
strlcpy(fname, "use_", sizeof(fname));
|
||||
strlcat(fname, itype->rtype->_name, sizeof(fname));
|
||||
|
||||
len = snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name);
|
||||
if (len > 0 && (size_t)len < sizeof(fname)) {
|
||||
callout = (int(*)(unit *, const item_type *, int, struct order *))get_function(fname);
|
||||
if (callout) {
|
||||
return callout(u, itype, amount, ord);
|
||||
|
@ -286,7 +282,7 @@ use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord)
|
|||
log_error("no such callout: %s", fname);
|
||||
}
|
||||
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue