lua-users home
lua-l archive

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


Hi Steve Donovan and people interested in this talk,

I implemented Strategy Pattern using of YACI[1]

https://github.com/Journeyer/yaci.lua/tree/hfdplua/hfdplua

I forked original YACI from github and created a branch - hfdplua.

In this branch, I will implement GoF's patterns and I will make a test suit for YACI using of these patterns implementations.

After I finished making a test suite I will submit the pull request to the host of YACI.

You said virtual function is not supported by lua. But YACI supports it though it would be too much complicated and never simple.

Without virtual function feature, I believe almost no GoF patterns could be implemented.

I received many OO library recommendations but YACI is one which has virtual function. I didn't search enough for other libraries but, until now YACI is the only one.
(If not please let me know. I am talking to the people provided me the library recommendations for this)

And If anyone should find any problem from my Strategy pattern implementation, please let me know.
This is almost my first time to make a lua program.
One thing I am not sure of is 'require' sentence. I don't know about environment and module, so I am not sure of my using of 'require' sentences.

Sincerely
Journeyer


[1] http://lua-users.org/wiki/YetAnotherClassImplementation


----------------------------------------
Journeyer J. Joh
o o s a p r o g r a m m e r
a t
g m a i l  d o t  c o m
----------------------------------------


2014-02-26 12:08 GMT+09:00 Journeyer J. Joh <oosaprogrammer@gmail.com>:
Hi Steve Donovan,

I understand what you mean though my understanding is not 100%.

But there is one, YACI[1], I understand that it would be too much complicated and never simple. But it supports something similar to virtual function. It even supports abstract function.

Now I am trying to implement strategy pattern using YACI. I will try it and if I succeeded I will open it here so that people can look and hopely people can give me some feedback. I wish you could also. ^^;

Thank you very much.
Sincerely
Journeyer

[1] http://lua-users.org/wiki/YetAnotherClassImplementation


----------------------------------------
Journeyer J. Joh
o o s a p r o g r a m m e r
a t
g m a i l  d o t  c o m
----------------------------------------


2014-02-25 21:45 GMT+09:00 steve donovan <steve.j.donovan@gmail.com>:
On Tue, Feb 25, 2014 at 5:21 AM, Journeyer J. Joh

<oosaprogrammer@gmail.com> wrote:
> Does penligh's class library support virtual function?

As Andrew says, the concept does not apply to Lua.

It is useful to look at the basics of 'OOP' in Lua:

obj:method(args) is exactly equivalent to obj.method(obj,args) - so
'method lookup' is exactly the same as table lookup.  So the simplest
possible scheme is to put the functions inside obj, which is wasteful
for many objects - they all have to contain references to the
functions.  If  obj has a metatable M, and M.__index = T, then if
looking up 'method' fails in obj, it will look in T.  This allows us
to keep only the state in the object, and the functions elsewhere.

Easiest way of seeing inheritance is the 'fat metable', where T will
initially contain all the inherited functions ('copy of base class'),
and then the new 'overrides' will be copied into T.  To a first
approximation you can think of T as a VMT (Virtual Method Table)
except it is indexed by name, not slot.

So everything is 'virtual', because obj.method will always pick up the
version redefined for that 'class'.