forked from github/server
refactor: pass function name to callback, calculate it in call_spell instead.
This commit is contained in:
parent
bd9968c266
commit
724a41ac85
|
@ -157,23 +157,12 @@ static void push_param(lua_State * L, char c, spllprm * param)
|
|||
}
|
||||
|
||||
/** callback to use lua for spell functions */
|
||||
static int lua_callspell(castorder * co)
|
||||
static int lua_callspell(castorder * co, const char *fname)
|
||||
{
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
const char *fname = co->sp->sname;
|
||||
unit *caster = co_get_caster(co);
|
||||
region * r = co_get_region(co);
|
||||
int result = -1;
|
||||
const char *hashpos = strchr(fname, '#');
|
||||
char fbuf[64];
|
||||
|
||||
if (hashpos != NULL) {
|
||||
ptrdiff_t len = hashpos - fname;
|
||||
assert(len < (ptrdiff_t) sizeof(fbuf));
|
||||
memcpy(fbuf, fname, len);
|
||||
fbuf[len] = '\0';
|
||||
fname = fbuf;
|
||||
}
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
|||
struct castorder;
|
||||
|
||||
extern struct callbacks {
|
||||
int (*cast_spell)(struct castorder *co);
|
||||
int (*cast_spell)(struct castorder *co, const char *fname);
|
||||
} callbacks;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1399,7 +1399,7 @@ static int parse_spells(xmlDocPtr doc)
|
|||
if (result->nodesetval->nodeNr == 0) {
|
||||
cast = get_function(sp->sname);
|
||||
if (!cast) {
|
||||
log_error("no spell cast function registered for '%s'\n", sp->sname);
|
||||
log_info("no spell cast function registered for '%s'\n", sp->sname);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
15
src/magic.c
15
src/magic.c
|
@ -3006,11 +3006,24 @@ spell *unit_getspell(struct unit *u, const char *name, const struct locale * lan
|
|||
|
||||
int cast_spell(struct castorder *co)
|
||||
{
|
||||
const char *fname = co->sp->sname;
|
||||
const char *hashpos = strchr(fname, '#');
|
||||
char fbuf[64];
|
||||
|
||||
const spell *sp = co->sp;
|
||||
if (sp->cast_fun) {
|
||||
return sp->cast_fun(co);
|
||||
}
|
||||
return callbacks.cast_spell(co);
|
||||
|
||||
if (hashpos != NULL) {
|
||||
ptrdiff_t len = hashpos - fname;
|
||||
assert(len < (ptrdiff_t) sizeof(fbuf));
|
||||
memcpy(fbuf, fname, len);
|
||||
fbuf[len] = '\0';
|
||||
fname = fbuf;
|
||||
}
|
||||
|
||||
return callbacks.cast_spell(co, fname);
|
||||
}
|
||||
|
||||
static critbit_tree cb_spellbooks;
|
||||
|
|
Loading…
Reference in New Issue