auto setup_chain = [L, theme, signals_to_connect, images_to_select, int_to_set, float_to_set, vec3_to_set, vec4_to_set, input_state]{
lock_guard<mutex> lock(theme->m);
- assert(theme->input_state == nullptr);
- theme->input_state = &input_state;
-
// Set up state, including connecting signals.
for (const auto &input_and_signal : signals_to_connect) {
LiveInputWrapper *input = input_and_signal.first;
value[0], value[1], value[2], value[3]);
}
}
-
- theme->input_state = nullptr;
};
return make_pair(effect_chain, move(setup_chain));
}
return 0;
}
-int Block_choose_alternative(lua_State* L)
+int Block_choose(lua_State* L)
{
assert(lua_gettop(L) == 2);
Block *block = *(Block **)luaL_checkudata(L, 1, "Block");
- int alternative_idx = luaL_checknumber(L, 2);
+ int alternative_idx = -1;
+ if (lua_isnumber(L, 2)) {
+ alternative_idx = luaL_checknumber(L, 2);
+ } else if (lua_istable(L, 2)) {
+ // See if it's an Effect metatable (e.g. foo:choose(ResampleEffect))
+ lua_getfield(L, 2, "__effect_type_id");
+ if (lua_isnumber(L, -1)) {
+ EffectType effect_type = EffectType(luaL_checknumber(L, -1));
+ alternative_idx = find_index_of(block, effect_type);
+ }
+ lua_pop(L, 1);
+ }
+
+ if (alternative_idx == -1) {
+ luaL_error(L, "choose() called with something that was not an index or an effect type (e.g. ResampleEffect) that was part of the alternatives");
+ }
assert(alternative_idx >= 0);
assert(size_t(alternative_idx) < block->alternatives.size());
assert(lua_gettop(L) == 1);
Block *block = *(Block **)luaL_checkudata(L, 1, "Block");
- if (block->alternatives.size() != 2 ||
- block->alternatives[1]->effect_type != IDENTITY_EFFECT) {
- luaL_error(L, "disable() called on something that wasn't added with add_optional_effect()");
- }
block->currently_chosen_alternative = find_index_of(block, IDENTITY_EFFECT);
+ if (block->currently_chosen_alternative == -1) {
+ luaL_error(L, "disable() called on something that didn't have an IdentityEffect fallback (try add_optional_effect())");
+ }
assert(block->currently_chosen_alternative != -1);
return 0;
}