lua-users home
lua-l archive

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

On Mon, 01 Mar 2010 14:31:21 +0200, Duncan Cross <> wrote:

I'm not against the idea, but I'm a bit confused why it'd be better
than just using an array as the 1 value?

answering to the "why better" part:
- it creates less data
- it is faster
- it considerably simplifies C side usage
- it reduces the size of the userdata when no Lua values are needed

You do have to go through
the extra step of retrieving the array before getting at the values,
but you could always write helper functions/macros to help with that
if it really bothers you.

Such helpers/macros would retrieve array, retrieve element of array, remove
array from the Lua stack. This would happen for every value you try to access.

As stated in the manual:
 " Environments associated with userdata have no meaning for Lua.
 " It is only a convenience feature for programmers
 " to associate a table to a userdata.
This is not a necessary feature. It is to simplify the C code.
You can as well use weak tables keyed by the userdata. So I think the more it
simplifies C side, the better.