[Fix] Fixed some Lua stack unbalanced issues.
This commit is contained in:
parent
970dd36c4f
commit
04ed5fe1bc
4
src/ai.c
4
src/ai.c
@ -269,6 +269,7 @@ static void ai_setMemory(void) {
|
|||||||
lua_pushnumber(L, cur_pilot->id);
|
lua_pushnumber(L, cur_pilot->id);
|
||||||
lua_gettable(L, -2);
|
lua_gettable(L, -2);
|
||||||
lua_setglobal(L, "mem");
|
lua_setglobal(L, "mem");
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -338,6 +339,7 @@ int ai_pinit(Pilot* p, char* ai) {
|
|||||||
lua_pushnumber(L, p->id);
|
lua_pushnumber(L, p->id);
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Create the pilot. */
|
/* Create the pilot. */
|
||||||
ai_create(p, (n != 0) ? param : NULL);
|
ai_create(p, (n != 0) ? param : NULL);
|
||||||
@ -359,6 +361,7 @@ void ai_destroy(Pilot* p) {
|
|||||||
lua_pushnumber(L, p->id);
|
lua_pushnumber(L, p->id);
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Clean up tasks. */
|
/* Clean up tasks. */
|
||||||
if(p->task)
|
if(p->task)
|
||||||
@ -508,6 +511,7 @@ void ai_think(Pilot* pilot) {
|
|||||||
ai_run(L, "control"); /* Run control. */
|
ai_run(L, "control"); /* Run control. */
|
||||||
lua_getglobal(L, "control_rate");
|
lua_getglobal(L, "control_rate");
|
||||||
cur_pilot->tcontrol = lua_tonumber(L, -1);
|
cur_pilot->tcontrol = lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
if(cur_pilot->task)
|
if(cur_pilot->task)
|
||||||
/* Pilot has a currently running task. */
|
/* Pilot has a currently running task. */
|
||||||
|
26
src/conf.c
26
src/conf.c
@ -22,14 +22,14 @@
|
|||||||
if(lua_isnumber(L, -1)) { \
|
if(lua_isnumber(L, -1)) { \
|
||||||
i = (int)lua_tonumber(L, -1); \
|
i = (int)lua_tonumber(L, -1); \
|
||||||
} \
|
} \
|
||||||
lua_remove(L, -1); \
|
lua_pop(L, 1); \
|
||||||
|
|
||||||
#define conf_loadFloat(n,f) \
|
#define conf_loadFloat(n,f) \
|
||||||
lua_getglobal(L,n); \
|
lua_getglobal(L,n); \
|
||||||
if(lua_isnumber(L, -1)) { \
|
if(lua_isnumber(L, -1)) { \
|
||||||
f = (double)lua_tonumber(L, -1); \
|
f = (double)lua_tonumber(L, -1); \
|
||||||
} \
|
} \
|
||||||
lua_remove(L,-1);\
|
lua_pop(L,1);\
|
||||||
|
|
||||||
#define conf_loadBool(n,b) \
|
#define conf_loadBool(n,b) \
|
||||||
lua_getglobal(L,n); \
|
lua_getglobal(L,n); \
|
||||||
@ -39,14 +39,14 @@
|
|||||||
} \
|
} \
|
||||||
else if(lua_isboolean(L, -1)) \
|
else if(lua_isboolean(L, -1)) \
|
||||||
b = lua_toboolean(L, -1); \
|
b = lua_toboolean(L, -1); \
|
||||||
lua_remove(L, -1); \
|
lua_pop(L, 1); \
|
||||||
|
|
||||||
#define conf_loadString(n,s) \
|
#define conf_loadString(n,s) \
|
||||||
lua_getglobal(L,n); \
|
lua_getglobal(L,n); \
|
||||||
if(lua_isstring(L, -1)) { \
|
if(lua_isstring(L, -1)) { \
|
||||||
s = strdup((char*)lua_tostring(L, -1)); \
|
s = strdup((char*)lua_tostring(L, -1)); \
|
||||||
} \
|
} \
|
||||||
lua_remove(L, -1); \
|
lua_pop(L, 1); \
|
||||||
|
|
||||||
/* Some crap from main. */
|
/* Some crap from main. */
|
||||||
extern int nosound;
|
extern int nosound;
|
||||||
@ -119,7 +119,7 @@ int conf_loadConfig(const char* file) {
|
|||||||
lua_getglobal(L, "data");
|
lua_getglobal(L, "data");
|
||||||
if(lua_isstring(L, -1))
|
if(lua_isstring(L, -1))
|
||||||
ldata_setPath((char*)lua_tostring(L, -1));
|
ldata_setPath((char*)lua_tostring(L, -1));
|
||||||
lua_remove(L, -1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* OpenGL properties.. */
|
/* OpenGL properties.. */
|
||||||
|
|
||||||
@ -193,8 +193,7 @@ int conf_loadConfig(const char* file) {
|
|||||||
indjoystick = (int)lua_tonumber(L, -1);
|
indjoystick = (int)lua_tonumber(L, -1);
|
||||||
else if(lua_isstring(L, -1))
|
else if(lua_isstring(L, -1))
|
||||||
namjoystick = strdup((char*)lua_tostring(L, -1));
|
namjoystick = strdup((char*)lua_tostring(L, -1));
|
||||||
|
lua_pop(L, 1);
|
||||||
lua_remove(L, -1);
|
|
||||||
|
|
||||||
/* Keybindings. */
|
/* Keybindings. */
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
|
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
|
||||||
@ -213,7 +212,7 @@ int conf_loadConfig(const char* file) {
|
|||||||
WARN("Found keybind with invalid type field!");
|
WARN("Found keybind with invalid type field!");
|
||||||
str = "null";
|
str = "null";
|
||||||
}
|
}
|
||||||
lua_remove(L, -1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Get the key. */
|
/* Get the key. */
|
||||||
lua_pushstring(L, "key");
|
lua_pushstring(L, "key");
|
||||||
@ -229,7 +228,7 @@ int conf_loadConfig(const char* file) {
|
|||||||
WARN("Found keybind with invalid key field!");
|
WARN("Found keybind with invalid key field!");
|
||||||
key = SDLK_UNKNOWN;
|
key = SDLK_UNKNOWN;
|
||||||
}
|
}
|
||||||
lua_remove(L, -1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Is it reversed? Only used for axis. */
|
/* Is it reversed? Only used for axis. */
|
||||||
lua_pushstring(L, "reverse");
|
lua_pushstring(L, "reverse");
|
||||||
@ -240,7 +239,7 @@ int conf_loadConfig(const char* file) {
|
|||||||
reverse = lua_toboolean(L, -1);
|
reverse = lua_toboolean(L, -1);
|
||||||
else
|
else
|
||||||
reverse = 0;
|
reverse = 0;
|
||||||
lua_remove(L, -1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
/* Get the modifier. */
|
/* Get the modifier. */
|
||||||
lua_pushstring(L, "mod");
|
lua_pushstring(L, "mod");
|
||||||
@ -249,7 +248,7 @@ int conf_loadConfig(const char* file) {
|
|||||||
mod = (char*)lua_tostring(L, -1);
|
mod = (char*)lua_tostring(L, -1);
|
||||||
else
|
else
|
||||||
mod = NULL;
|
mod = NULL;
|
||||||
lua_remove(L, -1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
if(str != NULL) {
|
if(str != NULL) {
|
||||||
/* Then the keybind is valid. Get the type. */
|
/* Then the keybind is valid. Get the type. */
|
||||||
@ -285,10 +284,9 @@ int conf_loadConfig(const char* file) {
|
|||||||
} else {
|
} else {
|
||||||
WARN("Malformed keybind for %s in '%s'", keybindNames[i], file);
|
WARN("Malformed keybind for %s in '%s'", keybindNames[i], file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean up after table crap. */
|
|
||||||
lua_remove(L,-1);
|
|
||||||
}
|
}
|
||||||
|
/* Clean up after table crap. */
|
||||||
|
lua_pop(L,1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Failed to load the config file.. */
|
/* Failed to load the config file.. */
|
||||||
|
Loading…
Reference in New Issue
Block a user