From bda395d374d009613df666d4d0794567c21a3c26 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 22 Apr 2017 18:57:57 +0200 Subject: [PATCH 1/7] shell wants ==, not = for string compares? --- s/build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/s/build b/s/build index 818cb0268..b3db6d11b 100755 --- a/s/build +++ b/s/build @@ -33,8 +33,9 @@ fi echo "build eressea" cd $ROOT/$BUILD BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') -if [ "$BRANCH" = "master" ] ; then +if [ "$BRANCH"=="master" ] ; then VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') +echo "master $VERSION" cmake -DERESSEA_VERSION="$VERSION" .. else REV=$(git rev-parse --short HEAD) From 1eb189cf47cc1e327a7c82596264d046cd7d6396 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 22 Apr 2017 18:57:57 +0200 Subject: [PATCH 2/7] shell wants spaces around = for string compares? --- s/build | 1 + 1 file changed, 1 insertion(+) diff --git a/s/build b/s/build index 818cb0268..e47ecf903 100755 --- a/s/build +++ b/s/build @@ -35,6 +35,7 @@ cd $ROOT/$BUILD BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') if [ "$BRANCH" = "master" ] ; then VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') +echo "$BRANCH $VERSION" cmake -DERESSEA_VERSION="$VERSION" .. else REV=$(git rev-parse --short HEAD) From 7f9c85384a68be8954d9357d66d6b4b3cf239e80 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 22 Apr 2017 19:06:38 +0200 Subject: [PATCH 3/7] build script madness, again --- s/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/build b/s/build index f019c98d5..e47ecf903 100755 --- a/s/build +++ b/s/build @@ -33,7 +33,7 @@ fi echo "build eressea" cd $ROOT/$BUILD BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') -if [ "$BRANCH"=="master" ] ; then +if [ "$BRANCH" = "master" ] ; then VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') echo "$BRANCH $VERSION" cmake -DERESSEA_VERSION="$VERSION" .. From 1cd8a5323248abd27f219198f68b70a895ce9b04 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 22 Apr 2017 19:07:47 +0200 Subject: [PATCH 4/7] whitespace framing equals --- s/build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s/build b/s/build index f019c98d5..e47ecf903 100755 --- a/s/build +++ b/s/build @@ -33,7 +33,7 @@ fi echo "build eressea" cd $ROOT/$BUILD BRANCH=$(git status -s -b | head -1 | cut -d\ -f 2 | sed 's/\..*//') -if [ "$BRANCH"=="master" ] ; then +if [ "$BRANCH" = "master" ] ; then VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') echo "$BRANCH $VERSION" cmake -DERESSEA_VERSION="$VERSION" .. From 45f8f73ede7ae90183d0757a78487ff59fd1236c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 23 Apr 2017 16:13:28 +0200 Subject: [PATCH 5/7] broaden valgrind suppression for strtold --- share/debian-7_8.supp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/share/debian-7_8.supp b/share/debian-7_8.supp index 99eefafa4..f6fabe6e7 100644 --- a/share/debian-7_8.supp +++ b/share/debian-7_8.supp @@ -50,11 +50,4 @@ obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 fun:lua_isnumber - fun:class_index_event - obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 - obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 - obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 - obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 - obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 - obj:/usr/lib/x86_64-linux-gnu/liblua5.2.so.0.0.0 } From 53dc475d9d55d73526f23a78eb8390dfab46b1c9 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 May 2017 22:41:00 +0200 Subject: [PATCH 6/7] remove unused callback functions. --- src/helpers.c | 165 -------------------------------------------------- 1 file changed, 165 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index ab59ea60c..e4397bd46 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -211,43 +211,6 @@ static int lua_callspell(castorder * co, const char *fname) return result; } -/** callback to initialize a familiar from lua. */ -static int lua_initfamiliar(unit * u) -{ - lua_State *L = (lua_State *)global.vm_state; - char fname[64]; - int result = -1; - - strlcpy(fname, "initfamiliar_", sizeof(fname)); - strlcat(fname, u_race(u)->_name, sizeof(fname)); - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, u, TOLUA_CAST "unit"); - - if (lua_pcall(L, 1, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("familiar(%s) calling '%s': %s.\n", unitname(u), fname, error); - lua_pop(L, 1); - } - else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); - } - } - else { - log_warning("familiar(%s) calling '%s': not a function.\n", unitname(u), fname); - lua_pop(L, 1); - } - - create_mage(u, M_GRAY); - - strlcpy(fname, u_race(u)->_name, sizeof(fname)); - strlcat(fname, "_familiar", sizeof(fname)); - equip_unit(u, get_equipment(fname)); - return result; -} - static int lua_changeresource(unit * u, const struct resource_type *rtype, int delta) { @@ -281,127 +244,6 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta) return result; } -static int lua_getresource(unit * u, const struct resource_type *rtype) -{ - lua_State *L = (lua_State *)global.vm_state; - int result = -1; - char fname[64]; - - strlcpy(fname, rtype->_name, sizeof(fname)); - strlcat(fname, "_getresource", sizeof(fname)); - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, u, TOLUA_CAST "unit"); - - if (lua_pcall(L, 1, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error); - lua_pop(L, 1); - } - else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); - } - } - else { - log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname); - lua_pop(L, 1); - } - - return result; -} - -static int -lua_wage(const region * r, const faction * f, const race * rc, int in_turn) -{ - lua_State *L = (lua_State *)global.vm_state; - const char *fname = "wage"; - int result = -1; - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); - tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); - tolua_pushstring(L, rc ? rc->_name : 0); - lua_pushinteger(L, in_turn); - - if (lua_pcall(L, 3, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("wage(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error); - lua_pop(L, 1); - } - else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); - } - } - else { - log_error("wage(%s) calling '%s': not a function.\n", regionname(r, NULL), fname); - lua_pop(L, 1); - } - - return result; -} - -static int lua_maintenance(const unit * u) -{ - lua_State *L = (lua_State *)global.vm_state; - const char *fname = "maintenance"; - int result = -1; - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); - - if (lua_pcall(L, 1, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("maintenance(%s) calling '%s': %s.\n", unitname(u), fname, error); - lua_pop(L, 1); - } - else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); - } - } - else { - log_error("maintenance(%s) calling '%s': not a function.\n", unitname(u), fname); - lua_pop(L, 1); - } - - return result; -} - -static int lua_equipmentcallback(const struct equipment *eq, unit * u) -{ - lua_State *L = (lua_State *)global.vm_state; - char fname[64]; - int result = -1; - - strlcpy(fname, "equip_", sizeof(fname)); - strlcat(fname, eq->name, sizeof(fname)); - - lua_getglobal(L, fname); - if (lua_isfunction(L, -1)) { - tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); - - if (lua_pcall(L, 1, 1, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("equip(%s) calling '%s': %s.\n", unitname(u), fname, error); - lua_pop(L, 1); - } - else { - result = (int)lua_tonumber(L, -1); - lua_pop(L, 1); - } - } - else { - log_error("equip(%s) calling '%s': not a function.\n", unitname(u), fname); - lua_pop(L, 1); - } - return result; -} - /** callback for an item-use function written in lua. */ static int use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord) @@ -447,7 +289,6 @@ use_item_lua(unit *u, const item_type *itype, int amount, struct order *ord) return result; } - /* compat code for old data files */ static int caldera_read(trigger *t, struct gamedata *data) { @@ -470,13 +311,7 @@ void register_tolua_helpers(void) callbacks.cast_spell = lua_callspell; - register_function((pf_generic)lua_initfamiliar, "lua_initfamiliar"); - register_function((pf_generic)lua_getresource, "lua_getresource"); register_function((pf_generic)lua_changeresource, "lua_changeresource"); - register_function((pf_generic)lua_equipmentcallback, "lua_equip"); - - register_function((pf_generic)lua_wage, "lua_wage"); - register_function((pf_generic)lua_maintenance, "lua_maintenance"); item_use_fun = use_item_lua; res_produce_fun = produce_resource_lua; From d9fca4dcb3c3b03822e3059ff35d71446874742b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 8 May 2017 22:44:18 +0200 Subject: [PATCH 7/7] refactor stray fptr variable into callbacks module. --- src/helpers.c | 7 +++---- src/kernel/callbacks.h | 6 ++++++ src/kernel/resources.c | 2 -- src/kernel/resources.h | 2 -- src/laws.c | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index e4397bd46..25079c549 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -310,11 +310,10 @@ void register_tolua_helpers(void) at_register(&at_building_action); callbacks.cast_spell = lua_callspell; - - register_function((pf_generic)lua_changeresource, "lua_changeresource"); - - item_use_fun = use_item_lua; + callbacks.use_item = use_item_lua; res_produce_fun = produce_resource_lua; res_limit_fun = limit_resource_lua; + + register_function((pf_generic)lua_changeresource, "lua_changeresource"); register_item_give(lua_giveitem, "lua_giveitem"); } diff --git a/src/kernel/callbacks.h b/src/kernel/callbacks.h index f42d25d3f..0aa71daca 100644 --- a/src/kernel/callbacks.h +++ b/src/kernel/callbacks.h @@ -24,9 +24,15 @@ extern "C" { #endif struct castorder; + struct order; + struct unit; + struct item_type; struct callback_struct { int (*cast_spell)(struct castorder *co, const char *fname); + int (*use_item)(struct unit *u, const struct item_type *itype, + int amount, struct order *ord); + }; extern struct callback_struct callbacks; diff --git a/src/kernel/resources.c b/src/kernel/resources.c index 8d6e1c2ac..fe18ae640 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -213,8 +213,6 @@ struct rawmaterial_type *rmt_create(struct resource_type *rtype) return rmtype; } -int(*item_use_fun)(struct unit *u, const struct item_type *itype, int amount, - struct order *ord); int(*res_limit_fun)(const struct region *, const struct resource_type *); void(*res_produce_fun)(struct region *, const struct resource_type *, int); diff --git a/src/kernel/resources.h b/src/kernel/resources.h index 1868dffc0..e7a232d27 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -73,8 +73,6 @@ extern "C" { extern int(*res_limit_fun)(const struct region *, const struct resource_type *); extern void(*res_produce_fun)(struct region *, const struct resource_type *, int); - extern int (*item_use_fun)(struct unit *, const struct item_type *, int amount, - struct order *ord); int limit_resource(const struct region *r, const struct resource_type *rtype); void produce_resource(struct region *r, const struct resource_type *rtype, int amount); diff --git a/src/laws.c b/src/laws.c index 250738f76..5bb87f4fb 100644 --- a/src/laws.c +++ b/src/laws.c @@ -45,6 +45,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* kernel includes */ #include #include +#include #include #include #include @@ -3218,7 +3219,7 @@ static int use_item(unit * u, const item_type * itype, int amount, struct order } if (itype->flags & ITF_CANUSE) { - int result = item_use_fun(u, itype, amount, ord); + int result = callbacks.use_item(u, itype, amount, ord); if (result > 0) { use_pooled(u, itype->rtype, GET_DEFAULT, result); }