I am writing LSL for the Lua translator, and I am having problems with the complexity of incrementing and contracting statements. LSL has such things using the usual syntax like C (x ++, x--, ++ x, --x), but Lua does not. To avoid massive typing, I treat these types of operators as "crements". In the code below, I will use "..." to represent other parts of the expression.
... x += 1 ...
It does not work, since Lua has a simple purpose.
... x = x + 1 ...
Wont work coz that operator, and Lua cannot use expressions in expressions. LSL can use crements in expressions.
function preIncrement(x) x = x + 1; return x; end ... preIncrement(x) ...
As long as it gives the correct value in the expression, Lua is passed by value for numbers, so the original variable does not change. If I could make it actually change the variable, then all is well. Concerning the environment may not be such a good idea, I don't know in which area x. I think I will explore this further. The translator can display information about the area.
Assuming the above function exists -
... x = preIncrement(x) ...
Does not work for the reason "this expression".
Other solutions are starting to get really dirty.
x = preIncrement(x) ... x ...
Works great unless the LSL source code looks something like this:
while (doOneThing(x++)) { doOtherThing(x); }
Which becomes a whole can of worms. Using tables in a function -
function preIncrement(x) x[1] = x[1] + 1; return x[1]; end temp = {x} ... preincrement(temp) ... x = temp[1]
Even randomly and has the same problems.
To begin with, I may have to actually analyze the surrounding code, and not just do simple translations to figure out what the correct way to implement any given crement will be. Has anyone got any simple ideas?