[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: ANN: LuaState (A C++ Lua Wrapper and enhanced Lua 4.1 Distribution)
- From: David Jeske <jeske@...>
- Date: Thu, 8 Nov 2001 09:21:53 -0800
Does this "unified methods" thing perform better than simply using
proto-style inheritence with a lua index tag method?
On Wed, Nov 07, 2001 at 10:33:40PM -0700, Joshua Jensen wrote:
> Unified Methods
> ===============
> Unified methods are based heavily on Edgar Toernig's Sol implementation
> of unified methods (note: some text is taken verbatim from the Sol
> documentation).
>
> Every object in Lua has an attached method table. For C++ users, the
> method table is most similar to a v-table. For Lua's simple types (nil,
> number, string, ustring, and function), there is one method table for
> all objects of the given type. Table and userdata objects have the
> ability to have method tables on a per object basis.
>
> Unlike Edgar's Sol implementation, the colon operator for Lua's
> automatic self functions is not replaced with an alternate
> implementation. This is done in an effort to keep LuaState
> functionality identical to the original Lua distribution. Instead, two
> new function operators are introduced. The pointer symbol (->) behaves
> like the colon operator, but it looks up the function to call in the
> method table. The second operator is the double colon operator, which
> behaves like the regular dot operator (no self is passed in).
>
> The biggest advantage of unified methods is memory savings. When
> dealing with many Lua objects (say, tables) of the same type, the
> functions don't have to be duplicated for each and every one.
> Significant amounts of memory may be saved by the use of the shared
> method table.
--
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net