lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Quoth Mark Hamburg <mark@grubmah.com>, on 2010-11-07 10:15:21 -0800:
> Per the discussions about strings for looking up values, one of my standard Lua utility routines is roughly:
> 
> 	int pushTableForKey( lua_State* L, int sourceIndex, const void* udkey ) {
> 		// Normalize sourceIndex to avoid problems with relative addresses after the push.
> 		lua_pushlightuserdata( L, (void*) udkey );
> 		lua_gettable( L, sourceIndex );
> 		if( !lua_isnil( L, -1 ) ) return 0;
> 		lua_pop( L, 1 );
> 		lua_newtable( L );
> 		return 1;
> 	}

Just out of curiosity, do you ever store the new table back into
<table at sourceIndex>[<lightuserdata udkey>]?  Was that part omitted
for clarity?

   ---> Drake Wilson