[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: void* in Lua_State for Application?
- From: William Ahern <william@...>
- Date: Tue, 10 Sep 2013 21:37:43 -0700
On Tue, Sep 10, 2013 at 11:48:45AM -0700, William Ahern wrote:
> On Tue, Sep 10, 2013 at 11:37:03PM +0900, Miles Bader wrote:
> > Tim Hill <drtimhill@gmail.com> writes:
> > > It's pretty late here, but looking at your code isn't it always trying
> > > to get not-present values? If so, I'm not sure if this can be extended
> > > to Lua behavior when it gets values that are present in the Registry?
> >
> > Indeed, and for the "integer" case, it uses huge integers, not the
> > smallish integers you'd normally use.
> >
> > I've modified the example program (see attachment) to use a more
> > realistic case of a small number of already-present entries , and added
> > tests for string accesses (using both lua_rawget and lua_getfield) too.
> >
> > Here's the results I get (which granted, are likely on a different CPU
> > etc than William used):
>
<snip>
> I dunno... this seems all so very inconsequential. Using lightuserdata seems
> very simple and clean (unlike string keys), and still perfectly performant.
> But, I guess suum cuique pulchrum est.
I take that back. The more I think about it the more using upvalues make
sense.
But when I use lightuserdata, I can keep all the logic highly localized.
Like
lua_pushlightuserdata(L, &key);
lua_gettable(L, LUA_REGISTRYINDEX);
if (lua_isnil(L, -1)) {
// initialize cache, etc
}
// use cache, etc
and most of my functions are defined using simple luaL_Reg arrays, so the
luaopen routine has no knowledge of what's happening. Is there a standard
pattern you use when defining your module's functions, or do you usually
single functions out one-by-one to be defined as a C closure outside the
normal loading code?
- References:
- Re: void* in Lua_State for Application?, Roberto Ierusalimschy
- Re: void* in Lua_State for Application?, Tim Hill
- Re: void* in Lua_State for Application?, Roberto Ierusalimschy
- Re: void* in Lua_State for Application?, Miles Bader
- Re: void* in Lua_State for Application?, William Ahern
- Re: void* in Lua_State for Application?, Miles Bader
- Re: void* in Lua_State for Application?, William Ahern
- Re: void* in Lua_State for Application?, Tim Hill
- Re: void* in Lua_State for Application?, Miles Bader
- Re: void* in Lua_State for Application?, William Ahern