VWR-1287 : support switch/case in LSL
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
09-26-2007 10:30
Somebody JIRA'ed this.. From: someone switch() statements in LSL would be quite handy, and cut down on a lot of if() statements.
Adding a switch statement to the compiler would give a reduction in bytecode. It would be X + 3 - N * 3, where X is the number of bytes of bytecode needed and N is the number of 'case' statements (excluding 'default'). This is as compared to using if-else blocks, doing a fall-into in if-else blocks would be tricky and costly.
The most tricky thing about this would be adding the break keyword.
Some samples of syntax and the appropriate bytecode are attached.
The syntax and function would be identical to C. If you know C (or C++ or C# or Java, etc) you know how much nicer switch/case support would make LSL.. Vote it up at http://jira.secondlife.com/browse/VWR-1287 .
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Lyn Mimistrobell
(waiting)
Join date: 11 Jan 2007
Posts: 179
|
09-26-2007 10:52
Sure, switch would be nice... but whatever you can do with a switch you can also do with if/elseif/else. There are so many things that we'd like that cannot be recreated using the existing methods, that this one for me is really low prioirity.
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
09-26-2007 10:57
If you think there are other language featues that would be better, please add JIRA issues for them.
Big blocks of if statements are not a very good replacement for switch/case, IMO. You either need to 'else' every bit of it, eat the cost of evaluating every 'if' or add returns all over the place. Having switch/case could _really_ cut down on the complexity of some of my scripts..
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Dytska Vieria
+/- .00004™
Join date: 13 Dec 2006
Posts: 768
|
09-26-2007 11:00
Do not quote me, but I believe in C, a switch case block is more optimum than an if/else if/else block because the entire block is examined in an if/else if/else block and only the one case in a switch is examined in a switch case.
So, not only does switch case make things more simple, it is more optimum and may cut down on script time lag.
_____________________
+/- 0.00004
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
09-26-2007 11:29
I've heard that before.. Since case values must be constants, the compiler can build an index table and just jump to the right one.
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|
|
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
|
09-26-2007 11:54
How about we go for arrays first?
_____________________
--AeonVox--Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
|
|
Monica Balut
Beam-Me
Join date: 18 Feb 2007
Posts: 311
|
09-26-2007 12:34
or being able to write to some sort of persistent data card
|
|
Meade Paravane
Hedgehog
Join date: 21 Nov 2006
Posts: 4,845
|
09-26-2007 12:44
From: Kenn Nilsson How about we go for arrays first? Add a new issue and pimp it in your own thread!!  From: Monica Balut or being able to write to some sort of persistent data card Writable notecards are not gonna happen. If you have a different idea, one that would be helpful and really hard to abuse, see the answer above. 
_____________________
Tired of shouting clubs and lucky chairs? Vote for llParcelSay!!! - Go here: http://jira.secondlife.com/browse/SVC-1224- If you see "if you were logged in.." on the left, click it and log in - Click the "Vote for it" link on the left
|