[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?
- From: Mark Hamburg <mark@...>
- Date: Sun, 7 Nov 2010 11:31:21 -0800
On Nov 7, 2010, at 10:37 AM, Drake Wilson wrote:
> 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?
Oops. I was writing that from memory since my personal e-mail machine is not the same as my main dev machine.
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 );
lua_pushlightuserdata( L, (void*) udkey );
lua_pushvalue( L, -2 );
lua_settable( L, sourceIndex );
return 1;
}
Mark
- References:
- ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Stefan Behnel
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Duncan Cross
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Stefan Behnel
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Duncan Cross
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Stefan Behnel
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, liam mail
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Leo Razoumov
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Shawn Fox
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Drake Wilson
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Mark Hamburg
- Re: ways to avoid (or speed up) luaL_checkudata() in LuaJIT2?, Drake Wilson