Open sl-service-account opened 1 year ago
Spidey Linden commented at 2023-04-19T17:35:57Z
Hello, and thank you for your feature request.
Incoming suggestions are reviewed in the order they are received by a team of Lindens with diverse areas of expertise. We consider a number of factors: Is this change possible? Will it increase lag? Will it break existing content? Is it likely that the number of residents using this feature will justify the time to develop it? This wiki page further describes the reasoning we use: http://wiki.secondlife.com/wiki/Feature_Requests
This particular suggestion, unfortunately, cannot be tackled at this time. However, we regularly review previously deferred suggestions when circumstances change or resources become available.
We are grateful for the time you took to submit this feature request. We hope that you are not discouraged from submitting others in the future. Many excellent ideas to improve Second Life come from you, our residents. We can’t do it alone.
Thank you for your continued commitment to Second Life.
How would you like the feature to work?
Currently LSL does not support break. I think a way LL could implement it quickly and safely using the existing opcodes for LSL is as follows.
Assign an internal breaks_handled=numberOfBreaks in the LSL compiler when compiling the script. This will hold the number of "break;" detected in the script, determined before the compilation process begins. Though, multiple break statements inside one loop are consolidated to represent a single break conceptually.
The label number for the jump label will be the line number in the LSL script where the loop has ended, determined when parsing the script. This label is automatically injected on the server side after each for loop ends during the compilation process if any break keywords exist on a previously entered line. An array of these line labels is indexable by breaks_handled.
Once the label is injected, then subtract from breaks_handled until it reaches zero. Change the previous "break;" to "jump label"+labelLine. The resulting lines changing in the transformed script during compilation do not impact the functionality because the labeling is just a unique way to separate the break labels.
This means the following script:
Now becomes internally (the scripter doesn't see this):
And, the break keyword will work as expected.
Also, I would suggest dynamically increasing the allowed memory for the script by the number of jump and label opcodes added by this procedure. For safety, there can be a high upper threshold on how many are allowed if there is a concern regarding that, e.g. no more than 20,000 breaks can be added so that it isn't too constricting but also prevents unlimited abusing of memory.
This feature would be appreciated and this would be a safe quick way to inject the functionality.
Edit 05/11/23: It goes without saying that the
continue
keyword should also be implemented. This means the following script:Now becomes internally (the scripter doesn't see this):
Why is this feature important to you? How would it benefit the community?
The break keyword would be very useful to have for scripters and modernize the language.
Original Jira Fields
| Field | Value | | ------------- | ------------- | | Issue | BUG-233780 | | Summary | Loop break implementation | | Type | New Feature Request | | Priority | Unset | | Status | Accepted | | Resolution | Unresolved | | Created at | 2023-04-19T08:30:37Z | | Updated at | 2023-09-08T03:13:24Z | ``` { 'Build Id': 'unset', 'Business Unit': ['Platform'], 'Date of First Response': '2023-04-19T12:35:56.513-0500', 'How would you like the feature to work?': 'Currently LSL does not support break. I think a way LL could implement it quickly and safely using the existing opcodes for LSL is as follows.\r\n\r\nAssign an internal breaks_handled=numberOfBreaks in the LSL compiler when compiling the script. This will hold the number of "break;" detected in the script, determined before the compilation process begins.\r\n\r\nThe label number for the jump label will be the line number in the LSL script where the loop has ended, determined when parsing the script. This label is automatically injected on the server side after each for loop ends during the compilation process if a break keyword exists on a previously entered line. \r\n\r\nOnce the label is injected, then subtract from breaks_handled until it reaches zero. Change the previous "break;" to "jump label"+labelLine. The resulting lines changing in the transformed script during compilation do not impact the functionality because the labeling is just a unique way to separate the break labels.\r\n\r\nThis means the following script:\r\n\r\nlist data = [9,3,2,4];\r\ninteger i;\r\nfor(i=0 ;i < llGetListLength(data); i++)\r\n{\r\n if (llList2Integer(data, i) < 3) break;\r\n llOwnerSay("Data Analyzed");\r\n}\r\n\r\nNow becomes:\r\n\r\nlist data = [9,3,2,4];\r\ninteger i;\r\nfor(i=0 ;i < llGetListLength(data); i++)\r\n{\r\n if (llList2Integer(data, i) < 3) jump label842;\r\n llOwnerSay("Data Analyzed");\r\n}\r\n@label842;\r\n\r\nAnd, the break keyword will work as expected.\r\n\r\nAlso, I would suggest dynamically increasing the allowed memory for the script by the number of jump and label opcodes added by this procedure. For safety, there can be a high upper threshold on how many are allowed if there is a concern regarding that, e.g. no more than 20,000 breaks can be added so that it isn\'t too constricting but also prevents unlimited abusing of memory.\r\n\r\nThis feature would be appreciated and this would be a safe quick way to inject the functionality.', 'ReOpened Count': 0.0, 'Severity': 'Unset', 'Target Viewer Version': 'viewer-development', 'Why is this feature important to you? How would it benefit the community?': 'The break keyword would be very useful to have for scripters and modernize the language.', } ```