diff --git a/lib/ParserLua.cpp b/lib/ParserLua.cpp index 5d085a966..1fba7dfc3 100644 --- a/lib/ParserLua.cpp +++ b/lib/ParserLua.cpp @@ -30,10 +30,14 @@ GINGA_END_DECLS GINGA_NAMESPACE_BEGIN -// TODO: -// make l_parse_children to avoid duplicated code -// remember to test if property exist before adding to document -// make maps<> to help parsing and avoid big if/case +/* TODO: + + - l_parse_media() is not dealing with labels + + - make l_parse_children to avoid duplicated code + remember to test if property exists before adding to document + make maps<> to help parsing and avoid big if/case statements + */ // declarations static int l_parse_context (lua_State *L); @@ -53,39 +57,39 @@ getEventStringAsEvent (string str, Context *parent) size_t at = str.find ('@'); if (at != str.npos) // presentation - { - id = str.substr (0, at); - evt = str.substr (at + 1, str.npos); - obj = parent->getChildById (id); + { + id = str.substr (0, at); + evt = str.substr (at + 1, str.npos); + obj = parent->getChildById (id); - // only lambda should have '@' as prefix? this seems strange - if (xstrcasecmp ("lambda", evt) == 0) - evt = "@lambda"; + // only lambda should have '@' as prefix? this seems strange + if (xstrcasecmp ("lambda", evt) == 0) + evt = "@lambda"; - return obj->getEvent (Event::PRESENTATION, evt); - } + return obj->getEvent (Event::PRESENTATION, evt); + } else if (str.find ('.') != str.npos) // attribution - { - at = str.find ('.'); - id = str.substr (0, at); - evt = str.substr (at + 1, str.npos); - obj = parent->getChildById (id); - return obj->getEvent (Event::ATTRIBUTION, evt); - } + { + at = str.find ('.'); + id = str.substr (0, at); + evt = str.substr (at + 1, str.npos); + obj = parent->getChildById (id); + return obj->getEvent (Event::ATTRIBUTION, evt); + } else // selection - { - at = str.find ('<'); - id = str.substr (0, at); - evt = str.substr (at + 1, str.npos); - evt.pop_back (); - obj = parent->getChildById (id); - return obj->getEvent (Event::SELECTION, evt); - } + { + at = str.find ('<'); + id = str.substr (0, at); + evt = str.substr (at + 1, str.npos); + evt.pop_back (); + obj = parent->getChildById (id); + return obj->getEvent (Event::SELECTION, evt); + } } -// Parsing functions. +/* Parsing functions. */ -// parse_context (doc, [parent], tab, path) +/* parse_context (doc, [parent], tab, path) */ static int l_parse_context (lua_State *L) { @@ -105,102 +109,102 @@ l_parse_context (lua_State *L) tag = luaL_checkstring (L, -1); if (!g_str_equal (tag, "context")) - { - lua_pushfstring (L, "unexpected tag: %s", tag); - lua_error (L); - } + { + lua_pushfstring (L, "unexpected tag: %s", tag); + lua_error (L); + } lua_rawgeti (L, 3, 2); id = luaL_checkstring (L, -1); if (parent == nullptr) // root - { - Context *root = doc->getRoot (); - ctx = root; - root->addAlias (string (id)); - parent = root; - } + { + Context *root = doc->getRoot (); + ctx = root; + root->addAlias (string (id)); + parent = root; + } else // non-root - { - ctx = new Context (id); - parent->addChild (ctx); - } + { + ctx = new Context (id); + parent->addChild (ctx); + } - lua_rawgeti (L, 3, 4); + lua_rawgeti (L, 3, 5); if (lua_isnil (L, -1) == 0) // children + { + lua_pushnil (L); + while (lua_next (L, -2) != 0) { - lua_pushnil (L); - while (lua_next (L, -2) != 0) - { - lua_rawgeti (L, -1, 1); - string child = luaL_checkstring (L, -1); - - if (xstrcasecmp (child, "context") == 0) - { - lua_pushcfunction (L, l_parse_context); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, ctx); - lua_pushvalue (L, -5); - lua_pushvalue (L, 4); - lua_call (L, 4, 0); - lua_pop (L, 2); - } - else if (xstrcasecmp (child, "switch") == 0) - { - lua_pushcfunction (L, l_parse_switch); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, ctx); - lua_pushvalue (L, -5); - lua_pushvalue (L, 4); - lua_call (L, 4, 0); - lua_pop (L, 2); - } - else if (xstrcasecmp (child, "media") == 0) - { - lua_pushcfunction (L, l_parse_media); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, ctx); - lua_pushvalue (L, -5); - lua_pushvalue (L, 4); - lua_call (L, 4, 0); - lua_pop (L, 2); - } - else - { - g_assert_not_reached (); // print error message first - } - } + lua_rawgeti (L, -1, 1); + string child = luaL_checkstring (L, -1); + + if (xstrcasecmp (child, "context") == 0) + { + lua_pushcfunction (L, l_parse_context); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, ctx); + lua_pushvalue (L, -5); + lua_pushvalue (L, 4); + lua_call (L, 4, 0); + lua_pop (L, 2); + } + else if (xstrcasecmp (child, "switch") == 0) + { + lua_pushcfunction (L, l_parse_switch); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, ctx); + lua_pushvalue (L, -5); + lua_pushvalue (L, 4); + lua_call (L, 4, 0); + lua_pop (L, 2); + } + else if (xstrcasecmp (child, "media") == 0) + { + lua_pushcfunction (L, l_parse_media); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, ctx); + lua_pushvalue (L, -5); + lua_pushvalue (L, 4); + lua_call (L, 4, 0); + lua_pop (L, 2); + } + else + { + g_assert_not_reached (); // print error message first + } } + } - lua_rawgeti (L, 3, 3); + lua_rawgeti (L, 3, 4); if (lua_isnil (L, -1) == 0) // ports + { + lua_pushnil (L); + while (lua_next (L, -2) != 0) { - lua_pushnil (L); - while (lua_next (L, -2) != 0) - { - lua_pushcfunction (L, l_parse_port); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, ctx); - lua_pushvalue (L, -4); - lua_call (L, 3, 0); - lua_pop (L, 1); - } + lua_pushcfunction (L, l_parse_port); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, ctx); + lua_pushvalue (L, -4); + lua_call (L, 3, 0); + lua_pop (L, 1); } + } - lua_rawgeti (L, 3, 5); + lua_rawgeti (L, 3, 6); if (lua_isnil (L, -1) == 0) // links + { + lua_pushnil (L); + while (lua_next (L, -2) != 0) { - lua_pushnil (L); - while (lua_next (L, -2) != 0) - { - lua_pushcfunction (L, l_parse_link); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, ctx); - lua_pushvalue (L, -4); - lua_call (L, 3, 0); - lua_pop (L, 1); - } + lua_pushcfunction (L, l_parse_link); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, ctx); + lua_pushvalue (L, -4); + lua_call (L, 3, 0); + lua_pop (L, 1); } + } return 0; } @@ -226,94 +230,94 @@ l_parse_switch (lua_State *L) tag = luaL_checkstring (L, -1); if (!g_str_equal (tag, "switch")) - { - lua_pushfstring (L, "unexpected tag: %s", tag); - lua_error (L); - } + { + lua_pushfstring (L, "unexpected tag: %s", tag); + lua_error (L); + } lua_rawgeti (L, 3, 2); id = luaL_checkstring (L, -1); if (parent == NULL) // error - { - lua_pushfstring (L, "parent missing: %s", id); - lua_error (L); - } + { + lua_pushfstring (L, "parent missing: %s", id); + lua_error (L); + } swtch = new Switch (id); parent->addChild (swtch); lua_rawgeti (L, 3, 3); if (lua_isnil (L, -1) == 0) // children + { + lua_pushnil (L); + while (lua_next (L, -2) != 0) { - lua_pushnil (L); - while (lua_next (L, -2) != 0) - { - lua_rawgeti (L, -1, 1); - string child = luaL_checkstring (L, -1); - - if (xstrcasecmp (child, "context") == 0) - { - lua_pushcfunction (L, l_parse_context); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, swtch); - lua_pushvalue (L, -5); - lua_pushvalue (L, 4); - lua_call (L, 4, 0); - lua_pop (L, 2); - } - else if (xstrcasecmp (child, "switch") == 0) - { - lua_pushcfunction (L, l_parse_switch); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, swtch); - lua_pushvalue (L, -5); - lua_pushvalue (L, 4); - lua_call (L, 4, 0); - lua_pop (L, 2); - } - else if (xstrcasecmp (child, "media") == 0) - { - lua_pushcfunction (L, l_parse_media); - lua_pushlightuserdata (L, doc); - lua_pushlightuserdata (L, swtch); - lua_pushvalue (L, -5); - lua_pushvalue (L, 4); - lua_call (L, 4, 0); - lua_pop (L, 2); - } - else - { - g_assert_not_reached (); // print error message first - } - } + lua_rawgeti (L, -1, 1); + string child = luaL_checkstring (L, -1); + + if (xstrcasecmp (child, "context") == 0) + { + lua_pushcfunction (L, l_parse_context); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, swtch); + lua_pushvalue (L, -5); + lua_pushvalue (L, 4); + lua_call (L, 4, 0); + lua_pop (L, 2); + } + else if (xstrcasecmp (child, "switch") == 0) + { + lua_pushcfunction (L, l_parse_switch); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, swtch); + lua_pushvalue (L, -5); + lua_pushvalue (L, 4); + lua_call (L, 4, 0); + lua_pop (L, 2); + } + else if (xstrcasecmp (child, "media") == 0) + { + lua_pushcfunction (L, l_parse_media); + lua_pushlightuserdata (L, doc); + lua_pushlightuserdata (L, swtch); + lua_pushvalue (L, -5); + lua_pushvalue (L, 4); + lua_call (L, 4, 0); + lua_pop (L, 2); + } + else + { + g_assert_not_reached (); // print error message first + } } + } lua_rawgeti (L, 3, 4); if (lua_isnil (L, -1) == 0) // rules + { + lua_pushnil (L); + while (lua_next (L, -2) != 0) { - lua_pushnil (L); - while (lua_next (L, -2) != 0) - { - lua_rawgeti (L, 10, 1); - const string id_media = string (luaL_checkstring (L, -1)); - Object *obj = swtch->getChildById (id_media); + lua_rawgeti (L, 10, 1); + const string id_media = string (luaL_checkstring (L, -1)); + Object *obj = swtch->getChildById (id_media); - lua_rawgeti (L, 10, 2); - luaL_checktype (L, -1, LUA_TTABLE); + lua_rawgeti (L, 10, 2); + luaL_checktype (L, -1, LUA_TTABLE); - Predicate *predicate = new Predicate (Predicate::CONJUNCTION); - lua_pushcfunction (L, l_parse_predicate); - lua_pushlightuserdata (L, predicate); - lua_pushvalue (L, -3); - lua_call (L, 2, 0); + Predicate *predicate = new Predicate (Predicate::CONJUNCTION); + lua_pushcfunction (L, l_parse_predicate); + lua_pushlightuserdata (L, predicate); + lua_pushvalue (L, -3); + lua_call (L, 2, 0); - Predicate *pred = predicate->getChildren ()->front (); - swtch->addRule (obj, pred); + Predicate *pred = predicate->getChildren ()->front (); + swtch->addRule (obj, pred); - lua_pop (L, 3); - } + lua_pop (L, 3); } + } return 0; } @@ -364,191 +368,180 @@ l_parse_media (lua_State *L) tag = luaL_checkstring (L, -1); if (!g_str_equal (tag, "media")) - { - lua_pushfstring (L, "unexpected tag: %s", tag); - lua_error (L); - } + { + lua_pushfstring (L, "unexpected tag: %s", tag); + lua_error (L); + } lua_rawgeti (L, 3, 2); id = luaL_checkstring (L, -1); media = new Media (id); if (parent == NULL) // error - { - lua_pushfstring (L, "parent missing: %s", id); - lua_error (L); - } + { + lua_pushfstring (L, "parent missing: %s", id); + lua_error (L); + } lua_rawgeti (L, 3, 3); if (lua_isnil (L, -1) == 0) // have property list + { + lua_pushnil (L); + while (lua_next (L, 7) != 0) { - lua_pushnil (L); - while (lua_next (L, 7) != 0) + name = lua_tolstring (L, -2, 0); + value = lua_tolstring (L, -1, 0); + + if (xstrcasecmp ("src", name) == 0) + { + name = "uri"; + src = string (value); + + // resolve relative dir + if (src != "" && !xpathisuri (src) && !xpathisabs (src)) + { + path = luaL_checkstring (L, 4); + string dir = xpathdirname (path); + src = xurifromsrc (src, dir); + value = src.c_str (); + } + } + else if ((xstrcasecmp ("transIn", name) == 0) + || (xstrcasecmp ("transOut", name) == 0)) + { + string aux; + + lua_getfield (L, 9, "type"); + if (lua_isnil (L, -1) == 0) { - name = lua_tolstring (L, -2, 0); - value = lua_tolstring (L, -1, 0); - - if (xstrcasecmp ("src", name) == 0) - { - name = "uri"; - src = string (value); - - // resolve relative dir - if (src != "" && !xpathisuri (src) && !xpathisabs (src)) - { - path = luaL_checkstring (L, 4); - string dir = xpathdirname (path); - src = xurifromsrc (src, dir); - value = src.c_str (); - } - } - else if ((xstrcasecmp ("transIn", name) == 0) - || (xstrcasecmp ("transOut", name) == 0)) - { - string aux; - - lua_getfield (L, 9, "type"); - if (lua_isnil (L, -1) == 0) - { - aux = lua_tolstring (L, -1, 0); - str = "{type='" + aux + "',"; - } - else - { - g_assert_not_reached (); - } - - lua_getfield (L, 9, "subtype"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = ""; - str += "subtype='" + aux + "',"; - - lua_getfield (L, 9, "dur"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "0"; - str += "dur='" + aux + "',"; - - lua_getfield (L, 9, "startProgress"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "0"; - str += "startProgress='" + aux + "',"; - - lua_getfield (L, 9, "endProgress"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "0"; - str += "endProgress='" + aux + "',"; - - lua_getfield (L, 9, "direction"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "forward"; - str += "direction='" + aux + "',"; - - lua_getfield (L, 9, "fadeColor"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = ""; - str += "fadeColor='" + aux + "',"; - - lua_getfield (L, 9, "horzRepeat"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "0"; - str += "horzRepeat='" + aux + "',"; - - lua_getfield (L, 9, "vertRepeat"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "0"; - str += "vertRepeat='" + aux + "',"; - - lua_getfield (L, 9, "borderWidth"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = "0"; - str += "borderWidth='" + aux + "',"; - - lua_getfield (L, 9, "borderColor"); - if (lua_isnil (L, -1) == 0) - aux = lua_tolstring (L, -1, 0); - else - aux = ""; - str += "borderColor='" + aux + "',"; - - str += "}"; - value = str.c_str (); - lua_pop (L, 11); - } - - media->addAttributionEvent (name); - media->setProperty (name, value); - lua_pop (L, 1); + aux = lua_tolstring (L, -1, 0); + str = "{type='" + aux + "',"; } + else + { + g_assert_not_reached (); + } + + lua_getfield (L, 9, "subtype"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = ""; + str += "subtype='" + aux + "',"; + + lua_getfield (L, 9, "dur"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "0"; + str += "dur='" + aux + "',"; + + lua_getfield (L, 9, "startProgress"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "0"; + str += "startProgress='" + aux + "',"; + + lua_getfield (L, 9, "endProgress"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "0"; + str += "endProgress='" + aux + "',"; + + lua_getfield (L, 9, "direction"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "forward"; + str += "direction='" + aux + "',"; + + lua_getfield (L, 9, "fadeColor"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = ""; + str += "fadeColor='" + aux + "',"; + + lua_getfield (L, 9, "horzRepeat"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "0"; + str += "horzRepeat='" + aux + "',"; + + lua_getfield (L, 9, "vertRepeat"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "0"; + str += "vertRepeat='" + aux + "',"; + + lua_getfield (L, 9, "borderWidth"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = "0"; + str += "borderWidth='" + aux + "',"; + + lua_getfield (L, 9, "borderColor"); + if (lua_isnil (L, -1) == 0) + aux = lua_tolstring (L, -1, 0); + else + aux = ""; + str += "borderColor='" + aux + "',"; + + str += "}"; + value = str.c_str (); + lua_pop (L, 11); + } + + media->addAttributionEvent (name); + media->setProperty (name, value); + lua_pop (L, 1); } + } lua_pop (L, 3); lua_rawgeti (L, 3, 4); if (lua_isnil (L, -1) == 0) // have area list + { + lua_pushnil (L); + while (lua_next (L, 5) != 0) { - lua_pushnil (L); - while (lua_next (L, 5) != 0) - { - name = lua_tolstring (L, -2, nullptr); - - lua_getfield (L, -1, "label"); - if (lua_isnil (L, -1) == 0) - { - string label = lua_tolstring (L, -1, nullptr); - media->addPresentationEvent (name, label); - - lua_pop (L, 1); - break; - } - else - { - lua_pop (L, 1); - lua_rawgeti (L, -1, 1); - value = lua_tolstring (L, -1, nullptr); - - begin = 0; - if ((value != NULL) - && (unlikely (!ginga::try_parse_time (value, &begin)))) - { - lua_pushfstring (L, "bad attr: %s", value); - lua_error (L); - } - - lua_pop (L, 1); - lua_rawgeti (L, -1, 2); - value = lua_tolstring (L, -1, 0); - - end = GINGA_TIME_NONE; - if ((value != NULL) - && (unlikely (!ginga::try_parse_time (value, &end)))) - { - lua_pushfstring (L, "bad attr: %s", value); - lua_error (L); - } - - media->addPresentationEvent (name, begin, end); - lua_pop (L, 2); - } - } + lua_rawgeti (L, -1, 1); + name = lua_tolstring (L, -1, nullptr); + + lua_pop (L, 1); + lua_rawgeti (L, -1, 2); + value = lua_tolstring (L, -1, nullptr); + + begin = 0; + if ((value != NULL) + && (unlikely (!ginga::try_parse_time (value, &begin)))) + { + lua_pushfstring (L, "bad attr: %s", value); + lua_error (L); + } + + lua_pop (L, 1); + lua_rawgeti (L, -1, 3); + value = lua_tolstring (L, -1, 0); + + end = GINGA_TIME_NONE; + if ((value != NULL) + && (unlikely (!ginga::try_parse_time (value, &end)))) + { + lua_pushfstring (L, "bad attr: %s", value); + lua_error (L); + } + + media->addPresentationEvent (name, begin, end); + lua_pop (L, 2); } + } parent->addChild (media); return 0; @@ -573,91 +566,91 @@ l_parse_link (lua_State *L) luaL_checktype (L, 4, LUA_TTABLE); lua_pushnil (L); while (lua_next (L, 4) != 0) - { - Action act; + { + Action act; - lua_rawgeti (L, 6, 1); // transition - string transition = luaL_checkstring (L, -1); + lua_rawgeti (L, 6, 1); // transition + string transition = luaL_checkstring (L, -1); - if (xstrcasecmp (transition, "set") == 0) - transition = "start"; + if (xstrcasecmp (transition, "set") == 0) + transition = "start"; - act.transition = Event::getStringAsTransition (transition); + act.transition = Event::getStringAsTransition (transition); - lua_rawgeti (L, 6, 2); // event - string event = luaL_checkstring (L, -1); - act.event = getEventStringAsEvent (event, parent); + lua_rawgeti (L, 6, 2); // event + string event = luaL_checkstring (L, -1); + act.event = getEventStringAsEvent (event, parent); - lua_rawgeti (L, 6, 3); // predicate - act.predicate = nullptr; - if (!lua_isnil (L, -1)) - { - luaL_checktype (L, -1, LUA_TTABLE); - - Predicate *predicate = new Predicate (Predicate::CONJUNCTION); - lua_pushcfunction (L, l_parse_predicate); - lua_pushlightuserdata (L, predicate); - lua_pushvalue (L, -3); - lua_call (L, 2, 0); + lua_rawgeti (L, 6, 3); // predicate + act.predicate = nullptr; + if (!lua_isnil (L, -1)) + { + luaL_checktype (L, -1, LUA_TTABLE); - Predicate *pred = predicate->getChildren ()->front (); - act.predicate = pred; - } + Predicate *predicate = new Predicate (Predicate::CONJUNCTION); + lua_pushcfunction (L, l_parse_predicate); + lua_pushlightuserdata (L, predicate); + lua_pushvalue (L, -3); + lua_call (L, 2, 0); - conditions.push_back (act); - lua_pop (L, 4); + Predicate *pred = predicate->getChildren ()->front (); + act.predicate = pred; } + conditions.push_back (act); + lua_pop (L, 4); + } + lua_rawgeti (L, 3, 2); // action table luaL_checktype (L, 5, LUA_TTABLE); lua_pushnil (L); while (lua_next (L, 5) != 0) - { - Action act; + { + Action act; - lua_rawgeti (L, 7, 1); // transition - string transition = luaL_checkstring (L, -1); + lua_rawgeti (L, 7, 1); // transition + string transition = luaL_checkstring (L, -1); - if (xstrcasecmp (transition, "set") == 0) - transition = "start"; + if (xstrcasecmp (transition, "set") == 0) + transition = "start"; - act.transition = Event::getStringAsTransition (transition); + act.transition = Event::getStringAsTransition (transition); - lua_rawgeti (L, 7, 2); // event - string event = luaL_checkstring (L, -1); - act.event = getEventStringAsEvent (event, parent); + lua_rawgeti (L, 7, 2); // event + string event = luaL_checkstring (L, -1); + act.event = getEventStringAsEvent (event, parent); - lua_rawgeti (L, 7, 3); // value - if (!lua_isnil (L, -1)) - act.value = luaL_checkstring (L, -1); + lua_rawgeti (L, 7, 3); // value + if (!lua_isnil (L, -1)) + act.value = luaL_checkstring (L, -1); - lua_rawgeti (L, 7, 4); // parameter list + lua_rawgeti (L, 7, 4); // parameter list + if (!lua_isnil (L, -1)) + { + luaL_checktype (L, 11, LUA_TTABLE); + lua_getfield (L, 11, "delay"); if (!lua_isnil (L, -1)) - { - luaL_checktype (L, 11, LUA_TTABLE); - lua_getfield (L, 11, "delay"); - if (!lua_isnil (L, -1)) - { - string str = luaL_checkstring (L, -1); - act.delay = str; - } - - lua_getfield (L, 11, "duration"); - if (!lua_isnil (L, -1)) - { - string str = luaL_checkstring (L, -1); - act.duration = str; - } - - lua_pop (L, 2); - } + { + string str = luaL_checkstring (L, -1); + act.delay = str; + } - act.predicate = nullptr; + lua_getfield (L, 11, "duration"); + if (!lua_isnil (L, -1)) + { + string str = luaL_checkstring (L, -1); + act.duration = str; + } - actions.push_back (act); - lua_pop (L, 5); + lua_pop (L, 2); } + act.predicate = nullptr; + + actions.push_back (act); + lua_pop (L, 5); + } + parent->addLink (conditions, actions); return 0; } @@ -677,76 +670,76 @@ l_parse_predicate (lua_State *L) lua_rawgeti (L, 2, 1); if (lua_isboolean (L, -1) == 1) - { - if (lua_toboolean (L, -1) == 1) - type = Predicate::VERUM; - else - type = Predicate::FALSUM; - } + { + if (lua_toboolean (L, -1) == 1) + type = Predicate::VERUM; + else + type = Predicate::FALSUM; + } else - { - str = luaL_checkstring (L, -1); - - if (xstrcasecmp (str, "not") == 0) - type = Predicate::NEGATION; - else if (xstrcasecmp (str, "and") == 0) - type = Predicate::CONJUNCTION; - else if (xstrcasecmp (str, "or") == 0) - type = Predicate::DISJUNCTION; - else - type = Predicate::ATOM; - } + { + str = luaL_checkstring (L, -1); + + if (xstrcasecmp (str, "not") == 0) + type = Predicate::NEGATION; + else if (xstrcasecmp (str, "and") == 0) + type = Predicate::CONJUNCTION; + else if (xstrcasecmp (str, "or") == 0) + type = Predicate::DISJUNCTION; + else + type = Predicate::ATOM; + } it = new Predicate (type); switch (type) + { + case Predicate::ATOM: { - case Predicate::ATOM: - { - string left = str; - - lua_rawgeti (L, 2, 2); - str = luaL_checkstring (L, -1); - - lua_rawgeti (L, 2, 3); - string right = luaL_checkstring (L, -1); - - if (xstrcasecmp (str, "==") == 0) - test = Predicate::EQ; - else if (xstrcasecmp (str, "!=") == 0) - test = Predicate::NE; - else if (xstrcasecmp (str, "<") == 0) - test = Predicate::LT; - else if (xstrcasecmp (str, "<=") == 0) - test = Predicate::LE; - else if (xstrcasecmp (str, ">") == 0) - test = Predicate::GT; - else if (xstrcasecmp (str, ">=") == 0) - test = Predicate::GE; - else - g_assert_not_reached (); + string left = str; - it->setTest (left, test, right); - break; - } - case Predicate::FALSUM: - case Predicate::VERUM: - break; - case Predicate::CONJUNCTION: - case Predicate::DISJUNCTION: - lua_pushcfunction (L, l_parse_predicate); // children - lua_pushlightuserdata (L, it); - lua_rawgeti (L, 2, 3); - lua_call (L, 2, 0); - case Predicate::NEGATION: // fall through - lua_pushcfunction (L, l_parse_predicate); - lua_pushlightuserdata (L, it); lua_rawgeti (L, 2, 2); - lua_call (L, 2, 0); + str = luaL_checkstring (L, -1); + + lua_rawgeti (L, 2, 3); + string right = luaL_checkstring (L, -1); + + if (xstrcasecmp (str, "==") == 0) + test = Predicate::EQ; + else if (xstrcasecmp (str, "!=") == 0) + test = Predicate::NE; + else if (xstrcasecmp (str, "<") == 0) + test = Predicate::LT; + else if (xstrcasecmp (str, "<=") == 0) + test = Predicate::LE; + else if (xstrcasecmp (str, ">") == 0) + test = Predicate::GT; + else if (xstrcasecmp (str, ">=") == 0) + test = Predicate::GE; + else + g_assert_not_reached (); + + it->setTest (left, test, right); break; - default: - g_assert_not_reached (); } + case Predicate::FALSUM: + case Predicate::VERUM: + break; + case Predicate::CONJUNCTION: + case Predicate::DISJUNCTION: + lua_pushcfunction (L, l_parse_predicate); // children + lua_pushlightuserdata (L, it); + lua_rawgeti (L, 2, 3); + lua_call (L, 2, 0); + case Predicate::NEGATION: // fall through + lua_pushcfunction (L, l_parse_predicate); + lua_pushlightuserdata (L, it); + lua_rawgeti (L, 2, 2); + lua_call (L, 2, 0); + break; + default: + g_assert_not_reached (); + } parent->addChild (it); return 0; @@ -767,11 +760,11 @@ process (lua_State *L, const string &path, string *errmsg) lua_pushvalue (L, 1); lua_pushstring (L, path.c_str ()); if (unlikely (lua_pcall (L, 4, 0, 0) != LUA_OK)) - { - delete doc; - tryset (errmsg, g_strdup (luaL_checkstring (L, -1))); - return nullptr; - } + { + delete doc; + tryset (errmsg, g_strdup (luaL_checkstring (L, -1))); + return nullptr; + } return doc; } @@ -803,14 +796,14 @@ ParserLua::parseBuffer (const void *buf, size_t size, string *errmsg) doc = nullptr; err = luaL_dostring (L, str); if (unlikely (err != LUA_OK)) - { - tryset (errmsg, g_strdup (luaL_checkstring (L, -1))); - goto done; - } + { + tryset (errmsg, g_strdup (luaL_checkstring (L, -1))); + goto done; + } doc = process (L, path, errmsg); -done: + done: g_free (str); lua_close (L); return doc; @@ -836,14 +829,14 @@ ParserLua::parseFile (const string &path, string *errmsg) doc = nullptr; err = luaL_dofile (L, path.c_str ()); if (unlikely (err != LUA_OK)) - { - tryset (errmsg, g_strdup (luaL_checkstring (L, -1))); - goto done; - } + { + tryset (errmsg, g_strdup (luaL_checkstring (L, -1))); + goto done; + } doc = process (L, path, errmsg); -done: + done: lua_close (L); return doc; } diff --git a/tests-ncl/test-ltab-1.lua b/tests-ncl/test-ltab-1.lua index e5a32b54e..365881685 100644 --- a/tests-ncl/test-ltab-1.lua +++ b/tests-ncl/test-ltab-1.lua @@ -1,11 +1,13 @@ ncl = { 'context', 'ncl', + -- list of properties + {}, -- list of ports {'m2@lambda'}, -- list of children { - {'media', 'm1', {src = 'samples/clock.ogv'}, {a1 = {'3s'}}}, + {'media', 'm1', {src = 'samples/clock.ogv'}, {{'a1', '3s'}}}, {'media', 'm2', {src = 'samples/gnu.png'}} }, -- list of links diff --git a/tests-ncl/test-ltab-2.lua b/tests-ncl/test-ltab-2.lua index ed0263072..4aa0d9708 100644 --- a/tests-ncl/test-ltab-2.lua +++ b/tests-ncl/test-ltab-2.lua @@ -1,11 +1,13 @@ ncl = { 'context', 'ncl', + -- list of properties + {}, -- list of ports {'m1@lambda'}, -- list of children { - {'media', 'm1', {src = 'samples/clock.ogv'}, {a1 = {'3s'}}}, + {'media', 'm1', {src = 'samples/clock.ogv'}, {{'a1', '3s'}}}, {'media', 'm2', {src = 'samples/gnu.png'}} }, -- list of links diff --git a/tests-ncl/test-ltab-3.lua b/tests-ncl/test-ltab-3.lua index 3913d3c3f..d3529a4d8 100644 --- a/tests-ncl/test-ltab-3.lua +++ b/tests-ncl/test-ltab-3.lua @@ -1,6 +1,8 @@ ncl = { 'context', 'ncl', + -- list of properties + {}, -- list of ports {'time@lambda', 's1@lambda'}, -- list of children @@ -8,7 +10,7 @@ ncl = { {'media', 'settings', {type = 'application/x-ginga-settings', var = 'm1'} }, - {'media', 'time', nil, {a1 = {'3s'}}}, + {'media', 'time', nil, {{'a1', '3s'}}}, { 'switch', 's1', diff --git a/tests-ncl/test-ltab-4.lua b/tests-ncl/test-ltab-4.lua index 3130192e9..c84c09db5 100644 --- a/tests-ncl/test-ltab-4.lua +++ b/tests-ncl/test-ltab-4.lua @@ -1,6 +1,8 @@ ncl = { 'context', 'ncl', + -- list of properties + {}, -- list of ports {'time@lambda', 'm1@lambda'}, -- list of children diff --git a/tests/test-ParserLua-parseBuffer.cpp b/tests/test-ParserLua-parseBuffer.cpp index 8963353c2..b2e806298 100644 --- a/tests/test-ParserLua-parseBuffer.cpp +++ b/tests/test-ParserLua-parseBuffer.cpp @@ -56,10 +56,10 @@ main (void) Document *doc; PASS (&doc, "Context check", "ncl =\ -{'context', 'ncl',\n \ +{'context', 'ncl', {},\n \ {'m2@lambda'},\n \ {\n \ - {'context', 'c1', nil,\n \ + {'context', 'c1', {}, nil,\n \ {{'media', 'm1'}}},\n \ {'media', 'm2'}\n \ }\n \ @@ -99,12 +99,12 @@ return ncl"); Document *doc; PASS (&doc, "Switch check", "ncl =\ -{'context', 'ncl', nil,\n \ +{'context', 'ncl', {}, nil,\n \ {\n \ {'switch', 's1',\n \ {\n \ {'media', 'm1'},\n \ - {'context', 'c1'},\n \ + {'context', 'c1', {}},\n \ {'switch', 's2'}\n \ }\n \ },\n \ @@ -157,7 +157,7 @@ return ncl"); Document *doc; PASS (&doc, "Media check", "ncl =\ -{'context', 'ncl', nil,\n \ +{'context', 'ncl', {}, nil,\n \ {\n \ {'media', 'm1',\n \ {src='path/to/file.txt',\n \ @@ -165,11 +165,11 @@ return ncl"); dur='1s'},\n \ transOut={type='barWipe',\n \ dur='1s'}\n \ - }\n \ + },\n \ },\n \ {'media', 'm2', nil,\n \ - {a1={'5s', '8s'},\n \ - a2={'1s', nil}}}\n \ + {{'a1', '5s', '8s'},\n \ + {'a2', '1s', nil}}}\n \ }\n \ }\n \ return ncl"); @@ -206,7 +206,7 @@ return ncl"); Document *doc; PASS (&doc, "Link check", "ncl = \ -{'context', 'ncl', nil,\n \ +{'context', 'ncl', {}, nil,\n \ {\n \ {'media', 'm1'},\n \ },\n \ @@ -242,7 +242,7 @@ return ncl"); Document *doc; PASS (&doc, "Predicate check", "ncl = \ -{'context', 'ncl', nil,\n \ +{'context', 'ncl', {}, nil,\n \ {\n \ {'media', 'm1'},\n \ },\n \ @@ -285,7 +285,7 @@ return ncl"); Document *doc; PASS (&doc, "Switch rule check", "ncl =\ -{'context', 'ncl', nil,\n \ +{'context', 'ncl', {}, nil,\n \ {\n \ {'switch', 's1',\n \ {{'media', 'm1'}},\n \