Commit b861be53 authored by Hanspeter Portner's avatar Hanspeter Portner

implement serial forge function calling.

parent 2e72b599
......@@ -34,6 +34,7 @@ Get more information at: [http://open-music-kontrollers.ch/lv2/moony](http://ope
* [LV2](http://lv2plug.in) (LV2 Plugin Standard)
* [Lua](http://lua.org) (Lightweight embeddable language)
* [Flex](http://flex.sourceforge.net) (Fast Lexical Analyzer)
* [Elementary](http://enlightenment.org) (Lightweight GUI Toolkit)
### Build / install
......
......@@ -966,7 +966,8 @@ _lforge_frame_time(lua_State *L)
lv2_atom_forge_frame_time(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -977,7 +978,8 @@ _lforge_beat_time(lua_State *L)
lv2_atom_forge_beat_time(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -997,7 +999,8 @@ _lforge_atom(lua_State *L)
lv2_atom_forge_raw(lforge->forge, atom, sizeof(LV2_Atom) + atom->size);
lv2_atom_forge_pad(lforge->forge, atom->size);
return 0;
lua_settop(L, 1);
return 1;
}
return luaL_error(L, "Atom expected at position #2");
......@@ -1011,7 +1014,8 @@ _lforge_int(lua_State *L)
lv2_atom_forge_int(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1022,7 +1026,8 @@ _lforge_long(lua_State *L)
lv2_atom_forge_long(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1033,7 +1038,8 @@ _lforge_float(lua_State *L)
lv2_atom_forge_float(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1044,7 +1050,8 @@ _lforge_double(lua_State *L)
lv2_atom_forge_double(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1055,7 +1062,8 @@ _lforge_bool(lua_State *L)
lv2_atom_forge_bool(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1066,7 +1074,8 @@ _lforge_urid(lua_State *L)
lv2_atom_forge_urid(lforge->forge, val);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1078,7 +1087,8 @@ _lforge_string(lua_State *L)
lv2_atom_forge_string(lforge->forge, val, size);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1092,7 +1102,8 @@ _lforge_literal(lua_State *L)
lv2_atom_forge_literal(lforge->forge, val, size, datatype, lang);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1104,7 +1115,8 @@ _lforge_uri(lua_State *L)
lv2_atom_forge_uri(lforge->forge, val, size);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1116,7 +1128,8 @@ _lforge_path(lua_State *L)
lv2_atom_forge_path(lforge->forge, val, size);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1157,7 +1170,8 @@ _lforge_bytes(lua_State *L, moony_t *moony, LV2_URID type)
lv2_atom_forge_pad(lforge->forge, size);
}
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1193,7 +1207,7 @@ _lforge_osc_bundle(lua_State *L)
osc_forge_bundle_push(oforge, forge, lframe->frame, timestamp);
return 1;
return 1; // derived forge
}
static int
......@@ -1328,7 +1342,8 @@ _lforge_osc_message(lua_State *L)
osc_forge_message_pop(oforge, forge, frame);
return 0;
lua_settop(L, 1);
return 1;
}
static int
......@@ -1342,7 +1357,7 @@ _lforge_tuple(lua_State *L)
lv2_atom_forge_tuple(lforge->forge, &lframe->frame[0]);
return 1;
return 1; // derived forge
}
static int
......@@ -1358,7 +1373,7 @@ _lforge_object(lua_State *L)
lv2_atom_forge_object(lforge->forge, &lframe->frame[0], id, otype);
return 1;
return 1; // derived forge
}
static int
......@@ -1369,6 +1384,7 @@ _lforge_key(lua_State *L)
lv2_atom_forge_key(lforge->forge, key);
lua_settop(L, 1);
return 1;
}
......@@ -1381,6 +1397,7 @@ _lforge_property(lua_State *L)
lv2_atom_forge_property_head(lforge->forge, key, context);
lua_settop(L, 1);
return 1;
}
......@@ -1396,7 +1413,7 @@ _lforge_sequence(lua_State *L)
lv2_atom_forge_sequence_head(lforge->forge, &lframe->frame[0], unit);
return 1;
return 1; // derived forge
}
static int
......@@ -1406,6 +1423,7 @@ _lforge_pop(lua_State *L)
for(int i=lforge->depth; i>0; i--)
lv2_atom_forge_pop(lforge->forge, &lforge->frame[i-1]);
lforge->depth = 0; // reset depth
return 0;
}
......@@ -1429,8 +1447,8 @@ static const luaL_Reg lforge_mt [] = {
//TODO vector
{"chunk", _lforge_chunk},
{"midi", _lforge_midi},
{"osc_bundle", _lforge_osc_bundle},
{"osc_message", _lforge_osc_message},
{"bundle", _lforge_osc_bundle},
{"message", _lforge_osc_message},
{"tuple", _lforge_tuple},
{"object", _lforge_object},
{"key", _lforge_key},
......
......@@ -154,8 +154,8 @@ forge:midi(0x90, 0x4a, 0x7f) -- push individual Lua integers as MIDI message
forge:chunk({0x01, 0x02, 0x03, 0x04}) -- push a Lua table as atom chunk
forge:chunk(0x01, 0x02, 0x03, 0x04) -- push individual Lua integers as atom chunk
bndl = forge:osc_bundle(1) -- start a new OSC bundle with timestamp (returns a derived forge container)
bndl:osc_message('/hello', 'si', 'world', 2015) -- push a complete OSC message
bndl = forge:bundle(1) -- start a new OSC bundle with timestamp (returns a derived forge container)
bndl:message('/hello', 'si', 'world', 2015) -- push a complete OSC message
bndl:pop() -- finalize derived forge container
tup = forge:tuple() -- start a new tuple (returns a derived forge container)
......@@ -169,6 +169,11 @@ obj:pop() -- finalize derived forge container
seq = forge:sequence(unit) -- start a nested sequence (returns a derived forge container)
seq:pop()
-- All forge function but forge:pop return a forge; either itself or a
-- derived one, depending on context. One can thus fill values in sequence, e.g:
forge:frame_time(0):midi(0x90, 0x20, 0x7f):frame_time(1):midi(0x80, 0x20, 0x00)
forge:frame_time(2):object(id, otype):key(key):int(1):pop()
--[[---------------------------------------------------------------------------
Atom Object
-----------------------------------------------------------------------------]]
......
......@@ -35,8 +35,7 @@ do
forge:frame_time(0)
forge:int(0x7fffffff)
forge:frame_time(0)
forge:int(0xffffffff)
forge:frame_time(0):int(0xffffffff)
end
local function consumer(seq)
......@@ -61,8 +60,7 @@ end
print('[test] Long')
do
local function producer(forge)
forge:frame_time(0)
forge:long(0x100000000)
forge:frame_time(0):long(0x100000000)
end
local function consumer(seq)
......@@ -101,8 +99,7 @@ end
print('[test] Double')
do
local function producer(forge)
forge:frame_time(0)
forge:double(0.12)
forge:frame_time(0):double(0.12)
end
local function consumer(seq)
......@@ -121,11 +118,8 @@ end
print('[test] Bool')
do
local function producer(forge)
forge:frame_time(0)
forge:bool(true)
forge:frame_time(0)
forge:bool(false)
forge:frame_time(0):bool(true)
forge:frame_time(0):bool(false)
end
local function consumer(seq)
......@@ -246,8 +240,7 @@ do
local urid = Map[uri]
local function producer(forge)
forge:frame_time(0)
forge:urid(urid)
forge:frame_time(0):urid(urid)
end
local function consumer(seq)
......@@ -269,8 +262,7 @@ do
local m = {0x90, 0x2a, 0x7f}
local function producer(forge)
forge:frame_time(0)
forge:midi(m)
forge:frame_time(0):midi(m)
forge:frame_time(0)
forge:midi(table.unpack(m))
......@@ -401,11 +393,8 @@ do
local function producer(forge)
forge:frame_time(0)
local tup = forge:tuple()
tup:int(1)
tup:float(2.0)
tup:long(3)
tup:double(4.0)
tup:pop()
assert(tup ~= forge)
tup:int(1):float(2.0):long(3):double(4.0):pop()
end
local function consumer(seq)
......@@ -466,16 +455,15 @@ do
local key2 = Map['http://test.org#key2']
local function producer(forge)
forge:frame_time(0)
assert(forge:frame_time(0) == forge)
local obj = forge:object(id, otype)
assert(obj ~= forge)
obj:key(key1)
obj:int(12)
assert(obj:key(key1):int(12) == obj)
obj:property(key2, context2)
obj:long(13)
obj:property(key2, context2):long(13)
obj:pop()
assert(obj:pop() == nil)
end
local function consumer(seq)
......@@ -522,8 +510,7 @@ do
assert(atom.type == Atom.Int)
assert(atom.value == 12)
forge0:frame_time(0)
forge0:atom(atom)
forge0:frame_time(0):atom(atom)
end
test(producer, consumer)
......@@ -534,28 +521,28 @@ print('[test] OSC')
do
local function producer(forge)
forge:frame_time(0)
forge:osc_message('/hello', 'sif', 'world', 12, 13.0)
forge:message('/hello', 'sif', 'world', 12, 13.0)
forge:frame_time(1)
forge:osc_message('/hallo', 'Shdt', 'velo', 12, 13.0, 1)
forge:message('/hallo', 'Shdt', 'velo', 12, 13.0, 1)
forge:frame_time(2)
forge:osc_message('/yup', 'c', string.byte('a'))
forge:message('/yup', 'c', string.byte('a'))
forge:frame_time(3)
forge:osc_message('/singletons', 'TFNI')
forge:message('/singletons', 'TFNI')
forge:frame_time(4)
forge:osc_message('/chunky', 'mb', {0x90, 0x20, 0x7f}, {0x01, 0x02, 0x03, 0x04})
forge:message('/chunky', 'mb', {0x90, 0x20, 0x7f}, {0x01, 0x02, 0x03, 0x04})
forge:frame_time(5)
local bndl = forge:osc_bundle(1)
bndl:osc_message('/one', 'i', 1)
bndl:osc_message('/two', 'i', 2)
bndl:osc_message('/three', 'i', 3)
local nested = bndl:osc_bundle(1)
nested:pop()
bndl:pop()
local bndl = forge:bundle(1)
assert(bndl ~= forge)
bndl:message('/one', 'i', 1)
bndl:message('/two', 'i', 2)
bndl:message('/three', 'i', 3)
bndl:bundle(1):pop() -- nested
assert(bndl:pop() == nil)
end
local function consumer(seq)
......@@ -702,14 +689,12 @@ do
local function producer(forge)
forge:frame_time(0)
local subseq = forge:sequence()
assert(subseq ~= forge)
subseq:frame_time(1)
subseq:int(1)
subseq:frame_time(2)
subseq:int(2)
subseq:frame_time(1):int(1)
subseq:frame_time(2):int(2)
subseq:pop()
assert(subseq:pop() == nil)
end
local function consumer(seq)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment