forked from github/server
add a callbacks module.
make last-chance spell function in lua for spells with none.
This commit is contained in:
parent
74673f172f
commit
edd3b36a9f
|
@ -92,6 +92,20 @@ TOLUA_PKG(locale);
|
|||
TOLUA_PKG(log);
|
||||
TOLUA_PKG(game);
|
||||
|
||||
int tolua_toid(lua_State * L, int idx, int def)
|
||||
{
|
||||
int no = 0;
|
||||
int type = lua_type(L, idx);
|
||||
if (type == LUA_TNUMBER) {
|
||||
no = (int)tolua_tonumber(L, idx, def);
|
||||
}
|
||||
else {
|
||||
const char *str = tolua_tostring(L, idx, NULL);
|
||||
no = str ? atoi36(str) : def;
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
int log_lua_error(lua_State * L)
|
||||
{
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
|
|
@ -18,6 +18,7 @@ extern "C" {
|
|||
struct _dictionary_;
|
||||
struct selist;
|
||||
|
||||
int tolua_toid(struct lua_State * L, int idx, int def);
|
||||
int tolua_sqlite_open(struct lua_State *L);
|
||||
int tolua_bindings_open(struct lua_State *L, const struct _dictionary_ *d);
|
||||
int tolua_itemlist_next(struct lua_State *L);
|
||||
|
|
|
@ -455,20 +455,6 @@ use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord)
|
|||
return result;
|
||||
}
|
||||
|
||||
int tolua_toid(lua_State * L, int idx, int def)
|
||||
{
|
||||
int no = 0;
|
||||
int type = lua_type(L, idx);
|
||||
if (type == LUA_TNUMBER) {
|
||||
no = (int)tolua_tonumber(L, idx, def);
|
||||
}
|
||||
else {
|
||||
const char *str = tolua_tostring(L, idx, NULL);
|
||||
no = str ? atoi36(str) : def;
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
void register_tolua_helpers(void)
|
||||
{
|
||||
at_register(&at_direction);
|
||||
|
|
|
@ -16,7 +16,6 @@ extern "C" {
|
|||
|
||||
struct lua_State;
|
||||
void register_tolua_helpers(void);
|
||||
int tolua_toid(struct lua_State *L, int idx, int def);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ alliance.test.c
|
|||
ally.test.c
|
||||
build.test.c
|
||||
building.test.c
|
||||
# callbacks.test.c
|
||||
command.test.c
|
||||
config.test.c
|
||||
# connection.test.c
|
||||
|
@ -38,6 +39,7 @@ alliance.c
|
|||
ally.c
|
||||
build.c
|
||||
building.c
|
||||
callbacks.c
|
||||
command.c
|
||||
config.c
|
||||
connection.c
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
#include <platform.h>
|
||||
#include "callbacks.h"
|
||||
|
||||
struct callbacks callbacks;
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#ifndef H_KRNL_CALLBACKS_H
|
||||
#define H_KRNL_CALLBACKS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct castorder;
|
||||
|
||||
extern struct callbacks {
|
||||
int (*cast_spell)(struct castorder *co);
|
||||
} callbacks;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* H_KRNL_CALLBACKS_H */
|
|
@ -27,6 +27,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <kernel/ally.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/callbacks.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
|
@ -3006,8 +3007,11 @@ spell *unit_getspell(struct unit *u, const char *name, const struct locale * lan
|
|||
int cast_spell(struct castorder *co)
|
||||
{
|
||||
const spell *sp = co->sp;
|
||||
if (sp->cast_fun) {
|
||||
return sp->cast_fun(co);
|
||||
}
|
||||
return callbacks.cast_spell(co);
|
||||
}
|
||||
|
||||
static critbit_tree cb_spellbooks;
|
||||
|
||||
|
|
Loading…
Reference in New Issue