Difference between revisions of "Preprocessing"

From Second Life Wiki
Jump to navigation Jump to search
(New page: I suggest the ability to add preprocessing to LSL, as this has no effect on LSL itself but can provide scripts which can do many different things, depending on. This would include. #Basic...)
 
(added ifndef and etc)
 
Line 3: Line 3:
This would include.
This would include.
#Basic Define keyword, can be used to define custom static variables. (these may need to be typed)
#Basic Define keyword, can be used to define custom static variables. (these may need to be typed)
#IF, IFN, ELSE, ENDIF preprocessor branches
#IF, ELSE, ENDIF preprocessor branches
#IFDEF, IFNDEF preprocessors


As such a script such as this:
As such a script such as this:
<lsl>
<lsl>
#define DEBUG   TRUE
#define DEBUG


#if DEBUG
#ifdef DEBUG
string mode = "DEBUG";
string mode = "DEBUG";
#else
#else
Line 17: Line 18:
default
default
{
{
#if DEBUG
#ifdef DEBUG
     on_rez(integer s)
     on_rez(integer s)
     {
     {
Line 27: Line 28:
     {
     {
         llOwnerSay(mode);
         llOwnerSay(mode);
#if DEBUG
#ifdef DEBUG
         llOwnerSay(llGetDate();
         llOwnerSay(llGetDate();
     }
     }
Line 38: Line 39:
Could produce two different scripts depending on the value of DEBUG, which would then get compiled/interpreted.
Could produce two different scripts depending on the value of DEBUG, which would then get compiled/interpreted.


With DEBUG set to TRUE.
With DEBUG defined
<lsl>
<lsl>
#define DEBUG   TRUE
#define DEBUG


string mode = "DEBUG";
string mode = "DEBUG";
Line 59: Line 60:
</lsl>
</lsl>


With DEBUG set to FALSE.
Without DEBUG defined
<lsl>
<lsl>
#define DEBUG  FALSE
string mode = "NORMAL";
string mode = "NORMAL";



Latest revision as of 20:09, 5 May 2009

I suggest the ability to add preprocessing to LSL, as this has no effect on LSL itself but can provide scripts which can do many different things, depending on.

This would include.

  1. Basic Define keyword, can be used to define custom static variables. (these may need to be typed)
  2. IF, ELSE, ENDIF preprocessor branches
  3. IFDEF, IFNDEF preprocessors

As such a script such as this: <lsl>

  1. define DEBUG
  1. ifdef DEBUG

string mode = "DEBUG";

  1. else

string mode = "NORMAL";

  1. endif

default {

  1. ifdef DEBUG
   on_rez(integer s)
   {
       llResetScript()
   }
  1. endif
   state_entry()
   {
       llOwnerSay(mode);
  1. ifdef DEBUG
       llOwnerSay(llGetDate();
   }
  1. else
   }
  1. endif

} </lsl>

Could produce two different scripts depending on the value of DEBUG, which would then get compiled/interpreted.

With DEBUG defined <lsl>

  1. define DEBUG

string mode = "DEBUG";

default {

   on_rez(integer s)
   {
       llResetScript()
   }
   state_entry()
   {
       llOwnerSay(mode);
       llOwnerSay(llGetDate();
   }

} </lsl>

Without DEBUG defined <lsl> string mode = "NORMAL";

default {

   state_entry()
   {
       llOwnerSay(mode);
   }

} </lsl>