lua-users home
lua-l archive

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



Could we start an 'inner circle' discussion & workgroup on this?

I don't know the 'answer' but I do know the need, and I'd be able to test out approaches in LuaX environment. Personally, I wouldn't start by demanding language (core) changes, rather just coming up with a working add-on, and if _then_ we find there's a crucial syntax/performance bottleneck, let's bring it up.

My requirements for this thing would be, that it's totally generic and loadable. Like:

	local obj= require "obj_support"	-- building blocks for other modules
	...
	local myclass_new= function(...)
		local o= obj.new( ... )
		...

The end user wouldn't (need to) see 'obj_support' but any OO modules would get smaller, by letting it do the administrative/oo specific work for them.

Am I in?

-ak



16.1.2005 kello 08:04, André de Leiradella kirjoitti:

 lua-bounces@bazar2.conectiva.com.br wrote:
André de Leiradella wrote:
+ Classes and objects

It's #1 to me. This seems to be a common wish, every now and then we
see threads on this topic and many people have developed workarounds
so that it looks like Lua is a real OOP language, and (or as) the
game programing community uses C++ a lot. It's not necessary to add
predefined classes to the core (like Java's VM that rely on String
and StringBuffer at least), just the ability to define classes,
instantiate objects and calling [inherited] methods.

This is very possible... there are various ways to do it, but that's
what metaprogramming is about.  Regardless of how you get there you
end up with something about as elegant as you could ask for
(obj:method(), obj.attribute), but you have to 'do it yourself'
(though a simple implementation is already very simple).  So I can't
see a 'blessed' way of doing this making it to the core, but I assume
it's already well-covered by projects such as LuaCheia (and
definitely amply covered by the Wiki code).

--Adam

I've done it myself, and I'm not happy. I've seen how others did it
themselves, and I'm still not happy. Unless I'm missing something, I
don't see a way to get rid of the self local that must prefix every
property of the "class", making me write self.this and self.that. I
don't see an elegant way to call inherited methods like
super.something(...) or inherited something(...), but only hacks like
self.super.something(self, ...) or SuperClassName.something(self, ...).
I don't like that users of my applications get stuck because they don't
remember where they should use 'obj.' or 'obj:'.

The "blessed" way of doing it would come up from the community just like
the packaging system. OOP in Lua would add very little to the core and
make the language a great choice for many applications that require it.
I'd like to stress this: there is no small scripting language with OOP,
I've been looking to many options and they're all bloated with modules.

Please let's not start discussing what OOP is, I'd be more than happy
with classes (that would be first class values, of course) and
instances, getting rid of the self prefix for all properties, a standard
way to call inherited methods; static (or class) methods and properties
and access previledges would be an welcome bonus.

I *think* that the keyword "new" was reserved in Lua 4, wasn't it? It
made me think that maybe OOP was in its way for Lua 5 :(

Regards,

Andre de Leiradella