[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How Lua code can be updated at runtime without breaking global state?
- From: Graham Wakefield <wakefield@...>
- Date: Wed, 27 Mar 2013 20:20:45 +0900
Hi Ross,
Nothing terribly documented yet (a journal submission in review...). Here's the basic idea:
The query system assumes a world of agents which can be arbitrarily 'tagged' with different names, using agent:tag(name) and agent:untag(name) methods, or Tag[name]:add(agent) to do it the other way around.
Tags can be modified directly by assignment, e.g.
Tag.foo = {
color = { 1, 1, 0 },
-- etc.
}
Queries can work on tagged entities using Q(), which can be chained, and used to set properties, call methods, etc.:
-- set the amplitude of the most recently created red-tagged agent:
Q("red"):last().amp = 0.5
-- terminate all agents which have a color assigned:
Q("*"):has("color"):die()
-- set the frequency of about half of all agents:
Q("*"):pick(0.5).freq = 200
-- set the frequency of four randomly selected red agents:
Q("red"):pick(4).freq = 500
-- stop one randomly selected agent from moving:
Q("*"):pick():halt()
The expression-object stuff borrows the same syntax as the audio synth defs in LuaAV.
-- construct an expression:
expr1 = (Max(Random(10), Random(10)) + 2) * 100
-- assign to property "freq" of all agents tagged "foo"
Q("foo").freq = expr1
This evaluates the expression for each match in the query (so they all get different random values). Regular Lua functions can be used too. Stateful expressions (oscillators etc.) create behaviors in the agent, rather than directly assigning a value.
We also added coroutine-based scheduling, and arbitrary event handling (e.g. agent:on(eventname, callback)).
The infrastructure of tags, queries, exprs, schedulers and events makes it easy to build up complex structures (and more importantly, modify them while they run) with very minimal blocks of code. We used it for collaborative performances creating immersive worlds.
I hope to get this shaped up into release-worthy condition soon, but I've just had my first child so time is hard to acquire...
Graham
On Mar 27, 2013, at 3:52 PM, Ross Bencina wrote:
> On 26/03/2013 9:42 PM, Graham Wakefield wrote:
>> Our most recent live coding experiments have shifted to using more
>> declarative problem-oriented syntaxes built on top of Lua, such as
>> expression object constructions and jQuery-style select/map
>> applications.
>
> Hi Graham,
>
> Do you have any links to your work with expression objects and jQuery-style select/map?
>
> I've started to play with Rx-style pipeline constructors for this kind of thing but no results of note yet.
>
> Ross.
>