[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: OO Syntax
- From: Eric Tetz <erictetz@...>
- Date: Wed, 24 Apr 2002 10:56:44 -0700 (PDT)
I'm comfortable with the bit of "syntax sugar" trickery Lua uses for
'method' invocation, i.e.:
object:method()
However, I'm finding that users in my Alpha test group are tripped
up by this quite often. I make heavy use of namespaces, so I use
might be called upon to write something like:
menu = mmb.newMenu() -- no table constructor, for example sake...
menu:add('Restore')
menu:add('Exit')
choice = menu:show()
if choice == 1 then
mmb.restoreApp()
else
mmb.exit()
end
Where 'mmb' is a namespace, and 'menu' is an object.
The problem is, users often forget which is which. Do they use ':' or
'.'? Sure, as they become Lua experts, and become more familiar with
my library, this will be a non-issue, but I don't want them to have to
become experts.
I would like to be able to tag a function as a 'method', at which
point it automatically provides the ':' invocation semantics. So I
could say:
menu = mmb.newMenu()
menu.add('Restore')
menu.add('Exit')
choice = menu.show()
if choice == 1 then
mmb.restoreApp()
else
mmb.exit()
end
As in Java, JavaScript, C#, etc.
Is there a way to do it without modifying the source? Has this been considered in the
past? Is there a patch somewhere?
Cheers,
Eric
__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/