[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: upvalues and polymorphism
- From: Dan Marks <dmarks@...>
- Date: Thu, 14 May 1998 23:08:45 -0500 (CDT)
I hate to stray more toward the Python crowd, but
I couldn't help noticing that upvalues seem like
a way to introduce object-oriented like programming
capability into lua. So the question is, why not
then make it so one is able to define functions that
are called differently depending on the tag of the
For example, I could define
myclass = newclass() -- really would be a "newtag"
myclass = newclass(oldclass) -- same as newtag() except all
-- methods would be copied from the old class.
e = myclass(5,4,6) -- would call constructor method for myclass
-- with parameters 5,4,6
then I could define a function like
To be invoked as e.mymethod(5,6,7)
You could even have constructors/destructors like
or function ~myclass
(called during garbage collection)
Perhaps I am missing the point on how upvalues should
be used, but it seems to me that invoking methods by
data type is a very common occurrence in most languages,
and lua is an excellent candidate to have good polymorphism.
Tags and classes are already almost analogous, and maybe
there is a simple way to make this work. I guess
"automatic upvalues" would be like inheritance, and would
facilitate calling subclassed methods, etc.
I don't want to turn lua in to a scripted C++ but lua
would be a very powerful and compact object-oriented
language. I think lua's strength is its simplicity so
if these types of features could be added without language
bloat that would be a great thing.