+ 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_alternative(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_alternative() called with something that was not an index or an effect type (e.g. ResampleEffect) that was part of the alternatives");
+ }