- find_inputs_for_block(L, scene, block, /*first_input_idx=*/2);
-
- if (block->inputs.size() != 1) {
- luaL_error(L, "add_auto_white_balance() needs exactly one input");
+ if (lua_gettop(L) == 1) {
+ // The last added effect is implicitly both the input and gives the white balance controller.
+ assert(!scene->blocks.empty());
+ block->inputs.push_back(scene->blocks.size() - 1);
+ block->white_balance_controller_block = scene->find_root_input_block(L, block);
+ } else if (lua_gettop(L) == 2) {
+ // The given effect is both the input and the white balance controller.
+ block->inputs.push_back(find_block_from_arg(L, scene, 2)->idx);
+ block->white_balance_controller_block = scene->find_root_input_block(L, block);
+ } else if (lua_gettop(L) == 3) {
+ // We have explicit input and white balance controller.
+ block->inputs.push_back(find_block_from_arg(L, scene, 2)->idx);
+ block->white_balance_controller_block = find_block_from_arg(L, scene, 3);
+ } else {
+ luaL_error(L, "add_white_balance([input], [white_balance_controller]) takes zero, one or two arguments");