[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Userdata with methods *and* table access.
- From: Rici Lake <lua@...>
- Date: Thu, 14 Oct 2004 14:52:39 -0500
On 14-Oct-04, at 2:39 PM, Tom Spilman wrote:
I was considering hashes, but doesn't Lua internally keep a hashed
version
of the string? Is there a way to get to that? Or can I count on the
const
char pointer returned from lua_tostring to be the same for the same
strings
(this sounds really hacky)? As it is now my innermost scripted loops
are
doing string compares at the binding layer which makes them less
efficient
than they could be with a good hash.
You can count on the char pointer to be the same provided the string
never gets garbage collected. (i.e., if you keep a reference to the
string somewhere.)
In that case, though, you might as well use the Lua string itself as a
key into a table whose values are, for example, a structure of getter
and setter functions for that key.
(Remember that technically function pointers cannot be cast to void*
but a struct whose members are function pointers can.)
Tom