+void Scene::find_inputs_for_block(lua_State *L, Scene *scene, Block *block)
+{
+ if (lua_gettop(L) == 2) {
+ // Implicitly the last added effect.
+ assert(!scene->blocks.empty());
+ block->inputs.push_back(scene->blocks.size() - 1);
+ return;
+ }
+
+ for (int idx = 3; idx <= lua_gettop(L); ++idx) {
+ Block *input_block = nullptr;
+ if (luaL_testudata(L, idx, "Block")) {
+ input_block = *(Block **)luaL_checkudata(L, idx, "Block");
+ } else {
+ EffectBlueprint *blueprint = *(EffectBlueprint **)luaL_checkudata(L, idx, "EffectBlueprint");
+
+ // Search through all the blocks to figure out which one contains this effect.
+ for (Block *block : scene->blocks) {
+ if (find(block->alternatives.begin(), block->alternatives.end(), blueprint) != block->alternatives.end()) {
+ input_block = block;
+ break;
+ }
+ }
+ if (input_block == nullptr) {
+ luaL_error(L, "Input effect in parameter #%d has not been added to this scene", idx - 1);
+ }
+ }
+ block->inputs.push_back(input_block->idx);
+ }
+}
+