+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "channel_name");
+ lua_pushnumber(L, channel);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `channel_nam': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ std::string ret = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return ret;
+}
+
+bool Theme::get_supports_set_wb(unsigned channel)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "supports_set_wb");
+ lua_pushnumber(L, channel);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `supports_set_wb': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ bool ret = checkbool(L, -1);
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return ret;
+}
+
+void Theme::set_wb(unsigned channel, double r, double g, double b)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "set_wb");
+ lua_pushnumber(L, channel);
+ lua_pushnumber(L, r);
+ lua_pushnumber(L, g);
+ lua_pushnumber(L, b);
+ if (lua_pcall(L, 4, 0, 0) != 0) {
+ fprintf(stderr, "error running function `set_wb': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ assert(lua_gettop(L) == 0);
+}
+
+std::vector<std::string> Theme::get_transition_names(float t)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "get_transitions");
+ lua_pushnumber(L, t);
+ if (lua_pcall(L, 1, 1, 0) != 0) {
+ fprintf(stderr, "error running function `get_transitions': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+
+ std::vector<std::string> ret;
+ lua_pushnil(L);
+ while (lua_next(L, -2) != 0) {
+ ret.push_back(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+ assert(lua_gettop(L) == 0);
+ return ret;
+}
+
+int Theme::map_signal(int signal_num)
+{
+ if (signal_num >= int(num_cards)) {
+ if (signals_warned_about.insert(signal_num).second) {
+ fprintf(stderr, "WARNING: Theme asked for input %d, but we only have %u card(s).\n", signal_num, num_cards);
+ fprintf(stderr, "Mapping to card %d instead.\n", signal_num % num_cards);
+ }
+ signal_num %= num_cards;
+ }
+ return signal_num;
+}
+
+void Theme::transition_clicked(int transition_num, float t)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "transition_clicked");
+ lua_pushnumber(L, transition_num);
+ lua_pushnumber(L, t);
+
+ if (lua_pcall(L, 2, 0, 0) != 0) {
+ fprintf(stderr, "error running function `transition_clicked': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+ assert(lua_gettop(L) == 0);
+}
+
+void Theme::channel_clicked(int preview_num)
+{
+ unique_lock<mutex> lock(m);
+ lua_getglobal(L, "channel_clicked");
+ lua_pushnumber(L, preview_num);
+
+ if (lua_pcall(L, 1, 0, 0) != 0) {
+ fprintf(stderr, "error running function `channel_clicked': %s\n", lua_tostring(L, -1));
+ exit(1);
+ }
+ assert(lua_gettop(L) == 0);