lua-users home
lua-l archive

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


On 12/4/05, Chris Marrin <chris@marrin.com> wrote:
> I could also store atoms in
> the registry:
>
>      lua_pushstring(L, "foo");
>      myFoo = luaL_ref(L, LUA_REGISTRYINDEX);
>
> then I could test like this:
>
>      lua_rawgeti(L, LUA_REGISTRYINDEX, myFoo);
>      if (lua_isequal(L, -1, -2)) ...
>
> but this requires looking up the atom in the atom every time.

Well, it does, but since it's a small integer index, that's a
constant-time array lookup. You can do the same thing if it's your
atom table instead of your registry.

The thing is, the string object itself is already the atom. It's a
little trickier to use because Lua holds on to it instead of you, but
it can be used the same way.

Ben