Commit 19911587 authored by Hanspeter Portner's avatar Hanspeter Portner

merge seq:multiplex into seq:foreach.

parent 5d0df8db
Pipeline #4217409 passed with stages
in 5 minutes and 35 seconds
......@@ -1550,10 +1550,6 @@ moony_open(moony_t *moony, lua_State *L, bool use_assert)
lua_pushcclosure(L, _latom_seq_foreach, 1);
lua_rawseti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_SEQUENCE_FOREACH);
lua_pushlightuserdata(L, moony);
lua_pushcclosure(L, _latom_seq_multiplex, 1);
lua_rawseti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_SEQUENCE_MULTIPLEX);
lua_newtable(L);
lua_rawseti(L, LUA_REGISTRYINDEX, UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_COUNT + MOONY_UPCLOSURE_TUPLE_FOREACH);
lua_newtable(L);
......
......@@ -701,12 +701,11 @@ _latom_seq_multiplex_itr(lua_State *L)
return 1;
}
int
_latom_seq_multiplex(lua_State *L)
static int
_latom_seq_multiplex(lua_State *L, unsigned n)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
latom_t *latom = lua_touserdata(L, 1);
const unsigned n = lua_gettop(L);
for(unsigned i=1; i<=n; i++)
{
......@@ -761,6 +760,10 @@ _latom_seq_foreach_itr(lua_State *L)
int
_latom_seq_foreach(lua_State *L)
{
const unsigned n = lua_gettop(L);
if(n > 1) // multiplex if given any function arguments
return _latom_seq_multiplex(L, n);
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
latom_t *latom = lua_touserdata(L, 1);
......@@ -778,8 +781,7 @@ const latom_driver_t latom_sequence_driver = {
.__indexi = _latom_seq__indexi,
.__len = _latom_seq__len,
.__tostring = _latom_seq__tostring,
.foreach = UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_SEQUENCE_FOREACH,
.multiplex = UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_SEQUENCE_MULTIPLEX
.foreach = UDATA_OFFSET + MOONY_UDATA_COUNT + MOONY_CCLOSURE_SEQUENCE_FOREACH
};
static int
......@@ -1033,11 +1035,6 @@ _latom__index(lua_State *L)
lua_rawgeti(L, LUA_REGISTRYINDEX, driver->foreach);
return 1;
}
else if(driver->foreach && !strcmp(key, "multiplex"))
{
lua_rawgeti(L, LUA_REGISTRYINDEX, driver->multiplex);
return 1;
}
else if(driver->unpack && !strcmp(key, "unpack"))
{
lua_rawgeti(L, LUA_REGISTRYINDEX, driver->unpack);
......
......@@ -38,7 +38,6 @@ struct _latom_driver_t {
latom_driver_function_t value;
int unpack;
int foreach;
int multiplex;
};
struct _latom_t {
......@@ -137,8 +136,6 @@ _latom_seq_foreach_itr(lua_State *L);
int
_latom_vec_foreach_itr(lua_State *L);
int
_latom_seq_multiplex(lua_State *L);
int
_latom_seq_multiplex_itr(lua_State *L);
......
......@@ -147,7 +147,6 @@ typedef enum _moony_cclosure_t {
MOONY_CCLOSURE_VECTOR_FOREACH,
MOONY_CCLOSURE_OBJECT_FOREACH,
MOONY_CCLOSURE_SEQUENCE_FOREACH,
MOONY_CCLOSURE_SEQUENCE_MULTIPLEX,
MOONY_CCLOSURE_CLONE,
MOONY_CCLOSURE_WRITE,
......
......@@ -133,7 +133,7 @@ moony:bank-multiplex_atom-multiplex2
doap:license lic:Artistic-2.0 ;
state:state [
moony:code """function run(n, seq1, forge1, seq2, forge2)
for frames, atom in seq1:multiplex(seq2) do
for frames, atom in seq1:foreach(seq2) do
forge1:time(frames):atom(atom)
forge2:time(frames):atom(atom)
end
......@@ -145,7 +145,7 @@ moony:bank-multiplex_atom-multiplex4
doap:license lic:Artistic-2.0 ;
state:state [
moony:code """function run(n, seq1, forge1, seq2, forge2, seq3, forge3, seq4, forge4)
for frames, atom in seq1:multiplex(seq2, seq3, seq4) do
for frames, atom in seq1:foreach(seq2, seq3, seq4) do
forge1:time(frames):atom(atom)
forge2:time(frames):atom(atom)
forge3:time(frames):atom(atom)
......
......@@ -1608,7 +1608,7 @@ do
assert(#stash2 == 3)
local i = 0
for frames, atom, seq in stash1:multiplex(stash2) do
for frames, atom, seq in stash1:foreach(stash2) do
assert(frames == i)
assert(atom.type == Atom.Int)
assert(atom.body == i)
......
......@@ -48,8 +48,6 @@ var LuaHighlightRules = function() {
"typed|get|set|put|patch|remove|add|pop|"+
// moony common
"foreach|unpack|clone|stash|apply|register|"+
// moony sequence
"multiplex|"+
// moony stash
"write|read");
......
......@@ -192,7 +192,7 @@ a.button:hover {
}
.api-section {
border-bottom:10ex solid #666;
border-bottom:10ex solid #111;
}
.api-content {
......
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