]> git.sesse.net Git - nageru/blobdiff - nageru/theme.cpp
Convert channel_signal() and supports_set_wb() to imperative versions.
[nageru] / nageru / theme.cpp
index b53c65bc3434f61aae29904c242254893a672d75..7c3b366e49fafa46514281f2137fb940b4f28cd1 100644 (file)
@@ -1247,6 +1247,34 @@ int Nageru_set_num_channels(lua_State *L)
        return 0;
 }
 
+int Nageru_set_channel_signal(lua_State *L)
+{
+       // NOTE: m is already locked.
+       Theme *theme = get_theme_updata(L);
+       if (theme->startup_finished) {
+               luaL_error(L, "set_channel_signal() can only be called at startup.");
+       }
+       unsigned channel = luaL_checknumber(L, 1);
+       int signal = luaL_checknumber(L, 2);
+       theme->channel_signals[channel] = signal;
+       lua_pop(L, 2);
+       return 0;
+}
+
+int Nageru_set_supports_wb(lua_State *L)
+{
+       // NOTE: m is already locked.
+       Theme *theme = get_theme_updata(L);
+       if (theme->startup_finished) {
+               luaL_error(L, "set_supports_wb() can only be called at startup.");
+       }
+       unsigned channel = luaL_checknumber(L, 1);
+       bool supports_wb = checkbool(L, 2);
+       theme->channel_supports_wb[channel] = supports_wb;
+       lua_pop(L, 2);
+       return 0;
+}
+
 Theme::Theme(const string &filename, const vector<string> &search_dirs, ResourcePool *resource_pool, unsigned num_cards)
        : resource_pool(resource_pool), num_cards(num_cards), signal_to_card_mapping(global_flags.default_stream_mapping)
 {
@@ -1388,6 +1416,8 @@ void Theme::register_globals()
        const luaL_Reg Nageru_funcs[] = {
                { "set_channel_name", Nageru_set_channel_name },
                { "set_num_channels", Nageru_set_num_channels },
+               { "set_channel_signal", Nageru_set_channel_signal },
+               { "set_supports_wb", Nageru_set_supports_wb },
                { NULL, NULL }
        };
        lua_pushlightuserdata(L, this);
@@ -1552,9 +1582,19 @@ int Theme::get_channel_signal(unsigned channel)
 {
        lock_guard<mutex> lock(m);
        lua_getglobal(L, "channel_signal");
+       if (lua_isnil(L, -1)) {
+               lua_pop(L, 1);
+               if (channel_signals.count(channel)) {
+                       return channel_signals[channel];
+               } else {
+                       return -1;
+               }
+       }
+
        lua_pushnumber(L, channel);
        if (lua_pcall(L, 1, 1, 0) != 0) {
                fprintf(stderr, "error running function `channel_signal': %s\n", lua_tostring(L, -1));
+               fprintf(stderr, "Try Nageru.set_channel_signal(channel, signal) at the start of the script instead.\n");
                abort();
        }
 
@@ -1590,9 +1630,19 @@ bool Theme::get_supports_set_wb(unsigned channel)
 {
        lock_guard<mutex> lock(m);
        lua_getglobal(L, "supports_set_wb");
+       if (lua_isnil(L, -1)) {
+               lua_pop(L, 1);
+               if (channel_supports_wb.count(channel)) {
+                       return channel_supports_wb[channel];
+               } else {
+                       return false;
+               }
+       }
+
        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));
+               fprintf(stderr, "Try Nageru.set_supports_wb(channel, bool) at the start of the script instead.\n");
                abort();
        }