I should mention, you can access global variables set by lua in regular tup-syntax files, and vice versa. So if you don't want to rewrite your "lots of stuff based on $(MODE) and $(VARIANT)" in lua, you can do something like this:
# Tupfile.lua:
VARIANT = variant
tup.include("rules.tup")
end
end
# rules.tup:
: |> echo Using mode $(MODE) with variant $(VARIANT) |>
(The local variables i, mode, j, and variant aren't accessible in rules.tup, but the global variables modes, variants, MODE, and VARIANT are).
You may also want to "tup refactor" to help verify that refactoring your Tupfiles into lua doesn't produce any unwanted changes if you are expecting it to generate the exact same command-lines.
-Mike