lua-users home
lua-l archive

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


On Tue, Sep 10, 2013 at 09:20:02AM +0900, Miles Bader wrote:
> Roberto Ierusalimschy <roberto@inf.puc-rio.br> writes:
> > Thanks for the info. How did you use the registry? Integer
> > keys/lua_rawgeti?  String keys? (This message is for Miles Bader,
> > too.)
> 
> I just used registry string entries at first because that's what the
> various luaL_ functions make easy to use ... luaL_checkudata, etc.
> Many existing libraries do things that way, so it was the natural way
> to go.
> 
> But later when trying to optimize things, I tried upvalues instead,
> and they were significantly faster.
> 
> It never occurred to me to try integer keys (or rawgeti), but as that
> presents additional issues (e.g., one must come up with a system to
> assign small-integer keys without conflicts), and has no particular
> library support (luaL_checkudata etc), it seems like I may as well
> just use upvalues when possible (and upvalues of course have the
> advantage of being a local namespace, with no namespace conflict
> issues).
> 

If you use lightuserdata there's no namespacing conflict, assuming a flat
process address space. Just take the address of a function, or if casting
function pointers to void pointers is distasteful, define a static const
variable and use its address.