[Change] Balanced the Lua conf stack.
This commit is contained in:
parent
73b034d1ec
commit
6575eace2b
25
src/conf.c
25
src/conf.c
@ -19,30 +19,30 @@
|
||||
lua_getglobal(L,n); \
|
||||
if(lua_isnumber(L, -1)) { \
|
||||
i = (int)lua_tonumber(L, -1); \
|
||||
} \
|
||||
lua_remove(L, -1); \
|
||||
}
|
||||
|
||||
#define conf_loadFloat(n,f) \
|
||||
lua_getglobal(L,n); \
|
||||
if(lua_isnumber(L, -1)) { \
|
||||
f = (double)lua_tonumber(L, -1); \
|
||||
} \
|
||||
lua_remove(L,-1);\
|
||||
}
|
||||
|
||||
#define conf_loadBool(n,b) \
|
||||
lua_getglobal(L,n); \
|
||||
if(lua_isnumber(L, -1)) \
|
||||
if((int)lua_tonumber(L, -1) == 1) { \
|
||||
b = 1; \
|
||||
lua_remove(L, -1); \
|
||||
} \
|
||||
lua_remove(L, -1); \
|
||||
|
||||
#define conf_loadString(n,s) \
|
||||
lua_getglobal(L,n); \
|
||||
if(lua_isstring(L, -1)) { \
|
||||
s = strdup((char*)lua_tostring(L, -1)); \
|
||||
} \
|
||||
lua_remove(L, -1); \
|
||||
}
|
||||
|
||||
/* Some crap from main. */
|
||||
extern int nosound;
|
||||
@ -164,25 +164,30 @@ int conf_loadConfig(const char* file) {
|
||||
lua_gettable(L, -2);
|
||||
if(lua_isstring(L, -1))
|
||||
str = (char*)lua_tostring(L, -1);
|
||||
lua_remove(L, -1);
|
||||
|
||||
/* Get the key. */
|
||||
lua_pushstring(L, "key");
|
||||
lua_gettable(L, -3);
|
||||
lua_gettable(L, -2);
|
||||
if(lua_isnumber(L, -1))
|
||||
key = (int)lua_tonumber(L, -1);
|
||||
lua_remove(L, -1);
|
||||
|
||||
/* Is it reversed? Only used for axis. */
|
||||
lua_pushstring(L, "reverse");
|
||||
lua_gettable(L, -4);
|
||||
lua_gettable(L, -2);
|
||||
if(lua_isnumber(L, -1))
|
||||
reverse = 1;
|
||||
lua_remove(L, -1);
|
||||
|
||||
lua_pushstring(L, "mod");
|
||||
lua_gettable(L, -4);
|
||||
lua_gettable(L, -2);
|
||||
if(lua_isstring(L, -1))
|
||||
mod = (char*)lua_tostring(L, -1);
|
||||
lua_remove(L, -1);
|
||||
|
||||
if(key != -1 && str != NULL) {
|
||||
|
||||
if((key != -1) && (str != NULL)) {
|
||||
/* Then the keybind is valid. Get the type. */
|
||||
if(strcmp(str, "null")==0) type = KEYBIND_NULL;
|
||||
else if(strcmp(str, "keyboard")==0) type = KEYBIND_KEYBOARD;
|
||||
@ -216,10 +221,8 @@ int conf_loadConfig(const char* file) {
|
||||
|
||||
/* Clean up after table crap. */
|
||||
lua_remove(L,-1);
|
||||
lua_remove(L,-1);
|
||||
lua_remove(L,-1);
|
||||
lua_remove(L,-1);
|
||||
}
|
||||
lua_remove(L, -1);
|
||||
}
|
||||
} else {
|
||||
/* Failed to load the config file.. */
|
||||
|
Loading…
Reference in New Issue
Block a user