From ba894de3014f02d0c6889b5e2df821b97a265bdb Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 3 Feb 2012 22:36:25 +1000 Subject: Assignments in the middle of expressions is legal in LSL, but not in Lua. Bump that problem until later. --- .../objects/onefang's test bed/~menucfg.lsl | 4 ++- LuaSL/src/LuaSL_compile.c | 35 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/LuaSL/Test sim/objects/onefang's test bed/~menucfg.lsl b/LuaSL/Test sim/objects/onefang's test bed/~menucfg.lsl index d38843d..a258fb8 100644 --- a/LuaSL/Test sim/objects/onefang's test bed/~menucfg.lsl +++ b/LuaSL/Test sim/objects/onefang's test bed/~menucfg.lsl @@ -254,10 +254,12 @@ state load { integer ix; integer count; - while ((ix = myListFind(buttons, "-")) != -1) { + ix = myListFind(buttons, "-"); + while (ix != -1) { ++count; buttons = llDeleteSubList(buttons, ix, ix); commands = llDeleteSubList(commands, ix, ix); + ix = myListFind(buttons, "-"); } if (count) { for (ix = 1; ix < llGetListLength(buttonindex); ++ix) { diff --git a/LuaSL/src/LuaSL_compile.c b/LuaSL/src/LuaSL_compile.c index e9a22c1..8194947 100644 --- a/LuaSL/src/LuaSL_compile.c +++ b/LuaSL/src/LuaSL_compile.c @@ -1,5 +1,40 @@ #include "LuaSL.h" +/* TODO - + +Assignments in the middle of expressions is legal in LSL, but not in Lua. +The big complication is that they often happen in the conditionals of flow control statements. That's a big bitch. + +So things like - + + while ((x = doSomething()) == foo) + { + buggerAround(); + } + +Turns into - + + x = doSomething(); + while (x == foo) + { + buggerAround(); + x = doSomething(); + } + +http://lua-users.org/wiki/StatementsInExpressions might be helpful. Which suggests something like this - + + while ( (function() x = doSomething(); return x; end)() == foo) + { + buggerAround(); + } + +The remaining problem is when to recognise the need to do that. +Note that assignments are really low precedence. + While adding operations + Flag the assignment expressions + If there is an assignment expression (not operation) on the RHS of an operation, we need to do this? +*/ + static LSL_Leaf *evaluateFloatToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); static LSL_Leaf *evaluateIntegerToken(LSL_Leaf *content, LSL_Leaf *left, LSL_Leaf *right); -- cgit v1.1