From: Steinar H. Gunderson Date: Mon, 2 May 2016 19:45:52 +0000 (+0200) Subject: Better error messages when channel_name/channel_color return nil. X-Git-Tag: 1.3.0~37 X-Git-Url: https://git.sesse.net/?p=nageru;a=commitdiff_plain;h=59367b8add7962e605b829a3e2997411e0ee82fe Better error messages when channel_name/channel_color return nil. --- diff --git a/theme.cpp b/theme.cpp index 2b5c5b4..ed187e5 100644 --- 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)