-
Notifications
You must be signed in to change notification settings - Fork 0
Define Expressions
Define expression are responsible for all ahead-of-time things you can do, like creating a new color or defining a new keyword.
It is generally recommended to only use #define Statements at the beginning of SusLang scripts.
If you are interested in how they actually work, you can find their source code [here].(https://github.com/zenonet/SusLang/blob/master/SusLang.Compiler/Expressions/DefaultExpressions/DefineExpression.cs)
#define color <color-name> allows you to create your own color which you can use like any other color.
Works in v0.5+
#define color neonblack
neonblack killed
report neonblack
#define suspect <color> sets a colors value to 65. This is useful when writing text is SusLang because 65 is the index of A, the first actual letter in ASCII
Note that this will set a colors value to 65 when the #define statement gets parsed. NOT when it's executed.
This might lead to unexpected behaviour in for example #define keyword expressions.
Works in v0.5+
#define suspect red
emergencyMeeting red
This will output the capital A.
#define keyword <name> [parameter1] [parameter2] allows you to create your own keywords like this:
Works in v0.5+
// This will create a keyword called vanished with one parameter (called red) which increases it's parameter by 5
#define keyword vanished red
// Increase red by 5
red vented
red vented
red vented
red vented
red vented
// This marks the end of the keyword definition:
#define keyword end
After defining the keyword, you can use it like this:
cyan killed
// Call the custom keyword
cyan vanished
//This will output 15 because vanished increased it's parameter by 5
report cyan
The name of this one is a but weird, I might change it some day.
Anyways, the #define import <path> expression allows you to import a SusLang-Library into your current file.
Here is an example:
Works in v0.5+
In your mylib.sus file
#define keyword plus red green
//Copy green to blue
blue wasWith green
//Add blue to red
sus blue
[
red vented
blue wasWithMe
]
#define keyword end
In your main file:
#define import mylib.sus
red killed
green vented
green vented
green vented
red plus green
report red
As you can see, the add keyword is defined in the mylib file but because of the #define import Statement, you can still use the keyword in your main file.
This works by simply executing the imported files (in the same context) when parsing the #define import Statement. This is far from a clean solution but hey, this is an esolang!