X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Ftheme.cpp;h=b53c65bc3434f61aae29904c242254893a672d75;hb=c109bb45b840bc48d265dd4bb03a3a27061b7eb7;hp=6a4de4baa248ece934994332de8d559b29736010;hpb=b7398dd7960ddf07f03b9a9ebc669d29141c09d0;p=nageru diff --git a/nageru/theme.cpp b/nageru/theme.cpp index 6a4de4b..b53c65b 100644 --- a/nageru/theme.cpp +++ b/nageru/theme.cpp @@ -1212,6 +1212,7 @@ int call_num_channels(lua_State *L) if (lua_pcall(L, 0, 1, 0) != 0) { fprintf(stderr, "error running function `num_channels': %s\n", lua_tostring(L, -1)); + fprintf(stderr, "Try Nageru.set_num_channels(...) at the start of the script instead.\n"); abort(); } @@ -1234,6 +1235,18 @@ int Nageru_set_channel_name(lua_State *L) return 0; } +int Nageru_set_num_channels(lua_State *L) +{ + // NOTE: m is already locked. + Theme *theme = get_theme_updata(L); + if (theme->startup_finished) { + luaL_error(L, "set_num_channels() can only be called at startup."); + } + theme->num_channels = luaL_checknumber(L, 1); + lua_pop(L, 1); + return 0; +} + Theme::Theme(const string &filename, const vector &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) { @@ -1335,8 +1348,11 @@ Theme::Theme(const string &filename, const vector &search_dirs, Resource } assert(lua_gettop(L) == 0); - // Ask it for the number of channels. - num_channels = call_num_channels(L); + if (num_channels == -1) { + // Ask it for the number of channels. + num_channels = call_num_channels(L); + } + startup_finished = true; } Theme::~Theme() @@ -1371,6 +1387,7 @@ void Theme::register_globals() const luaL_Reg Nageru_funcs[] = { { "set_channel_name", Nageru_set_channel_name }, + { "set_num_channels", Nageru_set_num_channels }, { NULL, NULL } }; lua_pushlightuserdata(L, this); @@ -1521,6 +1538,7 @@ string Theme::get_channel_name(unsigned channel) const char *ret = lua_tostring(L, -1); if (ret == nullptr) { fprintf(stderr, "function `channel_name' returned nil for channel %d\n", channel); + fprintf(stderr, "Try Nageru.set_channel_name(channel, name) at the start of the script instead.\n"); abort(); }