aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2016-02-21 18:55:26 +0100
committerHanspeter Portner <dev@open-music-kontrollers.ch>2016-02-21 18:55:26 +0100
commit0c7fff2025d8306aade81b4e46d18ff10be2e406 (patch)
tree45f61f5e3011a52baf9f43969ad2e5819117a6fb
parentb9b29b3844d669fe7ed157ae04774c0f513490f2 (diff)
downloadmoony.lv2-0c7fff2025d8306aade81b4e46d18ff10be2e406.tar.xz
inherit userdata cache flag to children.
* add cache flag to latom/lforge userdata. * inherit cache flag to latom/lforge children. * increase initial stash memory to 1024. * fix latom_atom to use separate atom and body.
-rw-r--r--api.c70
-rw-r--r--api_atom.c31
-rw-r--r--api_atom.h6
-rw-r--r--api_forge.c26
-rw-r--r--api_forge.h2
-rw-r--r--api_stash.c6
-rw-r--r--axa.c8
-rw-r--r--caxca.c8
-rw-r--r--cxc.c4
-rw-r--r--moony.h8
-rw-r--r--test_moony.c10
11 files changed, 104 insertions, 75 deletions
diff --git a/api.c b/api.c
index f684278..e871b8b 100644
--- a/api.c
+++ b/api.c
@@ -363,16 +363,17 @@ _stash(lua_State *L)
lua_getglobal(L, "stash");
if(lua_isfunction(L, -1))
{
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, true);
lframe->depth = 0;
lframe->last.frames = 0;
lframe->forge = &moony->stash_forge;
atom_ser_t ser = {
.tlsf = moony->vm.tlsf, // use tlsf_realloc
- .size = 256,
- .buf = tlsf_malloc(moony->vm.tlsf, 256)
+ .size = 1024,
+ .offset = 0
};
+ ser.buf = tlsf_malloc(moony->vm.tlsf, ser.size);
if(ser.buf)
{
@@ -402,7 +403,7 @@ _apply(lua_State *L)
lua_getglobal(L, "apply");
if(lua_isfunction(L, -1))
{
- _latom_new(L, moony->stash_atom);
+ _latom_new(L, moony->stash_atom, false);
lua_call(L, 1, 0);
}
else
@@ -418,7 +419,7 @@ _save(lua_State *L)
if(lua_getglobal(L, "save") == LUA_TFUNCTION)
{
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, true);
lframe->depth = 0;
lframe->last.frames = 0;
lframe->forge = &moony->state_forge;
@@ -457,9 +458,10 @@ _state_save(LV2_Handle instance, LV2_State_Store_Function store,
atom_ser_t ser = {
.tlsf = NULL,
- .size = 256,
- .buf = malloc(256)
+ .size = 1024,
+ .offset = 0
};
+ ser.buf = malloc(ser.size);
if(ser.buf)
{
@@ -481,6 +483,7 @@ _state_save(LV2_Handle instance, LV2_State_Store_Function store,
lv2_log_error(&moony->logger, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
}
+ lua_gc(L, LUA_GCSTEP, 0);
_unlock(&moony->lock.state);
@@ -510,7 +513,7 @@ _restore(lua_State *L)
if(lua_getglobal(L, "restore") == LUA_TFUNCTION)
{
- _latom_new(L, moony->state_atom);
+ _latom_new(L, moony->state_atom, false);
lua_call(L, 1, 0);
}
@@ -1356,36 +1359,50 @@ moony_open(moony_t *moony, lua_State *L, bool use_assert)
}
void *
-moony_newuserdata(lua_State *L, moony_t *moony, moony_udata_t type)
+moony_newuserdata(lua_State *L, moony_t *moony, moony_udata_t type, bool cache)
{
assert( (type >= MOONY_UDATA_ATOM) && (type < MOONY_UDATA_COUNT) );
int *itr = &moony->itr[type];
void *data = NULL;
- lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + type); // ref
- if(lua_rawgeti(L, -1, *itr) == LUA_TNIL) // no cached udata, create one!
+ if(cache) // do cash this!
{
+ lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + type); // ref
+ if(lua_rawgeti(L, -1, *itr) == LUA_TNIL) // no cached udata, create one!
+ {
#if 0
- if(moony->log)
- lv2_log_trace(&moony->logger, "moony_newuserdata: %s\n", moony_ref[type]);
+ if(moony->log)
+ lv2_log_trace(&moony->logger, "moony_newuserdata: %s\n", moony_ref[type]);
#endif
- lua_pop(L, 1); // nil
-
+ lua_pop(L, 1); // nil
+
+ data = lua_newuserdata(L, moony_sz[type]);
+ lheader_t *lheader = data;
+ lheader->type = type;
+ lheader->cache = cache;
+ luaL_getmetatable(L, moony_ref[type]);
+ lua_setmetatable(L, -2);
+ lua_pushvalue(L, -1);
+ lua_rawseti(L, -3, *itr); // store in cache
+ }
+ else // there is a cached udata, use it!
+ {
+ data = lua_touserdata(L, -1);
+ //printf("moony_newuserdata: %s %"PRIi32" %p\n", moony_ref[type], *itr, data);
+ }
+ lua_remove(L, -2); // ref
+ *itr += 1;
+ }
+ else // do not cash this!
+ {
data = lua_newuserdata(L, moony_sz[type]);
- *(moony_udata_t *)data = type;
+ lheader_t *lheader = data;
+ lheader->type = type;
+ lheader->cache = cache;
luaL_getmetatable(L, moony_ref[type]);
lua_setmetatable(L, -2);
- lua_pushvalue(L, -1);
- lua_rawseti(L, -3, *itr); // store in cache
- }
- else // there is a cached udata, use it!
- {
- data = lua_touserdata(L, -1);
- //printf("moony_newuserdata: %s %"PRIi32" %p\n", moony_ref[type], *itr, data);
}
- lua_remove(L, -2); // ref
- *itr += 1;
return data;
}
@@ -1471,6 +1488,7 @@ moony_in(moony_t *moony, const LV2_Atom_Sequence *control, LV2_Atom_Sequence *no
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_STASH);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
+ lua_gc(L, LUA_GCSTEP, 0);
// load chunk
const char *str = LV2_ATOM_BODY_CONST(value);
@@ -1492,6 +1510,7 @@ moony_in(moony_t *moony, const LV2_Atom_Sequence *control, LV2_Atom_Sequence *no
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_RESTORE);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
+ lua_gc(L, LUA_GCSTEP, 0);
}
/* FIXME FIXME FIXME do we want this?
@@ -1521,6 +1540,7 @@ moony_in(moony_t *moony, const LV2_Atom_Sequence *control, LV2_Atom_Sequence *no
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_APPLY);
if(lua_pcall(L, 0, 0, 0))
moony_error(moony);
+ lua_gc(L, LUA_GCSTEP, 0);
tlsf_free(moony->vm.tlsf, moony->stash_atom);
moony->stash_atom = NULL;
diff --git a/api_atom.c b/api_atom.c
index 9be9888..b484609 100644
--- a/api_atom.c
+++ b/api_atom.c
@@ -31,7 +31,7 @@ static const lua_CFunction upclosures [MOONY_UPCLOSURE_COUNT] = {
};
static inline void
-_pushupclosure(lua_State *L, moony_t *moony, moony_upclosure_t type)
+_pushupclosure(lua_State *L, moony_t *moony, moony_upclosure_t type, bool cache)
{
assert( (type >= MOONY_UPCLOSURE_TUPLE_FOREACH) && (type < MOONY_UPCLOSURE_COUNT) );
@@ -48,7 +48,7 @@ _pushupclosure(lua_State *L, moony_t *moony, moony_upclosure_t type)
lua_pop(L, 1); // nil
lua_pushlightuserdata(L, moony);
- _latom_new(L, NULL); // place-holder
+ _latom_new(L, NULL, cache); // place-holder
lua_pushcclosure(L, upclosures[type], 2);
lua_pushvalue(L, -1);
@@ -64,7 +64,8 @@ _latom_clone(lua_State *L)
latom_t *latom = lua_touserdata(L, 1);
latom_t *litem = lua_newuserdata(L, sizeof(latom_t) + lv2_atom_total_size(latom->atom));
- litem->type = MOONY_UDATA_ATOM;
+ litem->lheader.type = MOONY_UDATA_ATOM;
+ litem->lheader.cache = false;
litem->atom = (const LV2_Atom *)litem->payload;
litem->body.raw = LV2_ATOM_BODY_CONST(litem->atom);
@@ -83,7 +84,7 @@ _latom__gc(lua_State *L)
{
latom_t *latom = lua_touserdata(L, 1);
- if(latom->type == MOONY_UDATA_STASH)
+ if(latom->lheader.type == MOONY_UDATA_STASH)
return _lstash__gc(L);
return 0;
@@ -375,7 +376,7 @@ _latom_tuple__indexi(lua_State *L, latom_t *latom)
{
if(++count == idx)
{
- _latom_new(L, atom);
+ _latom_new(L, atom, latom->lheader.cache);
return 1;
}
}
@@ -423,7 +424,7 @@ _latom_tuple_unpack(lua_State *L)
{
if(pos <= max)
{
- _latom_new(L, atom);
+ _latom_new(L, atom, latom->lheader.cache);
count += 1;
}
else
@@ -473,7 +474,7 @@ _latom_tuple_foreach(lua_State *L)
latom->iter.tuple.pos = 1;
latom->iter.tuple.item = latom->body.tuple;
- _pushupclosure(L, moony, MOONY_UPCLOSURE_TUPLE_FOREACH);
+ _pushupclosure(L, moony, MOONY_UPCLOSURE_TUPLE_FOREACH, latom->lheader.cache);
lua_pushvalue(L, 1);
return 2;
@@ -496,7 +497,7 @@ _latom_obj__indexi(lua_State *L, latom_t *latom)
lv2_atom_object_body_get(latom->atom->size, latom->body.obj, urid, &atom, 0);
if(atom) // query returned a matching atom
- _latom_new(L, atom);
+ _latom_new(L, atom, latom->lheader.cache);
else // query returned no matching atom
lua_pushnil(L);
@@ -570,7 +571,7 @@ _latom_obj_foreach(lua_State *L)
// reset iterator to beginning of object
latom->iter.obj.prop = lv2_atom_object_begin(latom->body.obj);
- _pushupclosure(L, moony, MOONY_UPCLOSURE_OBJECT_FOREACH);
+ _pushupclosure(L, moony, MOONY_UPCLOSURE_OBJECT_FOREACH, latom->lheader.cache);
lua_pushvalue(L, 1);
return 2;
@@ -594,7 +595,7 @@ _latom_seq__indexi(lua_State *L, latom_t *latom)
{
if(++count == index)
{
- _latom_new(L, &ev->body);
+ _latom_new(L, &ev->body, latom->lheader.cache);
return 1;
}
}
@@ -656,7 +657,7 @@ _latom_seq_foreach(lua_State *L)
// reset iterator to beginning of sequence
latom->iter.seq.ev = lv2_atom_sequence_begin(latom->body.seq);
- _pushupclosure(L, moony, MOONY_UPCLOSURE_SEQUENCE_FOREACH);
+ _pushupclosure(L, moony, MOONY_UPCLOSURE_SEQUENCE_FOREACH, latom->lheader.cache);
lua_pushvalue(L, 1);
return 2;
@@ -679,7 +680,7 @@ _latom_vec__indexi(lua_State *L, latom_t *latom)
if( (index > 0) && (index <= count) )
{
- latom_t *litem = _latom_new(L, NULL);
+ latom_t *litem = _latom_new(L, NULL, latom->lheader.cache);
litem->atom = (const LV2_Atom *)latom->body.vec;
litem->body.raw = LV2_ATOM_VECTOR_BODY_ITEM_CONST(latom->body.vec, index - 1);
}
@@ -753,7 +754,7 @@ _latom_vec_unpack(lua_State *L)
for(int i=min; i<=max; i++)
{
- latom_t *litem = _latom_new(L, NULL);
+ latom_t *litem = _latom_new(L, NULL, latom->lheader.cache);
litem->atom = (const LV2_Atom *)latom->body.vec;
litem->body.raw = LV2_ATOM_VECTOR_BODY_ITEM_CONST(latom->body.vec, i - 1);
}
@@ -798,7 +799,7 @@ _latom_vec_foreach(lua_State *L)
/ latom->body.vec->child_size;
latom->iter.vec.pos = 0;
- _pushupclosure(L, moony, MOONY_UPCLOSURE_VECTOR_FOREACH);
+ _pushupclosure(L, moony, MOONY_UPCLOSURE_VECTOR_FOREACH, latom->lheader.cache);
lua_pushvalue(L, 1);
return 2;
@@ -930,7 +931,7 @@ _latom__index(lua_State *L)
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_CLONE);
return 1;
}
- else if(!strcmp(key, "write") && (latom->type == MOONY_UDATA_STASH) )
+ else if(!strcmp(key, "write") && (latom->lheader.type == MOONY_UDATA_STASH) )
{
lua_rawgeti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_WRITE);
return 1;
diff --git a/api_atom.h b/api_atom.h
index 772e5e9..641ab05 100644
--- a/api_atom.h
+++ b/api_atom.h
@@ -41,7 +41,7 @@ struct _latom_driver_t {
};
struct _latom_t {
- moony_udata_t type;
+ lheader_t lheader;
const LV2_Atom *atom;
@@ -134,11 +134,11 @@ int
_latom_vec_foreach_itr(lua_State *L);
static inline latom_t *
-_latom_new(lua_State *L, const LV2_Atom *atom)
+_latom_new(lua_State *L, const LV2_Atom *atom, bool cache)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
- latom_t *latom = moony_newuserdata(L, moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, moony, MOONY_UDATA_ATOM, cache);
if(atom)
{
latom->atom = atom;
diff --git a/api_forge.c b/api_forge.c
index 0100a8d..7f58657 100644
--- a/api_forge.c
+++ b/api_forge.c
@@ -96,8 +96,10 @@ _lforge_atom(lua_State *L)
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
latom_t *latom = luaL_checkudata(L, 2, "latom");
- if(!lv2_atom_forge_raw(lforge->forge, latom->atom, sizeof(LV2_Atom) + latom->atom->size))
+ if( !lv2_atom_forge_atom(lforge->forge, latom->atom->size, latom->atom->type)
+ && !lv2_atom_forge_raw(lforge->forge, latom->body.raw, latom->atom->size) )
luaL_error(L, forge_buffer_overflow);
+
lv2_atom_forge_pad(lforge->forge, latom->atom->size);
lua_settop(L, 1);
@@ -460,7 +462,7 @@ _lforge_osc_bundle(lua_State *L)
uint64_t timestamp = _lforge_to_timestamp(L, moony, lforge, 2);
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 2;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -611,7 +613,7 @@ _lforge_tuple(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -629,7 +631,7 @@ _lforge_object(lua_State *L)
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
LV2_URID id = luaL_optinteger(L, 2, 0);
LV2_URID otype = luaL_optinteger(L, 3, 0);
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -790,7 +792,7 @@ _lforge_sequence(lua_State *L)
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
LV2_URID unit = luaL_optinteger(L, 2, 0); //TODO use proper unit
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = 0;
lframe->forge = lforge->forge;
@@ -898,7 +900,7 @@ _lforge_set(lua_State *L)
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
LV2_URID subject = luaL_optinteger(L, 2, 0);
LV2_URID property = luaL_checkinteger(L, 3);
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -931,7 +933,7 @@ _lforge_put(lua_State *L)
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
LV2_URID subject = luaL_optinteger(L, 2, 0);
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 2;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -961,7 +963,7 @@ _lforge_patch(lua_State *L)
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
LV2_URID subject = luaL_optinteger(L, 2, 0);
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -985,7 +987,7 @@ _lforge_remove(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -1003,7 +1005,7 @@ _lforge_add(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
- lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, moony, MOONY_UDATA_FORGE, lforge->lheader.cache);
lframe->depth = 1;
lframe->last.frames = lforge->last.frames;
lframe->forge = lforge->forge;
@@ -1037,7 +1039,7 @@ _lforge_read(lua_State *L)
{
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
- if(lforge->type != MOONY_UDATA_STASH)
+ if(lforge->lheader.type != MOONY_UDATA_STASH)
luaL_error(L, "not a stash object");
return _lstash_read(L);
@@ -1048,7 +1050,7 @@ _lforge__gc(lua_State *L)
{
lforge_t *lforge = luaL_checkudata(L, 1, "lforge");
- if(lforge->type == MOONY_UDATA_STASH)
+ if(lforge->lheader.type == MOONY_UDATA_STASH)
return _lstash__gc(L);
return 0;
diff --git a/api_forge.h b/api_forge.h
index 0238714..b5801e9 100644
--- a/api_forge.h
+++ b/api_forge.h
@@ -23,7 +23,7 @@
typedef struct _lforge_t lforge_t;
struct _lforge_t {
- moony_udata_t type;
+ lheader_t lheader;
LV2_Atom_Forge *forge;
int depth;
diff --git a/api_stash.c b/api_stash.c
index b30b625..cc95c4b 100644
--- a/api_stash.c
+++ b/api_stash.c
@@ -74,7 +74,7 @@ _lstash(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
- lstash_t *lstash = moony_newuserdata(L, moony, MOONY_UDATA_STASH);
+ lstash_t *lstash = moony_newuserdata(L, moony, MOONY_UDATA_STASH, false);
// initialize forge (URIDs)
memcpy(&lstash->forge, &moony->forge, sizeof(LV2_Atom_Forge));
@@ -82,9 +82,9 @@ _lstash(lua_State *L)
// initialize memory pool
atom_ser_t *ser = &lstash->ser;
ser->tlsf = moony->vm.tlsf;
- ser->size = 256;
- ser->buf = tlsf_malloc(moony->vm.tlsf, ser->size);
+ ser->size = 1024;
ser->offset = 0; // reset stash pointer
+ ser->buf = tlsf_malloc(moony->vm.tlsf, ser->size);
if(!ser->buf)
lua_pushnil(L); // memory allocation failed
diff --git a/axa.c b/axa.c
index ee0c66f..b4b4f44 100644
--- a/axa.c
+++ b/axa.c
@@ -94,11 +94,11 @@ _run(lua_State *L)
// push sequence / forge pair(s)
for(unsigned i=0; i<handle->max_val; i++)
{
- latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM, true);
latom->atom = (const LV2_Atom *)handle->event_in[i];
latom->body.raw = LV2_ATOM_BODY_CONST(latom->atom);
- lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lforge->depth = 0;
lforge->last.frames = 0;
lforge->forge = &handle->forge[i];
@@ -106,11 +106,11 @@ _run(lua_State *L)
// push control / notify pair
{
- latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM, true);
latom->atom = (const LV2_Atom *)handle->control;
latom->body.raw = LV2_ATOM_BODY_CONST(latom->atom);
- lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lforge->depth = 0;
lforge->last.frames = 0;
lforge->forge = &handle->moony.notify_forge;
diff --git a/caxca.c b/caxca.c
index 87d6cec..23e067c 100644
--- a/caxca.c
+++ b/caxca.c
@@ -99,11 +99,11 @@ _run(lua_State *L)
// push sequence / forge pair
{
- latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM, true);
latom->atom = (const LV2_Atom *)handle->event_in;
latom->body.raw = LV2_ATOM_BODY_CONST(latom->atom);
- lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lforge->depth = 0;
lforge->last.frames = 0;
lforge->forge = &handle->forge;
@@ -115,11 +115,11 @@ _run(lua_State *L)
// push control / notify pair
{
- latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM, true);
latom->atom = (const LV2_Atom *)handle->control;
latom->body.raw = LV2_ATOM_BODY_CONST(latom->atom);
- lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lforge->depth = 0;
lforge->last.frames = 0;
lforge->forge = &handle->moony.notify_forge;
diff --git a/cxc.c b/cxc.c
index fc87d49..9952858 100644
--- a/cxc.c
+++ b/cxc.c
@@ -92,11 +92,11 @@ _run(lua_State *L)
// push control / notify pair
{
- latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM, true);
latom->atom = (const LV2_Atom *)handle->control;
latom->body.raw = LV2_ATOM_BODY_CONST(latom->atom);
- lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lforge->depth = 0;
lforge->last.frames = 0;
lforge->forge = &handle->moony.notify_forge;
diff --git a/moony.h b/moony.h
index 2af95cc..8363dc9 100644
--- a/moony.h
+++ b/moony.h
@@ -155,9 +155,15 @@ typedef enum _moony_upclosure_t {
} moony_upclosure_t;
// from api_atom.c
+typedef struct _lheader_t lheader_t;
typedef struct _latom_driver_t latom_driver_t;
typedef struct _latom_driver_hash_t latom_driver_hash_t;
+struct _lheader_t {
+ moony_udata_t type;
+ bool cache;
+};
+
struct _latom_driver_hash_t {
LV2_URID type;
const latom_driver_t *driver;
@@ -280,7 +286,7 @@ void moony_open(moony_t *moony, lua_State *L, bool use_assert);
void moony_in(moony_t *moony, const LV2_Atom_Sequence *control, LV2_Atom_Sequence *notify);
void moony_out(moony_t *moony, LV2_Atom_Sequence *notify, uint32_t frames);
const void* extension_data(const char* uri);
-void *moony_newuserdata(lua_State *L, moony_t *moony, moony_udata_t type);
+void *moony_newuserdata(lua_State *L, moony_t *moony, moony_udata_t type, bool cache);
static inline void
moony_freeuserdata(moony_t *moony)
diff --git a/test_moony.c b/test_moony.c
index b49fbdc..92b3f9b 100644
--- a/test_moony.c
+++ b/test_moony.c
@@ -39,8 +39,8 @@ struct _handle_t {
LV2_Atom_Forge forge;
- uint8_t buf [8192] __attribute__((aligned(8)));
- uint8_t buf2 [8192] __attribute__((aligned(8)));
+ uint8_t buf [BUF_SIZE] __attribute__((aligned(8)));
+ uint8_t buf2 [BUF_SIZE] __attribute__((aligned(8)));
urid_t urids [MAX_URIDS];
LV2_URID urid;
@@ -66,7 +66,7 @@ _test(lua_State *L)
{
lua_pushvalue(L, 1); // producer
- lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lforge = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lforge->depth = 0;
lforge->last.frames = 0;
lforge->forge = forge;
@@ -84,11 +84,11 @@ _test(lua_State *L)
{
lua_pushvalue(L, 2); // consumer
- latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM);
+ latom_t *latom = moony_newuserdata(L, &handle->moony, MOONY_UDATA_ATOM, true);
latom->atom = (const LV2_Atom *)handle->buf;
latom->body.raw = LV2_ATOM_BODY_CONST(latom->atom);
- lforge_t *lframe = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE);
+ lforge_t *lframe = moony_newuserdata(L, &handle->moony, MOONY_UDATA_FORGE, true);
lframe->depth = 0;
lframe->last.frames = 0;
lframe->forge = forge;