Thread: Bizare C/Lua issue

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735

    Bizare C/Lua issue

    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.

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735
    Found it!
    ...
    After printing to console the name and pointer for each function before they are added :|
    The problem was I mistakenly added [i] on the end of the name check

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. DNS issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-02-2008, 10:15 AM
  3. What is the issue?
    By al_engler in forum C Programming
    Replies: 2
    Last Post: 12-19-2006, 01:54 PM
  4. dll issue
    By yahn in forum C++ Programming
    Replies: 1
    Last Post: 01-20-2006, 10:40 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM

Tags for this Thread