lua-users home
lua-l archive

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


Edgar,

This sample file is amazing.  Thanks!
Coincidently I had just completed the changes in my vector 
implementation that resulted from some of the responses 
I got on this thread, and your file confirms that I made 
my modifications correctly (albeit your code is alot 
more tricky than mine  :-).

You say I shouldn't mix userdata and lua-tables...  Would you say
tolua implements its classes completely by using tables then?  
That seems to be the case.  I'm assuming, though, that I can 
use a table scheme to create a more generic class (for example a
game object class that has a bunch of vectors (those implemented
using userdata) in it, as well as strings, numbers and such).  
Is this correct?

The reason I ask is that I've finally figured out how tolua does
classes:  it creates a set of tables containing the accessor
functions to the class elements - the ".get" ".set" ".array" 
tables.  Then it uses a special tag method to access them (an
"index" tag?  I think so...). 
I want to reproduce this in my code, with a few modifications, 
using the tolua code as a model - I know it's weird (I could 
just *use* tolua) - it's just my way of learning, and my code 
has way more comments in it  :-)

Cheers,
Falko

"I hear and I forget. I see and I believe. I do and I understand. "
	- Confucius (551-479 BC)


-----Original Message-----
From: Edgar Toernig [mailto:froese@gmx.de]
Sent: Wednesday, June 14, 2000 8:30 PM
To: Multiple recipients of list
Subject: Re: Conceptual problem with gettable tag method [repost]


Falko Poiker wrote:
> One problem I see right away, though with:
> 
> localvec = newVector(10, 10, 10)
> localvec = GlobalVec
> 
> will result in a memory leak, because the vector created by newVector will
> now have nothing pointing to it.  I'm assuming the "gc" tagmethod wouldn't
> take care of this situation.

Of course it does!  That's the only reason for the existence of the "gc"
method: it tells you when an object is no longer used.  newVector mallocs
an object and the "gc" callback frees it.

For what you want: don't touch the set/getglobal methods.  They are not
meant to convert data.  Just decide how you want to have your vectors -
as userdata or lua-tables.  Don't try to mix it, it's just confusing *g*

Attached is an example to show you a possible implementation.  It's a
typical textbook example on how to implement a vector type as userdata
and how to overload the operators.

Ciao, ET.