Skip to content

Commit

Permalink
Add table for default value to select first available.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Feb 22, 2025
1 parent 0c77e3f commit e26392e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions radio/src/lua/lua_widget_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,39 @@ void LuaWidgetFactory::translateOptions(ZoneOption * options)

static int switchValue()
{
int v;
if (lua_type(lsWidgets, -1) == LUA_TSTRING) {
int v = SWSRC_INVERT;
if (lua_istable(lsWidgets, -1)) {
// Find first available
int t = lua_gettop(lsWidgets);
for (lua_pushnil(lsWidgets); v == SWSRC_INVERT && lua_next(lsWidgets, -2); lua_pop(lsWidgets, 1)) {
v = getSwitchIndex(luaL_checkstring(lsWidgets, -1), false);
}
lua_settop(lsWidgets, t);
} else if (lua_type(lsWidgets, -1) == LUA_TSTRING) {
v = getSwitchIndex(lua_tostring(lsWidgets, -1), true);
if (v == SWSRC_INVERT) v = SWSRC_NONE;
} else {
v = luaL_checkinteger(lsWidgets, -1);
}
if (v == SWSRC_INVERT) v = SWSRC_NONE;
return v;
}

static int sourceValue()
{
int v;
if (lua_type(lsWidgets, -1) == LUA_TSTRING) {
int v = -1;
if (lua_istable(lsWidgets, -1)) {
// Find first available
int t = lua_gettop(lsWidgets);
for (lua_pushnil(lsWidgets); v < 0 && lua_next(lsWidgets, -2); lua_pop(lsWidgets, 1)) {
v = getSourceIndex(luaL_checkstring(lsWidgets, -1), false);
}
lua_settop(lsWidgets, t);
} else if (lua_type(lsWidgets, -1) == LUA_TSTRING) {
v = getSourceIndex(lua_tostring(lsWidgets, -1), true);
if (v == -1) v = MIXSRC_NONE;
} else {
v = luaL_checkunsigned(lsWidgets, -1);
}
if (v == -1) v = MIXSRC_NONE;
return v;
}

Expand Down

0 comments on commit e26392e

Please sign in to comment.