[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Feature suggestion: "Up values for userdata"
- From: Tobias Käs <tobias.kaes@...>
- Date: Wed, 3 Sep 2003 21:50:11 +0200
----- Original Message -----
From: "Mark Hamburg" <mhamburg@adobe.com>
> Alternative implementations:
>
> * Use metatables. I'm doing this now, but it makes doing type-checking
> harder since every userdata with associated values has to have a distinct
> metatable.
>
Type checking does not really get harder. Just keep an entry for a type
identifier in the metatable. The overhead you get is 2 push (the key, which
is fixed, so you can duplicate it once - might be faster), 2 table access
operations (to get both types) and one comparison (can be done by through
the API). In my opinion a price worth to pay for the additional
functionality :-)
I know there is some more overhead in creating the userdata with this method
but I think you won't do that _very_ often anyways, if you attach objects to
the userdata.
Otherwise metatables do exactly what you want.
If you still insist on your system, I would suggest to attach a 2nd table
besides the metatable to the userdata, this would fit much more into the way
of Lua than the "virtual array" you suggest ;-)