I can "create" the class alright via this:
Code:
local dir = LakeDir(Lake.getcwd())
if not dir then error('Could not open our directory!') end
local ent = dir:next()
if not ent then error('No entries!') end
dir:shut()
dir = nil
ent = nil
With these as the backend
Code:
static int LakeDir_next( lua_State *L ) {
LakeDir_t *d = (LakeDir_t*)lua_touserdata(L,1);
if ( !d ) {
puts("WTF!? We have no object!");
lua_pushnil(L);
return 1;
}
else if ( (d->ent = readdir(d->dir)) != NULL )
return LakeDir__next( L, d );
puts("readdir returned NULL!");
lua_pushnil(L);
return 1;
}
...
static int LakeDir( lua_State *L ) {
const char *path = luaL_checkstring( L, 1 );
LakeDir_t *d = (LakeDir_t*)lua_newuserdata(L, sizeof(LakeDir_t) );
if ( !d ) {
lua_pushnil(L);
return 1;
}
memset( d, 0, sizeof(LakeDir_t) );
luaL_getmetatable( L, LAKEDIR_META );
lua_setmetatable( L, -2 );
d->dir = opendir( path );
if ( !d->dir ) {
lua_pushnil(L);
return 1;
}
lua_newtable(L);
lua_pushstring( L, "next" );
lua_pushcfunction( L, LakeDir_next );
lua_settable( L, -3 );
lua_pushstring( L, "shut" );
lua_pushcfunction( L, LakeDir_gc );
lua_settable( L, -3 );
return 1;
}
Resulting in this output:
Code:
"O:\Common\Lake64\lake64" (in directory: O:\Data\C_Playground\cheat-engine-master\Cheat Engine)
Loading lua file...
WTF!? We have no object!
Failed to run makefile.lua
Fatal Lua Error!
makefile.lua:5: No entries!
stack traceback:
Compilation failed.
Since I still don't quite understand how to use the Lua "class" related c functions I need some help understanding how I got to the least expected result of no object at all