Suppose we have the following class definition:
MyClass = class {That is, a simple class with a property name and two methods: ping and pong.
function init (self, name)
self._name = name
end,
function ping (self)
print('ping', self._name)
end,
function pong (self)
print('pong', self._name)
end,
}
Now we create three objects and link some of their methods:
a = MyClass('a')Then, a simple call to a.ping yields in:
b = MyClass('b')
c = MyClass('c')
LINK(a.ping, b.pong)
LINK(b.pong, c.ping)
LINK(c.ping, a.pong)
> a.ping()That simple! A method is implicitly called in reaction to a call in another condition method.
ping a
pong b
ping c
pong a
Comparing to event-driven programming, there's no need to define or post events, it's all made implicitly. Much less verbosity.
The reactive variables of LuaGravity (shown here and here) override Lua's default behavior for attribution. So:
b = aIs equivalent to:
a = 2
LINK(a.update, b.update)Variables are, instead, special objects with an update method.
a.update(2)
The parameter in a method call is propagated through its link chain as in a pipeline.
This way the value 2 is also passed to b.update.
A simple example of using LuaGravity in multimedia applications would go like this:
LINK(video1.start, video2.start)The first link makes video1 and video2 play in parallel, while the second link makes video3 and video4 play in sequence.
LINK(video3.stop, video4.start)
By overloading the operators + and * one could just write:
video1 + video2 -- play in parallel
video3 * video4 -- play in sequence
In LuaGravity, event definition is implicit, event posting is implicit and event linking may also be implicit (through operator overloading).
Given the amount of times the word implicit appears in this text, could LuaGravity be considered an implicit implicit invocation system?
"The parameter in a method call is propagated through its link chain as in a pipeline."
ReplyDeleteIs the parameter allowed to be changed inside a method call? The link chain would be much more useful if state changes and computation results are propagated through it. This information is not implicit in your text. :)
P.S.: Quite good syntax, by the way.
You are right, it's not implicit. :)
ReplyDeleteThe return value of each method in the chain is passed as a parameter to the next method.
So, it's possible (and common) that the information in a dataflow is changed from one end to the other as in filters.