[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: String equality?
- From: Ben Sunshine-Hill <sneftel@...>
- Date: Sun, 4 Dec 2005 09:09:41 -0800
On 12/4/05, Chris Marrin <email@example.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.