Has anyone ever encountered bad stack corruption in Lua, any version?
I am reaching the end of my rope as I can not find where or how the stack is getting corrupted.
Of course with the style of messages below I'm just assuming it's stack corruption. Any help would be appreciated.
Error Message:
DB.lua line 33:
kernel.dir function:
This is not a request for help regarding the above function, but just a general query of horrible experiences with Lua and how the problems were fixed/worked around.
I am reaching the end of my rope as I can not find where or how the stack is getting corrupted.
Of course with the style of messages below I'm just assuming it's stack corruption. Any help would be appreciated.
Error Message:
Sep 28, 19:32:04|BUG|Segmentation Violation
Sep 28, 19:32:04|BUG|Error 2 loading Lua startup file ../lib/Main.lua:
../lib/DB.lua:33: bad argument #2 to 'dir' (number expected, got string)
stack traceback:
[C]: in function 'dir'
../lib/DB.lua:33: in function 'loadDirectory'
../lib/Main.lua:49: in main chunk
DB.lua line 33:
local tbl = { kernel.dir(dir) };
kernel.dir function:
static int EXL_get_directory(lua_State *L) {
int nArgs = 0;
DIR *d;
struct dirent *entry = NULL;
const char *buf = luaL_checkstring(L, 1);
char dir_str[SHORT_STR_LENGTH * 2]; //256
nArgs = sprintf(dir_str, "%s", buf);
if( nArgs <= 0 ) {
return luaL_error(L, "Bad argument #1 to kernel.dir, string expected.");
}
d = opendir(dir_str);
if( d == NULL ) {
return luaL_error(L, "Cannot open directory %s for access.", dir_str);
}
nArgs = 0;
while( (entry = readdir(d)) != NULL ) {
if( entry->d_name == NULL ) {
break;
} else if( entry->d_name[0] == '.' ) {
continue;
} else {
lua_pushstring(L, entry->d_name);
nArgs++;
}
}
closedir(d);
return nArgs;
}
This is not a request for help regarding the above function, but just a general query of horrible experiences with Lua and how the problems were fixed/worked around.