X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fscene.cpp;h=a3d3c6a20f172496f58b1509b82c59eccb0050e8;hb=ca090e45b28fed464008086fbe3db19437c115dd;hp=6eb86ac91e6f85e1cf45120cc82910aceb3a0374;hpb=67bcd1fb516072bf48e4ac140b057f74a31edba0;p=nageru diff --git a/nageru/scene.cpp b/nageru/scene.cpp index 6eb86ac..a3d3c6a 100644 --- a/nageru/scene.cpp +++ b/nageru/scene.cpp @@ -495,7 +495,22 @@ int Block_choose_alternative(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_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"); + } assert(alternative_idx >= 0); assert(size_t(alternative_idx) < block->alternatives.size());