Proposal for simple but effective enhancements of LSL constructs
Artesia Heartsong
LSL is missing constructs that may reduce code a lot, save memory or increase performance.
Some are (not exhaustive yet):
- break/continue in loops, possibly with break 2 and continue 2 for skipping to a higher loop
- elseif
- ternary operators a = b?a:d or shortcut, if possible: a = b?;d
A less obvious one but regarding memory usage a really big one: optionally using parameters by reference for function calls.
Log In
WolfGang Senizen
While LSL does not have explicit break / continue syntax, you can implement them with jump
default
{
state_entry()
{
integer i;
integer j;
for(i=0;i<10;i++) {
for(j=0;j<10;j++) {
if(i == 2 && j == 2) jump loop_break_1;
else if(i == 3 && j == 3) jump loop_break_2;
}
@loop_break_1;
llOwnerSay((string)[i," - ",j]);
}
@loop_break_2;
llOwnerSay((string)[i," - ",j]);
}
}
In fact several people have made tools to add support for
break
and continue
in LSL by running their code through a transpile like step before uploading it to sl, and converting their break / continue statements into jumps.That also demonstrates LSL's use of
else if
, I recommend looking at the wiki page for flow controlTernary would be neat, but in at least the short term further development of LSL is unlikely especially as LUA is currently being prepped for partial release on main grid.
Artesia Heartsong
WolfGang Senizen I'm aware of the jump statement, ty for that. And yes, since I wrote a full transpiler to LSL for me it's very simple to convert any continue or break statement into jumps. And to be fair, built in LSL itself should be a very, very easy modification (especially one level break/continue).
The ternary is something very useful, in many cases way less code. Until Lua is fully available, I'd still propose to add that.