I can compile, I can use LakeDir.new/open but I can't use LakeDir.next because it shows up as nil, any ideas?
Code:
static const luaL_Reg LakeDirReg[] = {
	{ "__gc", LakeDir_gc },
	{ "__tostring", LakeDir_tostring },
	{ "new", LakeDir },
	{ "open", LakeDirOpen },
	{ "shut", LakeDir_gc },
	{ "next", LakeDirNext },
	{ NULL, NULL }
};
int LakeDir_register( lua_State *L ) {
    return LakeRegisterClass( L, "LakeDir", LakeDirReg );
}
...
int LakeRegisterClass( lua_State *L, char *name, const luaL_Reg *methods ) {
	char text[BUFSIZ] = {0};
	int i = 0;
	if ( !L || !name || !methods ) return -1;
	// get global environment table from registry
	lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
	// local tmp = {}
	lua_newtable(L);
	// for i,v in pairs(methods) do
	for ( ; methods[i].name[i] && methods[i].func; ++i ) {
		// tmp[v.name] = v.func
		lua_pushstring( L, methods[i].name );
		lua_pushcfunction( L, methods[i].func );
		lua_settable( L, -3 );
	}
	// name = tmp
	lua_setglobal( L, name );
	// name.__index = name
	snprintf( text, BUFSIZ, "%s.__index = %s", name, name );
	//puts(text);
	if ( luaL_dostring( L, text ) != 0 )
		return 1;
	return 0;
}
Btw I've already looked for any instance of LakeDir or LakeDir.next being reset upto the point I try to use it but nothing revealed itself in the find dialog.