lua-users home
lua-l archive

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


I am thinking about adding integer support to Lua, without giving up
floating point numbers as the basic number type. The obvious way to do this
seems to be to add a new userdata type, and provide suitable tag methods for
all the operations that can act on numbers.

However, I'm a bit worried by the description of lua_pushusertag. This says
that it first searches for a userdata with the same value and tag. The
natural way to store ints is "unboxed", i.e. to cast them to void *, but
this means that each time a C program wants to push an integer, the Lua
runtime will search to see if that integer is already in use.

So everything will work fine, but rather slowly.

I can imagine that implementing other types that take up little storage,
such as complex numbers, could give similar efficiency losses, even if the
value used as a userdata really is a pointer: it might be nice to be able to
tell Lua whether a given tag type should be shared where possible (as at
present) or copied every time (as I imagine would be better for integers).

So in the end I seem to be raising two issues:

1. How best to implement separate integer support? (Or is it just not worth
it?)

2. Is it worth allowing tag types *not* to be shared, but copied each time a
new value is created?

-- 
http://sc3d.org/rrt/
L'art des vers est de transformer en beautés les faiblesses (Aragon)