From fb5360d92864760d70d8a69c8dd4a9e738bcc0f0 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 21 Jan 2016 23:52:05 +0100 Subject: [PATCH] Small refactoring. --- theme.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/theme.cpp b/theme.cpp index e1fa816..3f387f8 100644 --- a/theme.cpp +++ b/theme.cpp @@ -646,6 +646,25 @@ void LiveInputWrapper::connect_signal(int signal_num) } } +namespace { + +int call_num_channels(lua_State *L) +{ + lua_getglobal(L, "num_channels"); + + if (lua_pcall(L, 0, 1, 0) != 0) { + fprintf(stderr, "error running function `num_channels': %s\n", lua_tostring(L, -1)); + exit(1); + } + + int num_channels = luaL_checknumber(L, 1); + lua_pop(L, 1); + assert(lua_gettop(L) == 0); + return num_channels; +} + +} // namespace + Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards) : resource_pool(resource_pool), num_cards(num_cards) { @@ -674,16 +693,7 @@ Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_car assert(lua_gettop(L) == 0); // Ask it for the number of channels. - lua_getglobal(L, "num_channels"); - - if (lua_pcall(L, 0, 1, 0) != 0) { - fprintf(stderr, "error running function `num_channels': %s\n", lua_tostring(L, -1)); - exit(1); - } - - num_channels = luaL_checknumber(L, 1); - lua_pop(L, 1); - assert(lua_gettop(L) == 0); + num_channels = call_num_channels(L); } Theme::~Theme() -- 2.39.2