]> git.sesse.net Git - nageru/commitdiff
Better error messages when channel_name/channel_color return nil.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 May 2016 19:45:52 +0000 (21:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 2 May 2016 20:05:21 +0000 (22:05 +0200)
theme.cpp

index 2b5c5b4257eeef1b0270e5dfc862702e11af0b89..ed187e5561189eda91a3e8e2d389a72aadec58a0 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -811,11 +811,16 @@ string Theme::get_channel_name(unsigned channel)
                fprintf(stderr, "error running function `channel_name': %s\n", lua_tostring(L, -1));
                exit(1);
        }
+       const char *ret = lua_tostring(L, -1);
+       if (ret == nullptr) {
+               fprintf(stderr, "function `channel_name' returned nil for channel %d\n", channel);
+               exit(1);
+       }
 
-       string ret = lua_tostring(L, -1);
+       string retstr = ret;
        lua_pop(L, 1);
        assert(lua_gettop(L) == 0);
-       return ret;
+       return retstr;
 }
 
 int Theme::get_channel_signal(unsigned channel)
@@ -844,10 +849,16 @@ std::string Theme::get_channel_color(unsigned channel)
                exit(1);
        }
 
-       std::string ret = checkstdstring(L, -1);
+       const char *ret = lua_tostring(L, -1);
+       if (ret == nullptr) {
+               fprintf(stderr, "function `channel_color' returned nil for channel %d\n", channel);
+               exit(1);
+       }
+
+       string retstr = ret;
        lua_pop(L, 1);
        assert(lua_gettop(L) == 0);
-       return ret;
+       return retstr;
 }
 
 bool Theme::get_supports_set_wb(unsigned channel)