Difference between revisions of "LSL Hacks"
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
{{LSL Header}} | {{LSL Header}} | ||
{{RightToc}} | {{RightToc}} | ||
= LSL Hacks = | |||
A page dedicated LSL Hacks, those things that make your code so much better but at the same time so much worse. | A page dedicated LSL Hacks, those things that make your code so much better but at the same time so much worse. | ||
{{#if: | {{#if: | ||
Variable hover text stuff. | |||
{{#vardefine:p_myList_desc|A list variable or constant}} | {{#vardefine:p_myList_desc|A list variable or constant}} | ||
{{#vardefine:p_c_desc|An integer variable}} | {{#vardefine:p_c_desc|An integer variable}} | ||
Line 10: | Line 11: | ||
}} | }} | ||
== [[llGetListLength]]({{LSL Param|myList}}) and ({{LSL Param|myList}} != []) == | == [[llGetListLength]]({{LSL Param|myList}}) and ({{LSL Param|myList}} != []) == | ||
{| {{Prettytable}} | {| {{Prettytable|style=margin:0;}} | ||
| '''VM''': LSO | | '''VM''': LSO | ||
| '''Discover''': Strife Onizuka | | '''Discover''': Strife Onizuka | ||
Line 26: | Line 27: | ||
*Will likely be removed in [[LSL3]]{{Footnote|Plans for LSL3 are still being worked out, nothing has been finalized, no release date has been set, LSL3 may in-fact never happen.}} | *Will likely be removed in [[LSL3]]{{Footnote|Plans for LSL3 are still being worked out, nothing has been finalized, no release date has been set, LSL3 may in-fact never happen.}} | ||
== ++c and c++ == | == ++{{LSL Param|c}} and {{LSL Param|c}}++ == | ||
{| {{Prettytable}} | {| {{Prettytable|style=margin:0;}} | ||
| '''VM''': LSO | | '''VM''': LSO | ||
| '''Discover''': Not Applicable | | '''Discover''': Not Applicable | ||
Line 43: | Line 44: | ||
== ({{LSL Param|c}} = -~{{LSL Param|c}}) same as ++{{LSL Param|c}} == | == ({{LSL Param|c}} = -~{{LSL Param|c}}) same as ++{{LSL Param|c}} == | ||
{| {{Prettytable}} | {| {{Prettytable|style=margin:0;}} | ||
| '''VM''': LSO | | '''VM''': LSO | ||
| '''Discover''': Strife Onizuka | | '''Discover''': Strife Onizuka | ||
Line 58: | Line 59: | ||
== Testing [[key]] validity == | == Testing [[key]] validity == | ||
{| {{Prettytable}} | {| {{Prettytable|style=margin:0;}} | ||
| '''VM''': LSO & Mono | | '''VM''': LSO & Mono | ||
| '''Discover''': Strife Onizuka | | '''Discover''': Strife Onizuka | ||
Line 78: | Line 79: | ||
*None | *None | ||
= Footnotes = | |||
{{Footnotes}} | {{Footnotes}} |
Revision as of 09:23, 19 May 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
LSL Hacks
A page dedicated LSL Hacks, those things that make your code so much better but at the same time so much worse.
llGetListLength(myList) and (myList != [])
VM: LSO | Discover: Strife Onizuka |
- Instead of using
llGetListLength(myList)
you can use(myList != [])
. - Instead of using
-llGetListLength(myList)
you can use([] != myList)
.
Pros
- Faster
- Uses less bytecode
Cons
++c and c++
VM: LSO | Discover: Not Applicable |
In LSO LSL (as opposed to Mono LSL) ++c is faster then c++ because of how the bytecode is generated[2]. There are very few applications where ++c can't be used instead.
Pros
- Faster code.
- Saves 6 bytes and 2 instructions.
Cons
- None
(c = -~c) same as ++c
VM: LSO | Discover: Strife Onizuka |
For the same instruction cost of (++c)
, (c = -~c)
can be substituted giving a 4 byte saves.
Pros
- Saves 4 bytes of bytecode.
Cons
- Will fail on hardware that doesn't support two's compliment (unlikely LL will ever use such a platform).
- ?
Testing key validity
VM: LSO & Mono | Discover: Strife Onizuka |
By passing the key value to a conditional, if it is valid and not a NULL_KEY then it will execute the true branch.
<lsl>integer isKey(key in) {
if(in) return 2; return (in == NULL_KEY);
}</lsl>
Pros
- Fast
- Easy
- Painless
Cons
- None