lua-users home
lua-l archive

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

And still this would only apply to those 'objects' that don't have any attributes.

given a table 'object'

table_object =
	method = function () end,
	attribute = 1

table_object.attribute = 2
table_object : method()

How can one convert this into a functional one? So, the proposed feature would only apply to objects that effectively are bags of functions with no data. Right? I think, practically, most objects people are dealing with have both methods and attributes. Given an function based object, can one use attributes with them?


function_object:method() --> function_object("method")
function_object.attribute --> ???


-----Original Message-----
From: Rici Lake []
Sent: Wednesday, September 22, 2004 12:13 PM
To: Lua list
Subject: Re: Functional objects

On 22-Sep-04, at 2:06 PM, Bilyk, Alex wrote:

> With all it's limitations and peculiarities of [mis]use in some 
> contexts I fail to see how Lua would benefit from this on one hand, 
> while I also fail to see what is wrong with
> function_obj("msg", ... )
> to begin with. The above form, while marginally longer to type, is 
> clear to anyone and works for any string.

Well, that was my first reaction, too. But when I started to think 
about it, particularly when playing around with implementing objects as 
coroutines, I realised that it is nice to be able to do:

   obj:method(arg1, arg2)

without having to know whether obj is a traditional table-based object, 
or a function-based object. (In other words, the implementation of obj 
could change without having to change consumers of the object.) Of 
course, you could write a wrapper for obj to make it work properly, but 
Mark's idea seems like a nice way of getting around having to do that.

So (I presume) it would be specifically for that case, in which case it 
is not really that limited or peculiar.