more Lua functions using the wrong stack index.

This commit is contained in:
Enno Rehling 2012-05-29 20:13:54 -07:00
parent cb0e406733
commit 5e26d246a2
1 changed files with 19 additions and 19 deletions

View File

@ -37,8 +37,7 @@ without prior permission by the authors of Eressea.
#include <assert.h> #include <assert.h>
static int static int
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *ord)
struct order *ord)
{ {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *) global.vm_state;
char fname[64]; char fname[64];
@ -46,11 +45,12 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n,
const char *iname = itype->rtype->_name[0]; const char *iname = itype->rtype->_name[0];
assert(s != NULL); assert(s != NULL);
strcat(strcpy(fname, iname), "_give"); strlcpy(fname, iname, sizeof(fname));
strlcat(fname, "_give", sizeof(fname));
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, s, TOLUA_CAST "unit"); tolua_pushusertype(L, s, TOLUA_CAST "unit");
tolua_pushusertype(L, d, TOLUA_CAST "unit"); tolua_pushusertype(L, d, TOLUA_CAST "unit");
tolua_pushstring(L, iname); tolua_pushstring(L, iname);
@ -83,7 +83,7 @@ static int limit_resource(const region * r, const resource_type * rtype)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
@ -113,7 +113,7 @@ produce_resource(region * r, const resource_type * rtype, int norders)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
tolua_pushnumber(L, (lua_Number) norders); tolua_pushnumber(L, (lua_Number) norders);
@ -142,7 +142,7 @@ static int lc_age(struct attrib *a)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
if (fparam) { if (fparam) {
tolua_pushstring(L, fparam); tolua_pushstring(L, fparam);
@ -256,7 +256,7 @@ static int lua_initfamiliar(unit * u)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
@ -292,7 +292,7 @@ lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) delta); tolua_pushnumber(L, (lua_Number) delta);
@ -323,7 +323,7 @@ static int lua_getresource(unit * u, const struct resource_type *rtype)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
@ -353,7 +353,7 @@ static boolean lua_canuse_item(const unit * u, const struct item_type *itype)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushstring(L, itype->rtype->_name[0]); tolua_pushstring(L, itype->rtype->_name[0]);
@ -383,7 +383,7 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
tolua_pushstring(L, rc ? rc->_name[0] : 0); tolua_pushstring(L, rc ? rc->_name[0] : 0);
@ -415,7 +415,7 @@ static void lua_agebuilding(building * b)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
if (lua_pcall(L, 1, 0, 0) != 0) { if (lua_pcall(L, 1, 0, 0) != 0) {
@ -437,7 +437,7 @@ static int lua_building_protection(building * b, unit * u)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
@ -464,7 +464,7 @@ static double lua_building_taxes(building * b, int level)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
tolua_pushnumber(L, level); tolua_pushnumber(L, level);
@ -491,7 +491,7 @@ static int lua_maintenance(const unit * u)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
@ -521,7 +521,7 @@ static int lua_equipmentcallback(const struct equipment *eq, unit * u)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
@ -553,7 +553,7 @@ lua_useitem(struct unit *u, const struct item_type *itype, int amount,
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) amount); tolua_pushnumber(L, (lua_Number) amount);
@ -584,7 +584,7 @@ static int lua_recruit(struct unit *u, const struct archetype *arch, int amount)
lua_pushstring(L, fname); lua_pushstring(L, fname);
lua_rawget(L, LUA_GLOBALSINDEX); lua_rawget(L, LUA_GLOBALSINDEX);
if (lua_isfunction(L, 1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) amount); tolua_pushnumber(L, (lua_Number) amount);