return wrap_lua_existing_object_nonowned<Block>(L, "Block", block);
}
+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);
+ }
+}
+
int Scene::add_effect(lua_State* L)
{
assert(lua_gettop(L) >= 2);
block->alternatives.push_back(blueprint);
}
- // Find the inputs.
- if (lua_gettop(L) == 2) {
- assert(!scene->blocks.empty());
- block->inputs.push_back(scene->blocks.size() - 1);
- } else {
- 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);
- }
- }
-
+ find_inputs_for_block(L, scene, block);
scene->blocks.push_back(block);
return wrap_lua_existing_object_nonowned<Block>(L, "Block", block);