Commit a64dd511 authored by Hanspeter Portner's avatar Hanspeter Portner

manual: document forge patch containers.

* add forge:ack and forge:error methods.
parent 4b43c232
Pipeline #4299020 passed with stages
in 16 minutes and 11 seconds
......@@ -909,8 +909,8 @@ _lforge_get(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = lua_touserdata(L, 1);
const LV2_URID subject = luaL_optinteger(L, 2, 0);
const LV2_URID property = luaL_checkinteger(L, 3);
const LV2_URID property = luaL_checkinteger(L, 2);
const LV2_URID subject = luaL_optinteger(L, 3, 0);
const int32_t sequence_num = luaL_optinteger(L, 4, 0);
LV2_Atom_Forge_Frame frame;
......@@ -947,8 +947,8 @@ _lforge_set(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = lua_touserdata(L, 1);
const LV2_URID subject = luaL_optinteger(L, 2, 0);
const LV2_URID property = luaL_checkinteger(L, 3);
const LV2_URID property = luaL_checkinteger(L, 2);
const LV2_URID subject = luaL_optinteger(L, 3, 0);
const int32_t sequence_num = luaL_optinteger(L, 4, 0);
lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
......@@ -1085,6 +1085,70 @@ _lforge_add(lua_State *L)
return 1; // derived forge
}
static int
_lforge_ack(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = lua_touserdata(L, 1);
const LV2_URID subject = luaL_optinteger(L, 2, 0);
const int32_t sequence_num = luaL_optinteger(L, 3, 0);
LV2_Atom_Forge_Frame frame;
if(!lv2_atom_forge_object(lforge->forge, &frame, 0, moony->uris.patch.ack))
luaL_error(L, forge_buffer_overflow);
if(subject) // is optional
{
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.subject))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_urid(lforge->forge, subject))
luaL_error(L, forge_buffer_overflow);
}
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.sequence))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_int(lforge->forge, sequence_num))
luaL_error(L, forge_buffer_overflow);
lv2_atom_forge_pop(lforge->forge, &frame);
lua_settop(L, 1);
return 1;
}
static int
_lforge_error(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = lua_touserdata(L, 1);
const LV2_URID subject = luaL_optinteger(L, 2, 0);
const int32_t sequence_num = luaL_optinteger(L, 3, 0);
LV2_Atom_Forge_Frame frame;
if(!lv2_atom_forge_object(lforge->forge, &frame, 0, moony->uris.patch.error))
luaL_error(L, forge_buffer_overflow);
if(subject) // is optional
{
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.subject))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_urid(lforge->forge, subject))
luaL_error(L, forge_buffer_overflow);
}
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.sequence))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_int(lforge->forge, sequence_num))
luaL_error(L, forge_buffer_overflow);
lv2_atom_forge_pop(lforge->forge, &frame);
lua_settop(L, 1);
return 1;
}
static int
_lforge_pop(lua_State *L)
{
......@@ -1171,6 +1235,8 @@ const luaL_Reg lforge_mt [] = {
{"patch", _lforge_patch},
{"remove", _lforge_remove},
{"add", _lforge_add},
{"ack", _lforge_ack},
{"error", _lforge_error},
{"pop", _lforge_pop},
......
......@@ -1194,14 +1194,14 @@ do
local rtid = VoiceMap() & 0x7fffffff
local function producer(forge)
forge:time(0):get(subject, property, rtid)
forge:time(0):get(property, subject, rtid)
forge:time(1):get(nil, property, rtid)
forge:time(1):get(property, nil, rtid)
local set = forge:time(2):set(subject, property, rtid)
local set = forge:time(2):set(property, subject, rtid)
set:string('hello world'):pop()
local set = forge:time(3):set(nil, property, rtid)
local set = forge:time(3):set(property, nil, rtid)
set:string('hello world'):pop()
local patch = forge:time(4):patch(subject, rtid)
......@@ -1227,10 +1227,14 @@ do
local put = forge:time(6):put(subject, rtid)
put:key(property):string('hello world')
put:pop()
forge:time(7):ack(subject, rtid)
forge:time(8):error(subject, rtid)
end
local function consumer(seq)
assert(#seq == 7)
assert(#seq == 9)
local get = seq[1]
assert(get.type == Atom.Object)
......@@ -1300,6 +1304,20 @@ do
assert(body)
assert(#body == 1)
assert(body[property].body == 'hello world')
local ack = seq[8]
assert(ack.type == Atom.Object)
assert(ack.otype == Patch.Ack)
assert(#ack == 2)
assert(ack[Patch.subject].body == subject)
assert(ack[Patch.sequenceNumber].body == rtid)
local err = seq[9]
assert(err.type == Atom.Object)
assert(err.otype == Patch.Error)
assert(#err == 2)
assert(err[Patch.subject].body == subject)
assert(err[Patch.sequenceNumber].body == rtid)
end
test(producer, consumer)
......@@ -1350,11 +1368,11 @@ do
})
local function producer(forge)
forge:frame_time(0):get(urid.subject, urid.int)
forge:frame_time(1):set(urid.subject, urid.int):typed(Atom.Int, 2):pop()
forge:frame_time(0):get(urid.int, urid.subject)
forge:frame_time(1):set(urid.int, urid.subject):typed(Atom.Int, 2):pop()
forge:frame_time(2):get(urid.subject, urid.flt)
forge:frame_time(3):set(urid.subject, urid.flt):typed(Atom.Float, 2.0):pop()
forge:frame_time(2):get(urid.flt, urid.subject)
forge:frame_time(3):set(urid.flt, urid.subject):typed(Atom.Float, 2.0):pop()
-- state:stash
forge:frame_time(4)
......
This diff is collapsed.
......@@ -45,7 +45,7 @@ var LuaHighlightRules = function() {
// moony forge
"frame_time|beat_time|time|atom|int|long|float|double|bool|urid|string|literal|uri|path|"+
"chunk|midi|raw|bundle|message|tuple|object|key|property|vector|sequence|"+
"typed|get|set|put|patch|remove|add|pop|"+
"typed|get|set|put|patch|remove|add|ack|error|pop|"+
// moony common
"foreach|unpack|clone|stash|apply|register|"+
// moony stash
......
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