lua-users home
lua-l archive

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


> As a base system, I'd agree because Python comes with classes, but Lua
> allows you to more easily build a more OO system(a prototype-based instead
> of class-based OO language) on top of it than you could in Python.

What is the difference between a prototype based OO system and a class based
one? I thought a prototyped systems were just part of the design phase of OO?!

> >(list and dictionaries accept methods)
> Could you explain this a bit more?

eg. Python:
[1,2,3,4,5,2,4,5].count(2)  count the number of 2's in the list.
{ 5:'apple', 6:'pear', 7:'banana' }.keys()  return the keys in the dictionary as
a list = [5,6,7]
This could be just seen as a style of implementation but I like it.Equally
ir( [ ] ) will give you a lists methods but this would imply that all objects
would inherit from an object containing a dir method if it were [ ].dir() which
is probably very bad?

> I solved this problem for myself by writing a Collection(List) object that
> has
> enumeration features.

This is what I find nice about Python you dont have to go round the houses all
the time to find solutions to programming styles ie. in Lua it seems you're
constantly trying to emulate the behaviour of other languages because a feature
you would like is lacking! Now you can see this as both a pain and great feature
(and it is a good feature but its a pain having to write extra code!). What I
would love is if there were a database of scripts on the Lua site implementing
these features so that users could pick and choose and it would be a great
advert for Lua and a good learning tool. I'm sure most casual Lua users are
unaware of the power Luas features or are not using them, me included! I am
using Lua in a hobbyist capacity whereas I use Python at work!! eg. I've only
really used the tag feature for data abstraction eg. vector/colour types etc. I
find Python more productive for being more fully featured. If we had had the
time on our latest project then I would almost certainly have included Lua but
we hard coded everything for speed due to an extremely tight deadline!!

[ By the way, on a seperate note, and you may know. Is Dylan similar to Lua? I
think that has language extension features. How does Lua compare? ]

> > I agree with this. Can you do inheritance with Lua? Copy an inherited
> > class/table into the inherited class table?
> Yes. In fact, that's all that Python does. Python classes are basicaly just
> dictionaries with a few extra convenience methods. In Lua, you can also
> implement
> inheritance through delegation if you choose. I think this is covered in the
> Lua FAQ.

Sorry couldnt find anything about this in the FAQ. I havent really used
delegation. I thought the benefit of it is that it extends the functionality of
objects at runtime, ie. it kind of emulates inheritance at runtime. This would
be useful in a statically typed language eg. C++, but since Python and Lua
classes are dynamic tables is this very useful? I'd be interested in seeing a
good example of this.

> I've implemented a prototype-based object system in Lua that uses delegation
> for inheritance. I could also put together a Python-like class system. If
> you
> think you'd find these usefull, I could put them in a package and make them
> available.

That would be very interesting. Don't go to too much trouble, if you have work
available then I'd like to see it.

Cheers,
Nick.