]> git.sesse.net Git - nageru/blobdiff - theme.cpp
Ask the Lua script for number of channels.
[nageru] / theme.cpp
index 5d42c3d661d8a05d99f05613bb18c1eb2470e4c7..31eb23d2e36a67a4c7c14737d18cfb8bd3d1ef41 100644 (file)
--- a/theme.cpp
+++ b/theme.cpp
@@ -191,14 +191,24 @@ Theme::Theme(const char *filename, ResourcePool *resource_pool)
        register_class("LiveInputWrapper", LiveInputWrapper_funcs); 
        register_class("WhiteBalanceEffect", WhiteBalanceEffect_funcs); 
 
-        // Run script.
-        lua_settop(L, 0);
-        if (luaL_dofile(L, filename)) {
-                fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
-                lua_pop(L, 1);
-                exit(1);
-        }
-        assert(lua_gettop(L) == 0); 
+       // Run script.
+       lua_settop(L, 0);
+       if (luaL_dofile(L, filename)) {
+               fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
+               lua_pop(L, 1);
+               exit(1);
+       }
+       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", lua_tostring(L, -1));
+               exit(1);
+       }
+
+       num_channels = luaL_checknumber(L, 1);
 }
 
 void Theme::register_class(const char *class_name, const luaL_Reg *funcs)