fprintf(stderr, " -c, --num-cards set number of input cards, including fake cards (default 2)\n");
fprintf(stderr, " -C, --num-fake-cards set number of fake cards (default 0)\n");
fprintf(stderr, " -t, --theme=FILE choose theme (default theme.lua)\n");
+ fprintf(stderr, " -I, --theme-dir=DIR search for theme in this directory (can be given multiple times)\n");
fprintf(stderr, " -v, --va-display=SPEC VA-API device for H.264 encoding\n");
fprintf(stderr, " ($DISPLAY spec or /dev/dri/render* path)\n");
fprintf(stderr, " -m, --map-signal=SIGNAL,CARD set a default card mapping (can be given multiple times)\n");
{ "num-cards", required_argument, 0, 'c' },
{ "num-fake-cards", required_argument, 0, 'C' },
{ "theme", required_argument, 0, 't' },
+ { "theme-dir", required_argument, 0, 'I' },
{ "map-signal", required_argument, 0, 'm' },
{ "va-display", required_argument, 0, OPTION_VA_DISPLAY },
{ "http-uncompressed-video", no_argument, 0, OPTION_HTTP_UNCOMPRESSED_VIDEO },
{ "no-flush-pbos", no_argument, 0, OPTION_NO_FLUSH_PBOS },
{ 0, 0, 0, 0 }
};
+ vector<string> theme_dirs;
for ( ;; ) {
int option_index = 0;
int c = getopt_long(argc, argv, "c:C:t:v:m:", long_options, &option_index);
case 't':
global_flags.theme_filename = optarg;
break;
+ case 'I':
+ theme_dirs.push_back(optarg);
+ break;
case 'm': {
char *ptr = strchr(optarg, ',');
if (ptr == nullptr) {
} else if (global_flags.x264_preset.empty()) {
global_flags.x264_preset = X264_DEFAULT_PRESET;
}
+ if (!theme_dirs.empty()) {
+ global_flags.theme_dirs = theme_dirs;
+ }
for (pair<int, int> mapping : global_flags.default_stream_mapping) {
if (mapping.second >= global_flags.num_cards) {
std::string va_display;
bool uncompressed_video_to_http = false;
bool x264_video_to_http = false;
+ std::vector<std::string> theme_dirs { ".", "/usr/local/share/nageru" };
std::string theme_filename = "theme.lua";
bool locut_enabled = true;
bool gain_staging_auto = true;
movit_texel_subpixel_precision /= 2.0;
resource_pool.reset(new ResourcePool);
- theme.reset(new Theme(global_flags.theme_filename.c_str(), resource_pool.get(), num_cards));
+ theme.reset(new Theme(global_flags.theme_filename, global_flags.theme_dirs, resource_pool.get(), num_cards));
for (unsigned i = 0; i < NUM_OUTPUTS; ++i) {
output_channel[i].parent = this;
output_channel[i].channel = i;
} // namespace
-Theme::Theme(const char *filename, ResourcePool *resource_pool, unsigned num_cards)
+Theme::Theme(const string &filename, const vector<string> &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)
{
L = luaL_newstate();
register_class("MixEffect", MixEffect_funcs);
register_class("InputStateInfo", InputStateInfo_funcs);
- // Run script.
+ // Run script. Search through all directories until we find a file that will load
+ // (as in, does not return LUA_ERRFILE); then run it. We store load errors
+ // from all the attempts, and show them once we know we can't find any of them.
lua_settop(L, 0);
- if (luaL_dofile(L, filename)) {
- fprintf(stderr, "error: %s\n", lua_tostring(L, -1));
+ vector<string> errors;
+ bool success = false;
+ for (size_t i = 0; i < search_dirs.size(); ++i) {
+ string path = search_dirs[i] + "/" + filename;
+ int err = luaL_loadfile(L, path.c_str());
+ if (err == 0) {
+ // Success; actually call the code.
+ if (lua_pcall(L, 0, LUA_MULTRET, 0)) {
+ fprintf(stderr, "Error when running %s: %s\n", path.c_str(), lua_tostring(L, -1));
+ exit(1);
+ }
+ success = true;
+ break;
+ }
+ errors.push_back(lua_tostring(L, -1));
lua_pop(L, 1);
+ if (err != LUA_ERRFILE) {
+ // The file actually loaded, but failed to parse somehow. Abort; don't try the next one.
+ break;
+ }
+ }
+
+ if (!success) {
+ for (const string &error : errors) {
+ fprintf(stderr, "%s\n", error.c_str());
+ }
exit(1);
}
assert(lua_gettop(L) == 0);
class Theme {
public:
- Theme(const char *filename, movit::ResourcePool *resource_pool, unsigned num_cards);
+ Theme(const std::string &filename, const std::vector<std::string> &search_dirs, movit::ResourcePool *resource_pool, unsigned num_cards);
~Theme();
struct Chain {