IncludeCPP 4.0.2__py3-none-any.whl → 4.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- includecpp/CHANGELOG.md +142 -0
- includecpp/DOCUMENTATION.md +446 -0
- includecpp/__init__.py +1 -1
- includecpp/__init__.pyi +4 -1
- includecpp/cli/commands.py +700 -86
- includecpp/core/ai_integration.py +46 -13
- includecpp/core/cpp_api_extensions.pyi +350 -0
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +1535 -1316
- includecpp/core/cssl/cssl_builtins.py +230 -23
- includecpp/core/cssl/cssl_languages.py +1757 -0
- includecpp/core/cssl/cssl_parser.py +967 -126
- includecpp/core/cssl/cssl_runtime.py +1133 -84
- includecpp/core/cssl/cssl_syntax.py +88 -4
- includecpp/core/cssl/cssl_types.py +361 -1
- includecpp/core/cssl_bridge.py +194 -8
- includecpp/core/cssl_bridge.pyi +148 -10
- includecpp/generator/parser.cpp +121 -4
- includecpp/generator/parser.h +6 -0
- includecpp/vscode/cssl/package.json +43 -1
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +178 -19
- includecpp-4.3.0.dist-info/METADATA +277 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/RECORD +26 -22
- includecpp-4.0.2.dist-info/METADATA +0 -908
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/WHEEL +0 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/entry_points.txt +0 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/licenses/LICENSE +0 -0
- {includecpp-4.0.2.dist-info → includecpp-4.3.0.dist-info}/top_level.txt +0 -0
|
@@ -1,1501 +1,1720 @@
|
|
|
1
|
-
# CSSL - C-Style Scripting Language
|
|
1
|
+
# CSSL - C-Style Scripting Language
|
|
2
2
|
|
|
3
|
-
> Version 4.
|
|
3
|
+
> Version 4.1.0 | A modern scripting language with C++-style syntax and unique features like CodeInfusion, BruteInjection, Python Interop, and Multi-Language Support.
|
|
4
4
|
|
|
5
|
-
---
|
|
5
|
+
---
|
|
6
6
|
|
|
7
|
-
## Table of Contents
|
|
7
|
+
## Table of Contents
|
|
8
8
|
|
|
9
|
-
1. [Quick Start](#quick-start)
|
|
10
|
-
2. [Syntax Basics](#syntax-basics)
|
|
11
|
-
3. [Data Types](#data-types)
|
|
12
|
-
4. [Variables & Globals](#variables--globals)
|
|
13
|
-
5. [Operators](#operators)
|
|
14
|
-
6. [Control Flow](#control-flow)
|
|
15
|
-
7. [Functions](#functions)
|
|
16
|
-
8. [Classes & OOP](#classes--oop)
|
|
17
|
-
9. [Container Types](#container-types)
|
|
18
|
-
10. [Built-in Functions](#built-in-functions)
|
|
19
|
-
11. [CodeInfusion](#codeinfusion)
|
|
20
|
-
12. [BruteInjection](#bruteinjection)
|
|
21
|
-
13. [Value Capture](#value-capture)
|
|
22
|
-
14. [Module System](#module-system)
|
|
23
|
-
15. [
|
|
24
|
-
16. [
|
|
9
|
+
1. [Quick Start](#quick-start)
|
|
10
|
+
2. [Syntax Basics](#syntax-basics)
|
|
11
|
+
3. [Data Types](#data-types)
|
|
12
|
+
4. [Variables & Globals](#variables--globals)
|
|
13
|
+
5. [Operators](#operators)
|
|
14
|
+
6. [Control Flow](#control-flow)
|
|
15
|
+
7. [Functions](#functions)
|
|
16
|
+
8. [Classes & OOP](#classes--oop)
|
|
17
|
+
9. [Container Types](#container-types)
|
|
18
|
+
10. [Built-in Functions](#built-in-functions)
|
|
19
|
+
11. [CodeInfusion](#codeinfusion)
|
|
20
|
+
12. [BruteInjection](#bruteinjection)
|
|
21
|
+
13. [Value Capture](#value-capture)
|
|
22
|
+
14. [Module System](#module-system)
|
|
23
|
+
15. [Multi-Language Support](#multi-language-support)
|
|
24
|
+
16. [Error Handling](#error-handling)
|
|
25
|
+
17. [Quick Reference](#quick-reference)
|
|
25
26
|
|
|
26
|
-
---
|
|
27
|
+
---
|
|
27
28
|
|
|
28
|
-
## Quick Start
|
|
29
|
+
## Quick Start
|
|
29
30
|
|
|
30
|
-
### Installation
|
|
31
|
+
### Installation
|
|
31
32
|
|
|
32
|
-
```bash
|
|
33
|
-
pip install includecpp
|
|
34
|
-
```
|
|
33
|
+
```bash
|
|
34
|
+
pip install includecpp
|
|
35
|
+
```
|
|
35
36
|
|
|
36
|
-
### Python Usage
|
|
37
|
+
### Python Usage
|
|
37
38
|
|
|
38
|
-
```python
|
|
39
|
-
from includecpp import CSSL
|
|
39
|
+
```python
|
|
40
|
+
from includecpp import CSSL
|
|
40
41
|
|
|
41
|
-
# Execute CSSL code
|
|
42
|
-
CSSL.run('''
|
|
43
|
-
|
|
44
|
-
''')
|
|
42
|
+
# Execute CSSL code
|
|
43
|
+
CSSL.run('''
|
|
44
|
+
printl("Hello CSSL!");
|
|
45
|
+
''')
|
|
45
46
|
|
|
46
|
-
# With parameters and return value
|
|
47
|
-
result = CSSL.run('''
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
''', "World")
|
|
47
|
+
# With parameters and return value
|
|
48
|
+
result = CSSL.run('''
|
|
49
|
+
string name = parameter.get(0);
|
|
50
|
+
printl("Hello " + name);
|
|
51
|
+
parameter.return(true);
|
|
52
|
+
''', "World")
|
|
52
53
|
|
|
53
|
-
print(result) # True
|
|
54
|
-
```
|
|
54
|
+
print(result) # True
|
|
55
|
+
```
|
|
55
56
|
|
|
56
|
-
### CLI Execution
|
|
57
|
+
### CLI Execution
|
|
57
58
|
|
|
58
|
-
```bash
|
|
59
|
-
# Execute CSSL file
|
|
60
|
-
python -m includecpp cssl exec myfile.cssl
|
|
59
|
+
```bash
|
|
60
|
+
# Execute CSSL file
|
|
61
|
+
python -m includecpp cssl exec myfile.cssl
|
|
61
62
|
|
|
62
|
-
# Create module from Python file
|
|
63
|
-
python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### First Script
|
|
63
|
+
# Create module from Python file
|
|
64
|
+
python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
|
|
65
|
+
```
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
// Variables
|
|
70
|
-
string name = "CSSL";
|
|
71
|
-
int version = 3;
|
|
67
|
+
### First Script
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
```cssl
|
|
70
|
+
// Variables
|
|
71
|
+
string name = "CSSL";
|
|
72
|
+
int version = 3;
|
|
75
73
|
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
printl(msg);
|
|
79
|
-
}
|
|
74
|
+
// Output
|
|
75
|
+
printl("Welcome to " + name);
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
// Function
|
|
78
|
+
void greet(string msg) {
|
|
79
|
+
printl(msg);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
greet("Hello World!");
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Syntax Basics
|
|
88
|
+
|
|
89
|
+
### Comments
|
|
83
90
|
|
|
84
|
-
|
|
91
|
+
```cssl
|
|
92
|
+
// Single-line comment (C-style)
|
|
93
|
+
# Single-line comment (Python-style)
|
|
94
|
+
```
|
|
85
95
|
|
|
86
|
-
|
|
96
|
+
### Semicolons
|
|
87
97
|
|
|
88
|
-
|
|
98
|
+
Semicolons are optional but recommended for clarity.
|
|
89
99
|
|
|
90
|
-
```cssl
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
```
|
|
100
|
+
```cssl
|
|
101
|
+
printl("Hello") // Works
|
|
102
|
+
printl("Hello"); // Also works (recommended)
|
|
103
|
+
```
|
|
94
104
|
|
|
95
|
-
###
|
|
105
|
+
### I/O Functions
|
|
96
106
|
|
|
97
|
-
|
|
107
|
+
```cssl
|
|
108
|
+
// Output
|
|
109
|
+
printl("Text"); // Print with newline
|
|
110
|
+
print("No newline"); // Print without newline
|
|
111
|
+
debug("Debug info"); // Print with [DEBUG] prefix
|
|
112
|
+
error("Error message"); // Print with [ERROR] prefix
|
|
113
|
+
warn("Warning"); // Print with [WARN] prefix
|
|
114
|
+
log("INFO", "Message"); // Print with custom prefix
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
// Input
|
|
117
|
+
string name = input("Enter your name: ");
|
|
118
|
+
int age = int(input("Enter your age: "));
|
|
119
|
+
string raw = input(); // Without prompt
|
|
120
|
+
```
|
|
103
121
|
|
|
104
|
-
|
|
122
|
+
---
|
|
105
123
|
|
|
106
|
-
|
|
107
|
-
printl("Text"); // Print with newline
|
|
108
|
-
print("No newline"); // Print without newline
|
|
109
|
-
debug("Debug info"); // Print with [DEBUG] prefix
|
|
110
|
-
error("Error message"); // Print with [ERROR] prefix
|
|
111
|
-
warn("Warning"); // Print with [WARN] prefix
|
|
112
|
-
log("INFO", "Message"); // Print with custom prefix
|
|
113
|
-
```
|
|
124
|
+
## Data Types
|
|
114
125
|
|
|
115
|
-
|
|
126
|
+
### Primitive Types
|
|
116
127
|
|
|
117
|
-
|
|
128
|
+
| Type | Description | Example |
|
|
129
|
+
|------|-------------|---------|
|
|
130
|
+
| `int` | Integer | `int x = 42;` |
|
|
131
|
+
| `float` | Floating point | `float f = 3.14;` |
|
|
132
|
+
| `string` | Text string | `string s = "Hello";` |
|
|
133
|
+
| `bool` | Boolean | `bool b = true;` |
|
|
134
|
+
| `dynamic` | Any type (flexible) | `dynamic x = "text";` |
|
|
135
|
+
| `void` | No return value | `void func() { }` |
|
|
136
|
+
| `null` | Absence of value | `dynamic x = null;` |
|
|
118
137
|
|
|
119
|
-
###
|
|
138
|
+
### Generic Container Types
|
|
120
139
|
|
|
121
|
-
| Type | Description | Example |
|
|
122
|
-
|------|-------------|---------|
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
| `
|
|
140
|
+
| Type | Description | Example |
|
|
141
|
+
|------|-------------|---------|
|
|
142
|
+
| `stack<T>` | LIFO stack | `stack<string> names;` |
|
|
143
|
+
| `vector<T>` | Dynamic array | `vector<int> nums;` |
|
|
144
|
+
| `array<T>` | Standard array | `array<float> values;` |
|
|
145
|
+
| `map<K,V>` | Ordered key-value | `map<string, int> ages;` |
|
|
146
|
+
| `list` | Python-like list | `list items = [1, 2, 3];` |
|
|
147
|
+
| `dict` | Dictionary | `dict data = {"a": 1};` |
|
|
148
|
+
| `datastruct<T>` | Universal container | `datastruct<string> data;` |
|
|
149
|
+
| `iterator<T>` | Programmable iterator | `iterator<int> it;` |
|
|
150
|
+
| `shuffled<T>` | Multi-value returns | `shuffled<string> results;` |
|
|
151
|
+
| `combo<T>` | Filter/search space | `combo<string> search;` |
|
|
130
152
|
|
|
131
|
-
###
|
|
153
|
+
### Type Conversion
|
|
132
154
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
| `dict` | Dictionary | `dict data = {"a": 1};` |
|
|
141
|
-
| `datastruct<T>` | Universal container | `datastruct<string> data;` |
|
|
142
|
-
| `iterator<T>` | Programmable iterator | `iterator<int> it;` |
|
|
143
|
-
| `shuffled<T>` | Multi-value returns | `shuffled<string> results;` |
|
|
144
|
-
| `combo<T>` | Filter/search space | `combo<string> search;` |
|
|
155
|
+
```cssl
|
|
156
|
+
int("42"); // String to int: 42
|
|
157
|
+
float("3.14"); // String to float: 3.14
|
|
158
|
+
str(42); // Int to string: "42"
|
|
159
|
+
bool(1); // Int to bool: true
|
|
160
|
+
int("ff", 16); // Hex to int: 255
|
|
161
|
+
```
|
|
145
162
|
|
|
146
|
-
### Type
|
|
163
|
+
### Type Checking
|
|
147
164
|
|
|
148
|
-
```cssl
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
```cssl
|
|
166
|
+
typeof(42); // "int"
|
|
167
|
+
typeof("hello"); // "str"
|
|
168
|
+
isinstance(42, "int"); // true
|
|
169
|
+
isint(42); // true
|
|
170
|
+
isstr("hello"); // true
|
|
171
|
+
isnull(null); // true
|
|
172
|
+
```
|
|
155
173
|
|
|
156
|
-
|
|
174
|
+
---
|
|
157
175
|
|
|
158
|
-
|
|
159
|
-
typeof(42); // "int"
|
|
160
|
-
typeof("hello"); // "str"
|
|
161
|
-
isinstance(42, "int"); // true
|
|
162
|
-
isint(42); // true
|
|
163
|
-
isstr("hello"); // true
|
|
164
|
-
isnull(null); // true
|
|
165
|
-
```
|
|
176
|
+
## Variables & Globals
|
|
166
177
|
|
|
167
|
-
|
|
178
|
+
### Scope Behavior
|
|
168
179
|
|
|
169
|
-
|
|
180
|
+
Variables are **local by default**. Each function/class has its own scope - variables defined inside a function only exist within that function.
|
|
170
181
|
|
|
171
|
-
|
|
182
|
+
```cssl
|
|
183
|
+
define myFunction() {
|
|
184
|
+
string name = "Alice"; // Local to myFunction
|
|
185
|
+
printl(name); // Works
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
myFunction();
|
|
189
|
+
// printl(name); // Error! 'name' doesn't exist here
|
|
172
190
|
|
|
173
|
-
|
|
191
|
+
// Same variable name in different scopes = different variables
|
|
192
|
+
string name = "Bob";
|
|
174
193
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
194
|
+
define otherFunction() {
|
|
195
|
+
string name = "Charlie"; // Different variable, local to otherFunction
|
|
196
|
+
printl(name); // "Charlie"
|
|
197
|
+
}
|
|
180
198
|
|
|
181
|
-
|
|
182
|
-
|
|
199
|
+
otherFunction();
|
|
200
|
+
printl(name); // "Bob" - outer scope unchanged
|
|
201
|
+
```
|
|
183
202
|
|
|
184
|
-
|
|
185
|
-
string name = "Bob";
|
|
203
|
+
### Everything is Local by Default
|
|
186
204
|
|
|
187
|
-
|
|
188
|
-
string name = "Charlie"; // Different variable, local to otherFunction
|
|
189
|
-
printl(name); // "Charlie"
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
otherFunction();
|
|
193
|
-
printl(name); // "Bob" - outer scope unchanged
|
|
194
|
-
```
|
|
205
|
+
All elements (variables, functions, classes) are **local by default** and must be explicitly marked global.
|
|
195
206
|
|
|
196
|
-
|
|
207
|
+
| Element | Local (default) | Global |
|
|
208
|
+
|---------|-----------------|--------|
|
|
209
|
+
| **Variables** | `string x = "text";` | `global x = "text";` or `@x = "text";` |
|
|
210
|
+
| **Functions** | `define myFunc() { }` | `global define myFunc() { }` or `define @myFunc() { }` |
|
|
211
|
+
| **Typed functions** | `void myFunc() { }` | `global void myFunc() { }` or `void @myFunc() { }` |
|
|
212
|
+
| **Classes** | `class MyClass { }` | `global class MyClass { }` or `class @MyClass { }` |
|
|
197
213
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
| Element | Local (default) | Global |
|
|
201
|
-
|---------|-----------------|--------|
|
|
202
|
-
| **Variables** | `string x = "text";` | `global x = "text";` or `@x = "text";` |
|
|
203
|
-
| **Functions** | `define myFunc() { }` | `global define myFunc() { }` or `define @myFunc() { }` |
|
|
204
|
-
| **Typed functions** | `void myFunc() { }` | `global void myFunc() { }` or `void @myFunc() { }` |
|
|
205
|
-
| **Classes** | `class MyClass { }` | `global class MyClass { }` or `class @MyClass { }` |
|
|
206
|
-
|
|
207
|
-
### Local Variables
|
|
214
|
+
### Local Variables
|
|
208
215
|
|
|
209
|
-
```cssl
|
|
210
|
-
string name = "Alice";
|
|
211
|
-
int count = 10;
|
|
212
|
-
float price = 19.99;
|
|
213
|
-
bool active = true;
|
|
214
|
-
```
|
|
216
|
+
```cssl
|
|
217
|
+
string name = "Alice";
|
|
218
|
+
int count = 10;
|
|
219
|
+
float price = 19.99;
|
|
220
|
+
bool active = true;
|
|
221
|
+
```
|
|
215
222
|
|
|
216
|
-
### Global Variables
|
|
223
|
+
### Global Variables
|
|
217
224
|
|
|
218
|
-
Use `global` keyword or `@`/`r@` prefix to create/access global variables:
|
|
225
|
+
Use `global` keyword or `@`/`r@` prefix to create/access global variables:
|
|
219
226
|
|
|
220
|
-
```cssl
|
|
221
|
-
// Declaration with 'global' keyword
|
|
222
|
-
global myGlobal = "visible everywhere";
|
|
227
|
+
```cssl
|
|
228
|
+
// Declaration with 'global' keyword
|
|
229
|
+
global myGlobal = "visible everywhere";
|
|
223
230
|
|
|
224
|
-
// Access with '@' prefix
|
|
225
|
-
printl(@myGlobal);
|
|
231
|
+
// Access with '@' prefix
|
|
232
|
+
printl(@myGlobal);
|
|
226
233
|
|
|
227
|
-
// Direct global assignment with @ or r@
|
|
228
|
-
@anotherGlobal = "also global";
|
|
229
|
-
r@yetAnother = "and this too";
|
|
234
|
+
// Direct global assignment with @ or r@
|
|
235
|
+
@anotherGlobal = "also global";
|
|
236
|
+
r@yetAnother = "and this too";
|
|
230
237
|
|
|
231
|
-
// Always read globals with @
|
|
232
|
-
printl(@x);
|
|
233
|
-
```
|
|
238
|
+
// Always read globals with @
|
|
239
|
+
printl(@x);
|
|
240
|
+
```
|
|
234
241
|
|
|
235
|
-
### Global Functions
|
|
242
|
+
### Global Functions
|
|
243
|
+
|
|
244
|
+
```cssl
|
|
245
|
+
// Global function with 'global' keyword
|
|
246
|
+
global define helper() {
|
|
247
|
+
printl("I'm global!");
|
|
248
|
+
}
|
|
236
249
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
global
|
|
240
|
-
|
|
241
|
-
}
|
|
250
|
+
// Alternative: @ prefix syntax
|
|
251
|
+
define @anotherHelper() {
|
|
252
|
+
printl("Also global!");
|
|
253
|
+
}
|
|
242
254
|
|
|
243
|
-
//
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
255
|
+
// Global typed function
|
|
256
|
+
global void @utilityFunc(string msg) {
|
|
257
|
+
printl(msg);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
247
260
|
|
|
248
|
-
|
|
249
|
-
global void @utilityFunc(string msg) {
|
|
250
|
-
printl(msg);
|
|
251
|
-
}
|
|
252
|
-
```
|
|
261
|
+
### Global Classes
|
|
253
262
|
|
|
254
|
-
|
|
263
|
+
```cssl
|
|
264
|
+
// Global class with 'global' keyword
|
|
265
|
+
global class SharedClass {
|
|
266
|
+
string value;
|
|
267
|
+
}
|
|
255
268
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}
|
|
269
|
+
// Alternative: @ prefix syntax
|
|
270
|
+
class @AnotherShared {
|
|
271
|
+
int count;
|
|
272
|
+
}
|
|
261
273
|
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
274
|
+
// Instantiate global class with @ prefix
|
|
275
|
+
instance = new @SharedClass();
|
|
276
|
+
```
|
|
266
277
|
|
|
267
|
-
|
|
268
|
-
instance = new @SharedClass();
|
|
269
|
-
```
|
|
278
|
+
### Prefix Reference
|
|
270
279
|
|
|
271
|
-
|
|
280
|
+
| Prefix | Name | Usage |
|
|
281
|
+
|--------|------|-------|
|
|
282
|
+
| `@` | Global/Module | Read global vars, access modules: `@myVar`, `@os.getcwd()` |
|
|
283
|
+
| `r@` | Global Ref | Assign to global scope: `r@name = value` |
|
|
284
|
+
| `$` | Shared | Access Python objects: `$counter.value` |
|
|
285
|
+
| `%` | Captured | Capture value at registration: `%version` |
|
|
286
|
+
| `s@` | Self-Ref | Access global structs: `s@Backend.config` |
|
|
272
287
|
|
|
273
|
-
|
|
274
|
-
|--------|------|-------|
|
|
275
|
-
| `@` | Global/Module | Read global vars, access modules: `@myVar`, `@os.getcwd()` |
|
|
276
|
-
| `r@` | Global Ref | Assign to global scope: `r@name = value` |
|
|
277
|
-
| `$` | Shared | Access Python objects: `$counter.value` |
|
|
278
|
-
| `%` | Captured | Capture value at registration: `%version` |
|
|
279
|
-
| `s@` | Self-Ref | Access global structs: `s@Backend.config` |
|
|
288
|
+
### Shared Objects ($)
|
|
280
289
|
|
|
281
|
-
|
|
290
|
+
Access Python objects shared via `CSSL.share()`:
|
|
282
291
|
|
|
283
|
-
|
|
292
|
+
```cssl
|
|
293
|
+
// Access shared Python object
|
|
294
|
+
$counter.value = 100;
|
|
295
|
+
$counter.increment();
|
|
284
296
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
$counter.increment();
|
|
297
|
+
// Delete shared object
|
|
298
|
+
delete("counter");
|
|
299
|
+
```
|
|
289
300
|
|
|
290
|
-
|
|
291
|
-
delete("counter");
|
|
292
|
-
```
|
|
301
|
+
### Captured References (%)
|
|
293
302
|
|
|
294
|
-
|
|
303
|
+
Capture value at registration time:
|
|
295
304
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
savedVersion
|
|
301
|
-
|
|
302
|
-
printl(savedVersion); // Still "1.0"
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
### Class Member Access (this->)
|
|
306
|
-
|
|
307
|
-
Inside classes, use `this->` to access instance members:
|
|
308
|
-
|
|
309
|
-
```cssl
|
|
310
|
-
class Person {
|
|
311
|
-
string name;
|
|
312
|
-
|
|
313
|
-
void setName(string n) {
|
|
314
|
-
this->name = n; // Instance member
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
---
|
|
320
|
-
|
|
321
|
-
## Operators
|
|
322
|
-
|
|
323
|
-
### Arithmetic
|
|
324
|
-
|
|
325
|
-
| Operator | Description | Example |
|
|
326
|
-
|----------|-------------|---------|
|
|
327
|
-
| `+` | Addition / Concatenation | `a + b` |
|
|
328
|
-
| `-` | Subtraction | `a - b` |
|
|
329
|
-
| `*` | Multiplication | `a * b` |
|
|
330
|
-
| `/` | Division | `a / b` |
|
|
331
|
-
| `%` | Modulo | `a % b` |
|
|
332
|
-
|
|
333
|
-
### Comparison
|
|
334
|
-
|
|
335
|
-
| Operator | Description | Example |
|
|
336
|
-
|----------|-------------|---------|
|
|
337
|
-
| `==` | Equal | `a == b` |
|
|
338
|
-
| `!=` | Not equal | `a != b` |
|
|
339
|
-
| `<` | Less than | `a < b` |
|
|
340
|
-
| `>` | Greater than | `a > b` |
|
|
341
|
-
| `<=` | Less or equal | `a <= b` |
|
|
342
|
-
| `>=` | Greater or equal | `a >= b` |
|
|
343
|
-
|
|
344
|
-
### Logical
|
|
345
|
-
|
|
346
|
-
| Operator | Description | Example |
|
|
347
|
-
|----------|-------------|---------|
|
|
348
|
-
| `&&` | AND | `a && b` |
|
|
349
|
-
| `\|\|` | OR | `a \|\| b` |
|
|
350
|
-
| `!` | NOT | `!a` |
|
|
351
|
-
| `and` | AND (keyword) | `a and b` |
|
|
352
|
-
| `or` | OR (keyword) | `a or b` |
|
|
353
|
-
| `not` | NOT (keyword) | `not a` |
|
|
354
|
-
|
|
355
|
-
### Increment/Decrement (in for-loops)
|
|
356
|
-
|
|
357
|
-
| Operator | Description | Example |
|
|
358
|
-
|----------|-------------|---------|
|
|
359
|
-
| `++` | Increment | `i++` |
|
|
360
|
-
| `--` | Decrement | `i--` |
|
|
361
|
-
| `+=` | Add assign | `i += 1` |
|
|
362
|
-
| `-=` | Subtract assign | `i -= 1` |
|
|
363
|
-
|
|
364
|
-
---
|
|
365
|
-
|
|
366
|
-
## Control Flow
|
|
367
|
-
|
|
368
|
-
### If / Else If / Else
|
|
369
|
-
|
|
370
|
-
```cssl
|
|
371
|
-
if (x < 5) {
|
|
372
|
-
printl("Small");
|
|
373
|
-
} else if (x < 15) {
|
|
374
|
-
printl("Medium");
|
|
375
|
-
} else {
|
|
376
|
-
printl("Large");
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// elif also works
|
|
380
|
-
if (x < 5) {
|
|
381
|
-
printl("Small");
|
|
382
|
-
} elif (x < 15) {
|
|
383
|
-
printl("Medium");
|
|
384
|
-
}
|
|
385
|
-
```
|
|
386
|
-
|
|
387
|
-
### Switch / Case
|
|
388
|
-
|
|
389
|
-
```cssl
|
|
390
|
-
switch (day) {
|
|
391
|
-
case 1:
|
|
392
|
-
printl("Monday");
|
|
393
|
-
break;
|
|
394
|
-
case 2:
|
|
395
|
-
printl("Tuesday");
|
|
396
|
-
break;
|
|
397
|
-
default:
|
|
398
|
-
printl("Other");
|
|
399
|
-
}
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
### While Loop
|
|
403
|
-
|
|
404
|
-
```cssl
|
|
405
|
-
int i = 0;
|
|
406
|
-
while (i < 5) {
|
|
407
|
-
printl(i);
|
|
408
|
-
i = i + 1;
|
|
409
|
-
}
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
### For Loop (Python-Style)
|
|
413
|
-
|
|
414
|
-
```cssl
|
|
415
|
-
// Range-based
|
|
416
|
-
for (i in range(5)) {
|
|
417
|
-
printl(i); // 0, 1, 2, 3, 4
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// With start and end
|
|
421
|
-
for (i in range(10, 15)) {
|
|
422
|
-
printl(i); // 10, 11, 12, 13, 14
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// With step
|
|
426
|
-
for (i in range(0, 10, 2)) {
|
|
427
|
-
printl(i); // 0, 2, 4, 6, 8
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
### For Loop (C-Style)
|
|
432
|
-
|
|
433
|
-
```cssl
|
|
434
|
-
for (int i = 0; i < 10; i++) {
|
|
435
|
-
printl(i);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
for (int i = 10; i > 0; i--) {
|
|
439
|
-
printl(i);
|
|
440
|
-
}
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
### Foreach
|
|
444
|
-
|
|
445
|
-
```cssl
|
|
446
|
-
stack<string> names;
|
|
447
|
-
names.push("Alice");
|
|
448
|
-
names.push("Bob");
|
|
449
|
-
|
|
450
|
-
// Syntax 1
|
|
451
|
-
foreach (name in names) {
|
|
452
|
-
printl(name);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Syntax 2
|
|
456
|
-
foreach names as name {
|
|
457
|
-
printl(name);
|
|
458
|
-
}
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
### Break & Continue
|
|
462
|
-
|
|
463
|
-
```cssl
|
|
464
|
-
for (i in range(10)) {
|
|
465
|
-
if (i == 5) break; // Exit loop
|
|
466
|
-
if (i == 3) continue; // Skip iteration
|
|
467
|
-
printl(i);
|
|
468
|
-
}
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
---
|
|
472
|
-
|
|
473
|
-
## Functions
|
|
474
|
-
|
|
475
|
-
### Basic Syntax
|
|
476
|
-
|
|
477
|
-
```cssl
|
|
478
|
-
// Without return
|
|
479
|
-
void sayHello() {
|
|
480
|
-
printl("Hello!");
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// With return
|
|
484
|
-
string getName() {
|
|
485
|
-
return "CSSL";
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// With parameters
|
|
489
|
-
int add(int a, int b) {
|
|
490
|
-
return a + b;
|
|
491
|
-
}
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
### Define Functions
|
|
495
|
-
|
|
496
|
-
```cssl
|
|
497
|
-
// Simple function without type
|
|
498
|
-
define greet() {
|
|
499
|
-
printl("Hello!");
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// With parameters
|
|
503
|
-
define greet(string name) {
|
|
504
|
-
printl("Hello " + name);
|
|
505
|
-
}
|
|
506
|
-
```
|
|
507
|
-
|
|
508
|
-
### Function Modifiers
|
|
509
|
-
|
|
510
|
-
| Modifier | Description |
|
|
511
|
-
|----------|-------------|
|
|
512
|
-
| `undefined` | Silently ignore errors |
|
|
513
|
-
| `closed` | Block external CodeInfusion |
|
|
514
|
-
| `private` | Block all CodeInfusion |
|
|
515
|
-
| `virtual` | Import-cycle safe |
|
|
516
|
-
| `meta` | Source function (any return type allowed) |
|
|
517
|
-
| `super` | Force execution (no exceptions) |
|
|
518
|
-
| `open` | Accept any parameters |
|
|
519
|
-
| `shuffled` | Return multiple values |
|
|
520
|
-
| `const` | Immutable function (like C++) |
|
|
521
|
-
| `static` | Static method/function |
|
|
522
|
-
| `public` | Explicitly public (default) |
|
|
523
|
-
| `global` | Makes function globally accessible |
|
|
524
|
-
|
|
525
|
-
**Flexible Modifier Order**: Modifiers can appear in any order before the function declaration.
|
|
526
|
-
|
|
527
|
-
```cssl
|
|
528
|
-
// Ignore errors
|
|
529
|
-
undefined void mayFail() {
|
|
530
|
-
riskyOperation();
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
// Protected from injection
|
|
534
|
-
closed void protected() {
|
|
535
|
-
printl("Protected");
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// Multiple returns
|
|
539
|
-
shuffled string getNames() {
|
|
540
|
-
return "Alice", "Bob", "Charlie";
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
a, b, c = getNames();
|
|
544
|
-
|
|
545
|
-
// Any order of modifiers works
|
|
546
|
-
private string *@Myfunc() {
|
|
547
|
-
println("Hello from global private non-null function!");
|
|
548
|
-
return "Hey";
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// Const function
|
|
552
|
-
const void immutableFunc() {
|
|
553
|
-
printl("I'm constant");
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// Global private const
|
|
557
|
-
global private const void @MyGlobalFunc() {
|
|
558
|
-
printl("Complex modifiers in any order");
|
|
559
|
-
}
|
|
560
|
-
```
|
|
561
|
-
|
|
562
|
-
### Typed Functions (Enforced Returns)
|
|
563
|
-
|
|
564
|
-
Functions with a return type (like `int`, `string`, `vector<T>`) MUST return that type:
|
|
565
|
-
|
|
566
|
-
```cssl
|
|
567
|
-
// MUST return string
|
|
568
|
-
string getName() {
|
|
569
|
-
return "Alice"; // OK
|
|
570
|
-
// return 42; // Error! Expected string
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// MUST return int
|
|
574
|
-
int getAge() {
|
|
575
|
-
return 30; // OK
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// meta modifier bypasses type checking
|
|
579
|
-
meta datastruct<string> getData() {
|
|
580
|
-
return "just a string"; // OK despite declared type
|
|
581
|
-
return 42; // Also OK - meta allows any type
|
|
582
|
-
}
|
|
583
|
-
```
|
|
584
|
-
|
|
585
|
-
### Non-Null Functions (*)
|
|
586
|
-
|
|
587
|
-
Functions that must never return null:
|
|
588
|
-
|
|
589
|
-
```cssl
|
|
590
|
-
// Non-null function
|
|
591
|
-
define *alwaysReturns() {
|
|
592
|
-
return "Always a value";
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
// Non-null assertion on value
|
|
596
|
-
this->name = *$System.os; // Error if null
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
### Type Exclusion Filter (*[type])
|
|
600
|
-
|
|
601
|
-
Functions that must NOT return a specific type:
|
|
602
|
-
|
|
603
|
-
```cssl
|
|
604
|
-
// Must NOT return string
|
|
605
|
-
shuffled *[string] getNumbers() {
|
|
606
|
-
return 1, 2, 3; // OK
|
|
607
|
-
// return "text"; // Error!
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
// Must NOT return null
|
|
611
|
-
define *[null] getValue() {
|
|
612
|
-
return 42; // OK
|
|
613
|
-
}
|
|
614
|
-
```
|
|
305
|
+
```cssl
|
|
306
|
+
string version = "1.0";
|
|
307
|
+
savedVersion <<== { %version; }
|
|
308
|
+
version = "2.0";
|
|
309
|
+
printl(savedVersion); // Still "1.0"
|
|
310
|
+
```
|
|
615
311
|
|
|
616
|
-
###
|
|
312
|
+
### Class Member Access (this->)
|
|
617
313
|
|
|
618
|
-
|
|
619
|
-
open define flexibleFunc(open Params) {
|
|
620
|
-
string name = OpenFind<string>(0);
|
|
621
|
-
int num = OpenFind<int>(0);
|
|
622
|
-
printl(name + " " + num);
|
|
623
|
-
}
|
|
314
|
+
Inside classes, use `this->` to access instance members:
|
|
624
315
|
|
|
625
|
-
|
|
626
|
-
|
|
316
|
+
```cssl
|
|
317
|
+
class Person {
|
|
318
|
+
string name;
|
|
627
319
|
|
|
628
|
-
|
|
320
|
+
void setName(string n) {
|
|
321
|
+
this->name = n; // Instance member
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Operators
|
|
329
|
+
|
|
330
|
+
### Arithmetic
|
|
331
|
+
|
|
332
|
+
| Operator | Description | Example |
|
|
333
|
+
|----------|-------------|---------|
|
|
334
|
+
| `+` | Addition / Concatenation | `a + b` |
|
|
335
|
+
| `-` | Subtraction | `a - b` |
|
|
336
|
+
| `*` | Multiplication | `a * b` |
|
|
337
|
+
| `/` | Division | `a / b` |
|
|
338
|
+
| `%` | Modulo | `a % b` |
|
|
339
|
+
|
|
340
|
+
### Comparison
|
|
341
|
+
|
|
342
|
+
| Operator | Description | Example |
|
|
343
|
+
|----------|-------------|---------|
|
|
344
|
+
| `==` | Equal | `a == b` |
|
|
345
|
+
| `!=` | Not equal | `a != b` |
|
|
346
|
+
| `<` | Less than | `a < b` |
|
|
347
|
+
| `>` | Greater than | `a > b` |
|
|
348
|
+
| `<=` | Less or equal | `a <= b` |
|
|
349
|
+
| `>=` | Greater or equal | `a >= b` |
|
|
350
|
+
|
|
351
|
+
### Logical
|
|
352
|
+
|
|
353
|
+
| Operator | Description | Example |
|
|
354
|
+
|----------|-------------|---------|
|
|
355
|
+
| `&&` | AND | `a && b` |
|
|
356
|
+
| `\|\|` | OR | `a \|\| b` |
|
|
357
|
+
| `!` | NOT | `!a` |
|
|
358
|
+
| `and` | AND (keyword) | `a and b` |
|
|
359
|
+
| `or` | OR (keyword) | `a or b` |
|
|
360
|
+
| `not` | NOT (keyword) | `not a` |
|
|
361
|
+
|
|
362
|
+
### Increment/Decrement (in for-loops)
|
|
363
|
+
|
|
364
|
+
| Operator | Description | Example |
|
|
365
|
+
|----------|-------------|---------|
|
|
366
|
+
| `++` | Increment | `i++` |
|
|
367
|
+
| `--` | Decrement | `i--` |
|
|
368
|
+
| `+=` | Add assign | `i += 1` |
|
|
369
|
+
| `-=` | Subtract assign | `i -= 1` |
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
## Control Flow
|
|
374
|
+
|
|
375
|
+
### If / Else If / Else
|
|
376
|
+
|
|
377
|
+
```cssl
|
|
378
|
+
if (x < 5) {
|
|
379
|
+
printl("Small");
|
|
380
|
+
} else if (x < 15) {
|
|
381
|
+
printl("Medium");
|
|
382
|
+
} else {
|
|
383
|
+
printl("Large");
|
|
384
|
+
}
|
|
629
385
|
|
|
630
|
-
|
|
386
|
+
// elif also works
|
|
387
|
+
if (x < 5) {
|
|
388
|
+
printl("Small");
|
|
389
|
+
} elif (x < 15) {
|
|
390
|
+
printl("Medium");
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Switch / Case
|
|
395
|
+
|
|
396
|
+
```cssl
|
|
397
|
+
switch (day) {
|
|
398
|
+
case 1:
|
|
399
|
+
printl("Monday");
|
|
400
|
+
break;
|
|
401
|
+
case 2:
|
|
402
|
+
printl("Tuesday");
|
|
403
|
+
break;
|
|
404
|
+
default:
|
|
405
|
+
printl("Other");
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Parameter Switch (Open Params)
|
|
410
|
+
|
|
411
|
+
Pattern matching on which named parameters were provided to a function.
|
|
412
|
+
|
|
413
|
+
```cssl
|
|
414
|
+
define greet(...) {
|
|
415
|
+
switch (open) {
|
|
416
|
+
case name & age:
|
|
417
|
+
printl("Hello " + OpenFind<string, "name"> + ", age " + OpenFind<int, "age">);
|
|
418
|
+
case name:
|
|
419
|
+
printl("Hello " + OpenFind<string, "name">);
|
|
420
|
+
except name:
|
|
421
|
+
printl("No name provided!");
|
|
422
|
+
default:
|
|
423
|
+
printl("Unknown parameters");
|
|
424
|
+
always:
|
|
425
|
+
printl("-- greeting complete --");
|
|
426
|
+
finally:
|
|
427
|
+
printl("== cleanup ==");
|
|
428
|
+
}
|
|
429
|
+
}
|
|
631
430
|
|
|
632
|
-
|
|
431
|
+
greet(name="Alice"); // case name matches
|
|
432
|
+
greet(name="Bob", age=25); // case name & age matches
|
|
433
|
+
greet(foo="bar"); // except name matches (no name)
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
**Syntax:**
|
|
437
|
+
- `case param:` - executes if parameter exists
|
|
438
|
+
- `case param1 & param2:` - executes if ALL parameters exist
|
|
439
|
+
- `case param1 & not param2:` - AND with negation
|
|
440
|
+
- `except param:` - executes if parameter does NOT exist
|
|
441
|
+
- `default:` - executes if no case matched
|
|
442
|
+
- `always:` - executes after any matching case (not after except/default)
|
|
443
|
+
- `finally:` - always executes (cleanup, like try/finally)
|
|
444
|
+
|
|
445
|
+
> **Note:** Cases are checked in order. Place more specific cases first (`case name & age` before `case name`).
|
|
446
|
+
|
|
447
|
+
### While Loop
|
|
448
|
+
|
|
449
|
+
```cssl
|
|
450
|
+
int i = 0;
|
|
451
|
+
while (i < 5) {
|
|
452
|
+
printl(i);
|
|
453
|
+
i = i + 1;
|
|
454
|
+
}
|
|
455
|
+
```
|
|
633
456
|
|
|
634
|
-
|
|
635
|
-
class Person {
|
|
636
|
-
string name;
|
|
637
|
-
int age;
|
|
457
|
+
### For Loop (Python-Style)
|
|
638
458
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
459
|
+
```cssl
|
|
460
|
+
// Range-based
|
|
461
|
+
for (i in range(5)) {
|
|
462
|
+
printl(i); // 0, 1, 2, 3, 4
|
|
643
463
|
}
|
|
644
464
|
|
|
645
|
-
|
|
646
|
-
|
|
465
|
+
// With start and end
|
|
466
|
+
for (i in range(10, 15)) {
|
|
467
|
+
printl(i); // 10, 11, 12, 13, 14
|
|
647
468
|
}
|
|
648
469
|
|
|
470
|
+
// With step
|
|
471
|
+
for (i in range(0, 10, 2)) {
|
|
472
|
+
printl(i); // 0, 2, 4, 6, 8
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
### For Loop (C-Style)
|
|
477
|
+
|
|
478
|
+
```cssl
|
|
479
|
+
for (int i = 0; i < 10; i++) {
|
|
480
|
+
printl(i);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
for (int i = 10; i > 0; i--) {
|
|
484
|
+
printl(i);
|
|
485
|
+
}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
### Foreach
|
|
489
|
+
|
|
490
|
+
```cssl
|
|
491
|
+
stack<string> names;
|
|
492
|
+
names.push("Alice");
|
|
493
|
+
names.push("Bob");
|
|
494
|
+
|
|
495
|
+
// Syntax 1
|
|
496
|
+
foreach (name in names) {
|
|
497
|
+
printl(name);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Syntax 2
|
|
501
|
+
foreach names as name {
|
|
502
|
+
printl(name);
|
|
503
|
+
}
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### Break & Continue
|
|
507
|
+
|
|
508
|
+
```cssl
|
|
509
|
+
for (i in range(10)) {
|
|
510
|
+
if (i == 5) break; // Exit loop
|
|
511
|
+
if (i == 3) continue; // Skip iteration
|
|
512
|
+
printl(i);
|
|
513
|
+
}
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
## Functions
|
|
519
|
+
|
|
520
|
+
### Basic Syntax
|
|
521
|
+
|
|
522
|
+
```cssl
|
|
523
|
+
// Without return
|
|
524
|
+
void sayHello() {
|
|
525
|
+
printl("Hello!");
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// With return
|
|
529
|
+
string getName() {
|
|
530
|
+
return "CSSL";
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// With parameters
|
|
534
|
+
int add(int a, int b) {
|
|
535
|
+
return a + b;
|
|
536
|
+
}
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
### Define Functions
|
|
540
|
+
|
|
541
|
+
```cssl
|
|
542
|
+
// Simple function without type
|
|
543
|
+
define greet() {
|
|
544
|
+
printl("Hello!");
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// With parameters
|
|
548
|
+
define greet(string name) {
|
|
549
|
+
printl("Hello " + name);
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
### Function Modifiers
|
|
554
|
+
|
|
555
|
+
| Modifier | Description |
|
|
556
|
+
|----------|-------------|
|
|
557
|
+
| `undefined` | Silently ignore errors |
|
|
558
|
+
| `closed` | Block external CodeInfusion |
|
|
559
|
+
| `private` | Block all CodeInfusion |
|
|
560
|
+
| `virtual` | Import-cycle safe |
|
|
561
|
+
| `meta` | Source function (any return type allowed) |
|
|
562
|
+
| `super` | Force execution (no exceptions) |
|
|
563
|
+
| `open` | Accept any parameters |
|
|
564
|
+
| `shuffled` | Return multiple values |
|
|
565
|
+
| `const` | Immutable function (like C++) |
|
|
566
|
+
| `static` | Static method/function |
|
|
567
|
+
| `public` | Explicitly public (default) |
|
|
568
|
+
| `global` | Makes function globally accessible |
|
|
569
|
+
|
|
570
|
+
**Flexible Modifier Order**: Modifiers can appear in any order before the function declaration.
|
|
571
|
+
|
|
572
|
+
```cssl
|
|
573
|
+
// Ignore errors
|
|
574
|
+
undefined void mayFail() {
|
|
575
|
+
riskyOperation();
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Protected from injection
|
|
579
|
+
closed void protected() {
|
|
580
|
+
printl("Protected");
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
// Multiple returns
|
|
584
|
+
shuffled string getNames() {
|
|
585
|
+
return "Alice", "Bob", "Charlie";
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
a, b, c = getNames();
|
|
589
|
+
|
|
590
|
+
// Any order of modifiers works
|
|
591
|
+
private string *@Myfunc() {
|
|
592
|
+
println("Hello from global private non-null function!");
|
|
593
|
+
return "Hey";
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Const function
|
|
597
|
+
const void immutableFunc() {
|
|
598
|
+
printl("I'm constant");
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Global private const
|
|
602
|
+
global private const void @MyGlobalFunc() {
|
|
603
|
+
printl("Complex modifiers in any order");
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
### Typed Functions (Enforced Returns)
|
|
608
|
+
|
|
609
|
+
Functions with a return type (like `int`, `string`, `vector<T>`) MUST return that type:
|
|
610
|
+
|
|
611
|
+
```cssl
|
|
612
|
+
// MUST return string
|
|
649
613
|
string getName() {
|
|
650
|
-
return
|
|
614
|
+
return "Alice"; // OK
|
|
615
|
+
// return 42; // Error! Expected string
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// MUST return int
|
|
619
|
+
int getAge() {
|
|
620
|
+
return 30; // OK
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// meta modifier bypasses type checking
|
|
624
|
+
meta datastruct<string> getData() {
|
|
625
|
+
return "just a string"; // OK despite declared type
|
|
626
|
+
return 42; // Also OK - meta allows any type
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
### Non-Null Functions (*)
|
|
631
|
+
|
|
632
|
+
Functions that must never return null:
|
|
633
|
+
|
|
634
|
+
```cssl
|
|
635
|
+
// Non-null function
|
|
636
|
+
define *alwaysReturns() {
|
|
637
|
+
return "Always a value";
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Non-null assertion on value
|
|
641
|
+
this->name = *$System.os; // Error if null
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
### Type Exclusion Filter (*[type])
|
|
645
|
+
|
|
646
|
+
Functions that must NOT return a specific type:
|
|
647
|
+
|
|
648
|
+
```cssl
|
|
649
|
+
// Must NOT return string
|
|
650
|
+
shuffled *[string] getNumbers() {
|
|
651
|
+
return 1, 2, 3; // OK
|
|
652
|
+
// return "text"; // Error!
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
// Must NOT return null
|
|
656
|
+
define *[null] getValue() {
|
|
657
|
+
return 42; // OK
|
|
658
|
+
}
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
### Open Parameters
|
|
662
|
+
|
|
663
|
+
```cssl
|
|
664
|
+
open define flexibleFunc(open Params) {
|
|
665
|
+
string name = OpenFind<string>(0);
|
|
666
|
+
int num = OpenFind<int>(0);
|
|
667
|
+
printl(name + " " + num);
|
|
651
668
|
}
|
|
652
|
-
}
|
|
653
|
-
```
|
|
654
669
|
|
|
655
|
-
|
|
670
|
+
flexibleFunc("Hello", 123, true);
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
---
|
|
674
|
+
|
|
675
|
+
## Classes & OOP
|
|
656
676
|
|
|
657
|
-
|
|
658
|
-
Person p = new Person("Alice", 30);
|
|
659
|
-
p.greet();
|
|
660
|
-
printl(p.name);
|
|
661
|
-
```
|
|
677
|
+
### Class Definition
|
|
662
678
|
|
|
663
|
-
|
|
679
|
+
```cssl
|
|
680
|
+
class Person {
|
|
681
|
+
string name;
|
|
682
|
+
int age;
|
|
664
683
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
684
|
+
// Constructor
|
|
685
|
+
void Person(string n, int a) {
|
|
686
|
+
this->name = n;
|
|
687
|
+
this->age = a;
|
|
688
|
+
}
|
|
668
689
|
|
|
669
|
-
|
|
670
|
-
|
|
690
|
+
void greet() {
|
|
691
|
+
printl("Hello, I'm " + this->name);
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
string getName() {
|
|
695
|
+
return this->name;
|
|
696
|
+
}
|
|
671
697
|
}
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
### Creating Instances
|
|
672
701
|
|
|
673
|
-
|
|
674
|
-
|
|
702
|
+
```cssl
|
|
703
|
+
Person p = new Person("Alice", 30);
|
|
704
|
+
p.greet();
|
|
705
|
+
printl(p.name);
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
### Constructor with `constr` Keyword
|
|
709
|
+
|
|
710
|
+
```cssl
|
|
711
|
+
class Vehicle {
|
|
712
|
+
string brand;
|
|
713
|
+
|
|
714
|
+
constr Initialize(string b) {
|
|
715
|
+
this->brand = b;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
constr SetupDefaults() {
|
|
719
|
+
printl("Vehicle ready");
|
|
720
|
+
}
|
|
675
721
|
}
|
|
676
|
-
}
|
|
677
722
|
|
|
678
|
-
Vehicle v = new Vehicle("Toyota");
|
|
679
|
-
```
|
|
723
|
+
Vehicle v = new Vehicle("Toyota");
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### Class Inheritance
|
|
680
727
|
|
|
681
|
-
|
|
728
|
+
```cssl
|
|
729
|
+
class Animal {
|
|
730
|
+
string name;
|
|
682
731
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
732
|
+
void Animal(string n) {
|
|
733
|
+
this->name = n;
|
|
734
|
+
}
|
|
686
735
|
|
|
687
|
-
|
|
688
|
-
|
|
736
|
+
void speak() {
|
|
737
|
+
printl("Sound");
|
|
738
|
+
}
|
|
689
739
|
}
|
|
690
740
|
|
|
691
|
-
|
|
692
|
-
|
|
741
|
+
class Dog : extends Animal {
|
|
742
|
+
void Dog(string n) {
|
|
743
|
+
this->name = n;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
void speak() {
|
|
747
|
+
printl("Woof! I'm " + this->name);
|
|
748
|
+
}
|
|
693
749
|
}
|
|
694
|
-
}
|
|
695
750
|
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
751
|
+
Dog d = new Dog("Buddy");
|
|
752
|
+
d.speak(); // "Woof! I'm Buddy"
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
### super() and super::method()
|
|
756
|
+
|
|
757
|
+
```cssl
|
|
758
|
+
class Child : extends Parent {
|
|
759
|
+
constr ChildInit(string name) {
|
|
760
|
+
super(name); // Call parent constructor
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
void speak() {
|
|
764
|
+
super::speak(); // Call parent method
|
|
765
|
+
printl("Child speaking");
|
|
766
|
+
}
|
|
699
767
|
}
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### Append Mode (++)
|
|
700
771
|
|
|
701
|
-
|
|
702
|
-
|
|
772
|
+
Extend constructors/functions while keeping original code:
|
|
773
|
+
|
|
774
|
+
```cssl
|
|
775
|
+
// Original function
|
|
776
|
+
define BaseFunc() {
|
|
777
|
+
printl("Base functionality");
|
|
703
778
|
}
|
|
704
|
-
}
|
|
705
779
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
780
|
+
// Append to BaseFunc
|
|
781
|
+
define ExtendedFunc() &BaseFunc ++ {
|
|
782
|
+
printl("Extended functionality");
|
|
783
|
+
}
|
|
709
784
|
|
|
710
|
-
|
|
785
|
+
ExtendedFunc();
|
|
786
|
+
// Output:
|
|
787
|
+
// Base functionality
|
|
788
|
+
// Extended functionality
|
|
789
|
+
```
|
|
790
|
+
|
|
791
|
+
```cssl
|
|
792
|
+
class MyClass {
|
|
793
|
+
constr MyClassConstructor() {
|
|
794
|
+
printl("MyClass constructor");
|
|
795
|
+
this->value = 10;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
711
798
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
799
|
+
class BetterClass :: extends MyClass {
|
|
800
|
+
constr BetterConstructor() &MyClass::MyClassConstructor ++ {
|
|
801
|
+
printl("BetterClass - added code");
|
|
802
|
+
this->extra = 20;
|
|
803
|
+
}
|
|
716
804
|
}
|
|
805
|
+
```
|
|
717
806
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
807
|
+
### Non-Null Class
|
|
808
|
+
|
|
809
|
+
```cssl
|
|
810
|
+
class *MyClass {
|
|
811
|
+
// All methods must return non-null
|
|
812
|
+
string getValue() {
|
|
813
|
+
return "Value";
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
```
|
|
817
|
+
|
|
818
|
+
---
|
|
819
|
+
|
|
820
|
+
## Container Types
|
|
821
|
+
|
|
822
|
+
### stack\<T\> - LIFO Stack
|
|
823
|
+
|
|
824
|
+
```cssl
|
|
825
|
+
stack<string> names;
|
|
826
|
+
names.push("Alice");
|
|
827
|
+
names.push("Bob");
|
|
828
|
+
|
|
829
|
+
printl(names.pop()); // "Bob"
|
|
830
|
+
printl(names.peek()); // "Alice" (doesn't remove)
|
|
831
|
+
printl(names.size()); // 1
|
|
832
|
+
printl(names.isEmpty()); // false
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
**Methods:**
|
|
836
|
+
|
|
837
|
+
| Method | Description |
|
|
838
|
+
|--------|-------------|
|
|
839
|
+
| `push(value)` | Add to top |
|
|
840
|
+
| `pop()` | Remove and return top |
|
|
841
|
+
| `peek()` | View top without removing |
|
|
842
|
+
| `size()` / `length()` | Element count |
|
|
843
|
+
| `isEmpty()` / `is_empty()` | Check if empty |
|
|
844
|
+
| `contains(value)` | Check if contains |
|
|
845
|
+
| `indexOf(value)` | Find index (-1 if not found) |
|
|
846
|
+
| `toArray()` | Convert to list |
|
|
847
|
+
| `swap()` | Swap top two elements |
|
|
848
|
+
| `dup()` | Duplicate top element |
|
|
849
|
+
|
|
850
|
+
### vector\<T\> - Dynamic Array
|
|
851
|
+
|
|
852
|
+
```cssl
|
|
853
|
+
vector<int> nums;
|
|
854
|
+
nums.push(10);
|
|
855
|
+
nums.push(20);
|
|
856
|
+
|
|
857
|
+
printl(nums.at(0)); // 10
|
|
858
|
+
printl(nums.front()); // 10
|
|
859
|
+
printl(nums.back()); // 20
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
**Methods:**
|
|
863
|
+
|
|
864
|
+
| Method | Description |
|
|
865
|
+
|--------|-------------|
|
|
866
|
+
| `push(value)` / `push_back(value)` | Add to end |
|
|
867
|
+
| `push_front(value)` | Add to front |
|
|
868
|
+
| `pop_back()` | Remove from end |
|
|
869
|
+
| `pop_front()` | Remove from front |
|
|
870
|
+
| `at(index)` | Get element |
|
|
871
|
+
| `set(index, value)` | Set element |
|
|
872
|
+
| `front()` | Get first |
|
|
873
|
+
| `back()` | Get last |
|
|
874
|
+
| `size()` / `length()` | Element count |
|
|
875
|
+
| `empty()` / `isEmpty()` | Check if empty |
|
|
876
|
+
| `contains(value)` | Check if contains |
|
|
877
|
+
| `indexOf(value)` | Find first index |
|
|
878
|
+
| `lastIndexOf(value)` | Find last index |
|
|
879
|
+
| `slice(start, end)` | Get sub-vector |
|
|
880
|
+
| `join(separator)` | Join to string |
|
|
881
|
+
| `map(func)` | Apply function |
|
|
882
|
+
| `filter(predicate)` | Filter elements |
|
|
883
|
+
| `forEach(func)` | Execute for each |
|
|
884
|
+
| `every(predicate)` | Check all match |
|
|
885
|
+
| `some(predicate)` | Check any match |
|
|
886
|
+
| `reduce(func, initial)` | Reduce to value |
|
|
887
|
+
| `toArray()` | Convert to list |
|
|
888
|
+
|
|
889
|
+
### map\<K,V\> - Ordered Key-Value
|
|
890
|
+
|
|
891
|
+
```cssl
|
|
892
|
+
map<string, int> ages;
|
|
893
|
+
ages.insert("Alice", 30);
|
|
894
|
+
ages.insert("Bob", 25);
|
|
895
|
+
|
|
896
|
+
printl(ages.find("Alice")); // 30
|
|
897
|
+
printl(ages.contains("Bob")); // true
|
|
898
|
+
ages.erase("Bob");
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
**Methods:**
|
|
902
|
+
|
|
903
|
+
| Method | Description |
|
|
904
|
+
|--------|-------------|
|
|
905
|
+
| `insert(key, value)` | Insert/update pair |
|
|
906
|
+
| `find(key)` | Get value (null if not found) |
|
|
907
|
+
| `at(key)` | Get value (throws if not found) |
|
|
908
|
+
| `erase(key)` | Remove key |
|
|
909
|
+
| `contains(key)` | Check if key exists |
|
|
910
|
+
| `count(key)` | Count (0 or 1) |
|
|
911
|
+
| `size()` | Pair count |
|
|
912
|
+
| `empty()` | Check if empty |
|
|
913
|
+
| `begin()` | First key-value tuple |
|
|
914
|
+
| `end()` | Last key-value tuple |
|
|
915
|
+
| `lower_bound(key)` | First key >= given |
|
|
916
|
+
| `upper_bound(key)` | First key > given |
|
|
917
|
+
|
|
918
|
+
### datastruct\<T\> - Universal Container
|
|
919
|
+
|
|
920
|
+
Primary target for BruteInjection operations.
|
|
921
|
+
|
|
922
|
+
```cssl
|
|
923
|
+
datastruct<string> data;
|
|
924
|
+
data.add("item1");
|
|
925
|
+
data.add("item2");
|
|
926
|
+
|
|
927
|
+
printl(data.content()); // All elements
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
**Methods:**
|
|
931
|
+
|
|
932
|
+
| Method | Description |
|
|
933
|
+
|--------|-------------|
|
|
934
|
+
| `content()` | Get all elements |
|
|
935
|
+
| `add(value)` | Add element |
|
|
936
|
+
| `remove_where(predicate)` | Remove matching |
|
|
937
|
+
| `find_where(predicate)` | Find first matching |
|
|
938
|
+
| `convert(type)` | Convert first element |
|
|
939
|
+
|
|
940
|
+
### shuffled\<T\> - Multiple Returns
|
|
941
|
+
|
|
942
|
+
```cssl
|
|
943
|
+
shuffled string getInfo() {
|
|
944
|
+
return "Alice", "Bob", "Charlie";
|
|
721
945
|
}
|
|
722
|
-
}
|
|
723
|
-
```
|
|
724
946
|
|
|
725
|
-
|
|
947
|
+
a, b, c = getInfo();
|
|
948
|
+
printl(a); // "Alice"
|
|
949
|
+
```
|
|
950
|
+
|
|
951
|
+
---
|
|
952
|
+
|
|
953
|
+
## Built-in Functions
|
|
954
|
+
|
|
955
|
+
### String Operations
|
|
956
|
+
|
|
957
|
+
```cssl
|
|
958
|
+
string s = "Hello World";
|
|
959
|
+
|
|
960
|
+
// Case
|
|
961
|
+
upper(s); // "HELLO WORLD"
|
|
962
|
+
lower(s); // "hello world"
|
|
963
|
+
capitalize(s); // "Hello world"
|
|
964
|
+
title(s); // "Hello World"
|
|
965
|
+
|
|
966
|
+
// Trim
|
|
967
|
+
trim(" text "); // "text"
|
|
968
|
+
ltrim(" text"); // "text"
|
|
969
|
+
rtrim("text "); // "text"
|
|
970
|
+
|
|
971
|
+
// Search
|
|
972
|
+
contains(s, "World"); // true
|
|
973
|
+
startswith(s, "Hello"); // true
|
|
974
|
+
endswith(s, "World"); // true
|
|
975
|
+
indexof(s, "o"); // 4
|
|
976
|
+
lastindexof(s, "o"); // 7
|
|
977
|
+
|
|
978
|
+
// Manipulation
|
|
979
|
+
replace(s, "World", "CSSL"); // "Hello CSSL"
|
|
980
|
+
substr(s, 0, 5); // "Hello"
|
|
981
|
+
split(s, " "); // ["Hello", "World"]
|
|
982
|
+
join("-", ["a", "b"]); // "a-b"
|
|
983
|
+
repeat("ab", 3); // "ababab"
|
|
984
|
+
reverse(s); // "dlroW olleH"
|
|
985
|
+
|
|
986
|
+
// Padding
|
|
987
|
+
padleft("42", 5, "0"); // "00042"
|
|
988
|
+
padright("42", 5, "."); // "42..."
|
|
989
|
+
center("hi", 6, "-"); // "--hi--"
|
|
990
|
+
zfill("42", 5); // "00042"
|
|
991
|
+
|
|
992
|
+
// Character
|
|
993
|
+
len(s); // 11
|
|
994
|
+
chars("abc"); // ["a", "b", "c"]
|
|
995
|
+
ord("A"); // 65
|
|
996
|
+
chr(65); // "A"
|
|
997
|
+
|
|
998
|
+
// Checks
|
|
999
|
+
isalpha("abc"); // true
|
|
1000
|
+
isdigit("123"); // true
|
|
1001
|
+
isalnum("abc123"); // true
|
|
1002
|
+
isspace(" "); // true
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
### Array/List Operations
|
|
1006
|
+
|
|
1007
|
+
```cssl
|
|
1008
|
+
stack<int> arr = [1, 2, 3, 4, 5];
|
|
1009
|
+
|
|
1010
|
+
// Add/Remove
|
|
1011
|
+
push(arr, 6); // Add to end
|
|
1012
|
+
pop(arr); // Remove last
|
|
1013
|
+
shift(arr); // Remove first
|
|
1014
|
+
unshift(arr, 0); // Add to front
|
|
1015
|
+
|
|
1016
|
+
// Access
|
|
1017
|
+
first(arr); // First element
|
|
1018
|
+
last(arr); // Last element
|
|
1019
|
+
slice(arr, 1, 3); // [2, 3]
|
|
1020
|
+
|
|
1021
|
+
// Transform
|
|
1022
|
+
sort(arr); // Sort ascending
|
|
1023
|
+
rsort(arr); // Sort descending
|
|
1024
|
+
reversed(arr); // Reverse copy
|
|
1025
|
+
shuffle(arr); // Random order
|
|
1026
|
+
unique(arr); // Remove duplicates
|
|
1027
|
+
flatten([[1,2],[3,4]]); // [1, 2, 3, 4]
|
|
1028
|
+
|
|
1029
|
+
// Search
|
|
1030
|
+
find(arr, x => x > 3); // First matching
|
|
1031
|
+
findindex(arr, x => x > 3);
|
|
1032
|
+
every(arr, x => x > 0); // All match?
|
|
1033
|
+
some(arr, x => x > 3); // Any match?
|
|
1034
|
+
count(arr, 2); // Count of 2
|
|
1035
|
+
|
|
1036
|
+
// Functional
|
|
1037
|
+
map(arr, x => x * 2); // [2, 4, 6, 8, 10]
|
|
1038
|
+
filter(arr, x => x > 2); // [3, 4, 5]
|
|
1039
|
+
reduce(arr, (a,b) => a+b, 0); // 15
|
|
1040
|
+
|
|
1041
|
+
// Utilities
|
|
1042
|
+
range(5); // [0, 1, 2, 3, 4]
|
|
1043
|
+
range(1, 5); // [1, 2, 3, 4]
|
|
1044
|
+
range(0, 10, 2); // [0, 2, 4, 6, 8]
|
|
1045
|
+
enumerate(arr); // [(0,1), (1,2), ...]
|
|
1046
|
+
zip([1,2], ["a","b"]); // [(1,"a"), (2,"b")]
|
|
1047
|
+
take(arr, 3); // First 3 elements
|
|
1048
|
+
drop(arr, 2); // Skip first 2
|
|
1049
|
+
chunk(arr, 2); // [[1,2], [3,4], [5]]
|
|
1050
|
+
sample(arr, 2); // 2 random elements
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
### Dictionary Operations
|
|
1054
|
+
|
|
1055
|
+
```cssl
|
|
1056
|
+
dict d = {"name": "Alice", "age": 30};
|
|
1057
|
+
|
|
1058
|
+
keys(d); // ["name", "age"]
|
|
1059
|
+
values(d); // ["Alice", 30]
|
|
1060
|
+
items(d); // [("name","Alice"), ...]
|
|
1061
|
+
haskey(d, "name"); // true
|
|
1062
|
+
getkey(d, "name"); // "Alice"
|
|
1063
|
+
getkey(d, "x", "default"); // "default"
|
|
1064
|
+
setkey(d, "city", "NYC"); // Add key
|
|
1065
|
+
delkey(d, "age"); // Remove key
|
|
1066
|
+
merge(d1, d2); // Merge dicts
|
|
1067
|
+
update(d, {"new": 1}); // Update in place
|
|
1068
|
+
fromkeys(["a","b"], 0); // {"a": 0, "b": 0}
|
|
1069
|
+
invert({"a": 1}); // {1: "a"}
|
|
1070
|
+
pick(d, "name"); // {"name": "Alice"}
|
|
1071
|
+
omit(d, "age"); // {"name": "Alice"}
|
|
1072
|
+
```
|
|
1073
|
+
|
|
1074
|
+
### Math Functions
|
|
1075
|
+
|
|
1076
|
+
```cssl
|
|
1077
|
+
abs(-5); // 5
|
|
1078
|
+
min(3, 1, 2); // 1
|
|
1079
|
+
max(3, 1, 2); // 3
|
|
1080
|
+
sum([1, 2, 3]); // 6
|
|
1081
|
+
avg([1, 2, 3, 4, 5]); // 3.0
|
|
1082
|
+
|
|
1083
|
+
round(3.14159, 2); // 3.14
|
|
1084
|
+
floor(3.9); // 3
|
|
1085
|
+
ceil(3.1); // 4
|
|
1086
|
+
|
|
1087
|
+
pow(2, 3); // 8
|
|
1088
|
+
sqrt(16); // 4
|
|
1089
|
+
mod(7, 3); // 1
|
|
1090
|
+
|
|
1091
|
+
sin(0); // 0.0
|
|
1092
|
+
cos(0); // 1.0
|
|
1093
|
+
tan(0); // 0.0
|
|
1094
|
+
asin(1); // 1.5708
|
|
1095
|
+
acos(0); // 1.5708
|
|
1096
|
+
atan(1); // 0.7854
|
|
1097
|
+
atan2(1, 1); // 0.7854
|
|
1098
|
+
|
|
1099
|
+
log(e()); // 1.0
|
|
1100
|
+
log10(100); // 2.0
|
|
1101
|
+
exp(1); // 2.71828
|
|
1102
|
+
|
|
1103
|
+
pi(); // 3.14159...
|
|
1104
|
+
e(); // 2.71828...
|
|
1105
|
+
radians(180); // 3.14159
|
|
1106
|
+
degrees(3.14159); // 180
|
|
1107
|
+
|
|
1108
|
+
random(); // 0.0 to 1.0
|
|
1109
|
+
randint(1, 6); // 1 to 6
|
|
1110
|
+
```
|
|
1111
|
+
|
|
1112
|
+
### Date/Time Functions
|
|
1113
|
+
|
|
1114
|
+
```cssl
|
|
1115
|
+
now(); // Unix timestamp (float)
|
|
1116
|
+
timestamp(); // Unix timestamp (int)
|
|
1117
|
+
date(); // "2025-12-30"
|
|
1118
|
+
date("%d/%m/%Y"); // "30/12/2025"
|
|
1119
|
+
time(); // "14:30:45"
|
|
1120
|
+
datetime(); // "2025-12-30 14:30:45"
|
|
1121
|
+
strftime("%Y-%m-%d", ts);
|
|
1122
|
+
|
|
1123
|
+
sleep(1.5); // Wait 1.5 seconds
|
|
1124
|
+
delay(500); // Wait 500 milliseconds
|
|
1125
|
+
```
|
|
1126
|
+
|
|
1127
|
+
### File I/O Functions
|
|
1128
|
+
|
|
1129
|
+
```cssl
|
|
1130
|
+
// Read
|
|
1131
|
+
string content = read("file.txt");
|
|
1132
|
+
string line5 = readline(5, "file.txt");
|
|
1133
|
+
stack<string> lines = readlines("file.txt");
|
|
1134
|
+
|
|
1135
|
+
// Write
|
|
1136
|
+
write("file.txt", "Hello");
|
|
1137
|
+
writeline(3, "New line", "file.txt");
|
|
1138
|
+
appendfile("file.txt", "\nMore");
|
|
1139
|
+
|
|
1140
|
+
// Path operations
|
|
1141
|
+
basename("/path/to/file.txt"); // "file.txt"
|
|
1142
|
+
dirname("/path/to/file.txt"); // "/path/to"
|
|
1143
|
+
joinpath("/path", "file.txt"); // "/path/file.txt"
|
|
1144
|
+
abspath("./file.txt");
|
|
1145
|
+
normpath("/path/../other");
|
|
1146
|
+
|
|
1147
|
+
// Checks
|
|
1148
|
+
pathexists("file.txt"); // true/false
|
|
1149
|
+
isfile("file.txt"); // true/false
|
|
1150
|
+
isdir("folder"); // true/false
|
|
1151
|
+
filesize("file.txt"); // bytes
|
|
1152
|
+
|
|
1153
|
+
// Directory
|
|
1154
|
+
listdir("./"); // ["file1", "file2"]
|
|
1155
|
+
makedirs("new/folder");
|
|
1156
|
+
removefile("file.txt");
|
|
1157
|
+
removedir("folder");
|
|
1158
|
+
copyfile("src", "dst");
|
|
1159
|
+
movefile("old", "new");
|
|
1160
|
+
```
|
|
1161
|
+
|
|
1162
|
+
### JSON Functions (json:: namespace)
|
|
1163
|
+
|
|
1164
|
+
```cssl
|
|
1165
|
+
// File operations
|
|
1166
|
+
json data = json::read("config.json");
|
|
1167
|
+
json::write("output.json", data);
|
|
1168
|
+
|
|
1169
|
+
// Parse/Stringify
|
|
1170
|
+
json obj = json::parse('{"name": "Alice"}');
|
|
1171
|
+
string str = json::stringify(obj);
|
|
1172
|
+
string pretty = json::pretty(obj);
|
|
1173
|
+
|
|
1174
|
+
// Path operations
|
|
1175
|
+
json::get(data, "user.name");
|
|
1176
|
+
json::get(data, "user.age", 0); // with default
|
|
1177
|
+
json::set(data, "user.name", "Bob");
|
|
1178
|
+
json::has(data, "user.email");
|
|
1179
|
+
|
|
1180
|
+
// Object operations
|
|
1181
|
+
json::keys(obj); // ["name"]
|
|
1182
|
+
json::values(obj); // ["Alice"]
|
|
1183
|
+
json::merge(obj1, obj2); // Deep merge
|
|
1184
|
+
```
|
|
1185
|
+
|
|
1186
|
+
### Instance Functions (instance:: namespace)
|
|
1187
|
+
|
|
1188
|
+
```cssl
|
|
1189
|
+
@module = include("lib.cssl-mod");
|
|
1190
|
+
|
|
1191
|
+
instance::getMethods(@module); // Method names
|
|
1192
|
+
instance::getClasses(@module); // Class names
|
|
1193
|
+
instance::getVars(@module); // Variable names
|
|
1194
|
+
instance::getAll(@module); // Categorized dict
|
|
1195
|
+
|
|
1196
|
+
instance::call(@module, "methodName", arg1);
|
|
1197
|
+
instance::has(@module, "attribute");
|
|
1198
|
+
instance::type(@module); // Type name
|
|
1199
|
+
|
|
1200
|
+
isavailable("sharedName"); // Check if exists
|
|
1201
|
+
```
|
|
1202
|
+
|
|
1203
|
+
### Regex Functions
|
|
1204
|
+
|
|
1205
|
+
```cssl
|
|
1206
|
+
match("\\d+", "abc123"); // Match at start
|
|
1207
|
+
search("\\d+", "abc123"); // Search anywhere
|
|
1208
|
+
findall("\\d+", "a1b2c3"); // ["1", "2", "3"]
|
|
1209
|
+
sub("\\d", "X", "a1b2"); // "aXbX"
|
|
1210
|
+
sub("\\d", "X", "a1b2", 1); // "aXb2" (count=1)
|
|
1211
|
+
```
|
|
1212
|
+
|
|
1213
|
+
### Hash Functions
|
|
1214
|
+
|
|
1215
|
+
```cssl
|
|
1216
|
+
md5("hello"); // 32 hex chars
|
|
1217
|
+
sha1("hello"); // 40 hex chars
|
|
1218
|
+
sha256("hello"); // 64 hex chars
|
|
1219
|
+
```
|
|
1220
|
+
|
|
1221
|
+
### System Functions
|
|
1222
|
+
|
|
1223
|
+
```cssl
|
|
1224
|
+
exit(0); // Exit with code
|
|
1225
|
+
input("Enter name: "); // Read user input
|
|
1226
|
+
|
|
1227
|
+
env("PATH"); // Get env variable
|
|
1228
|
+
setenv("MY_VAR", "val"); // Set env variable
|
|
1229
|
+
|
|
1230
|
+
copy(obj); // Shallow copy
|
|
1231
|
+
deepcopy(obj); // Deep copy
|
|
1232
|
+
|
|
1233
|
+
clear(); // Clear console
|
|
1234
|
+
|
|
1235
|
+
pyimport("os"); // Import Python module
|
|
1236
|
+
include("lib.cssl-mod"); // Import CSSL module
|
|
1237
|
+
payload("helper.cssl-pl"); // Load payload
|
|
1238
|
+
|
|
1239
|
+
isLinux(); // Platform checks
|
|
1240
|
+
isWindows();
|
|
1241
|
+
isMac();
|
|
1242
|
+
```
|
|
1243
|
+
|
|
1244
|
+
### Filter Functions (filter:: namespace)
|
|
726
1245
|
|
|
727
|
-
|
|
1246
|
+
```cssl
|
|
1247
|
+
// Register custom filter
|
|
1248
|
+
filter::register("custom", "handler", callback);
|
|
1249
|
+
filter::unregister("custom", "handler");
|
|
1250
|
+
filter::list(); // All registered filters
|
|
1251
|
+
filter::exists("custom", "handler");
|
|
1252
|
+
```
|
|
728
1253
|
|
|
729
|
-
|
|
730
|
-
// Original function
|
|
731
|
-
define BaseFunc() {
|
|
732
|
-
printl("Base functionality");
|
|
733
|
-
}
|
|
1254
|
+
---
|
|
734
1255
|
|
|
735
|
-
|
|
736
|
-
define ExtendedFunc() &BaseFunc ++ {
|
|
737
|
-
printl("Extended functionality");
|
|
738
|
-
}
|
|
1256
|
+
## CodeInfusion
|
|
739
1257
|
|
|
740
|
-
|
|
741
|
-
// Output:
|
|
742
|
-
// Base functionality
|
|
743
|
-
// Extended functionality
|
|
744
|
-
```
|
|
1258
|
+
Modify functions at runtime.
|
|
745
1259
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
1260
|
+
### <<== (Replace)
|
|
1261
|
+
|
|
1262
|
+
```cssl
|
|
1263
|
+
void original() {
|
|
1264
|
+
printl("Original");
|
|
751
1265
|
}
|
|
752
|
-
}
|
|
753
1266
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
printl("BetterClass - added code");
|
|
757
|
-
this->extra = 20;
|
|
1267
|
+
original() <<== {
|
|
1268
|
+
printl("Replaced");
|
|
758
1269
|
}
|
|
759
|
-
}
|
|
760
|
-
```
|
|
761
1270
|
|
|
762
|
-
|
|
1271
|
+
original(); // "Replaced"
|
|
1272
|
+
```
|
|
763
1273
|
|
|
764
|
-
|
|
765
|
-
class *MyClass {
|
|
766
|
-
// All methods must return non-null
|
|
767
|
-
string getValue() {
|
|
768
|
-
return "Value";
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
```
|
|
772
|
-
|
|
773
|
-
---
|
|
774
|
-
|
|
775
|
-
## Container Types
|
|
776
|
-
|
|
777
|
-
### stack\<T\> - LIFO Stack
|
|
778
|
-
|
|
779
|
-
```cssl
|
|
780
|
-
stack<string> names;
|
|
781
|
-
names.push("Alice");
|
|
782
|
-
names.push("Bob");
|
|
783
|
-
|
|
784
|
-
printl(names.pop()); // "Bob"
|
|
785
|
-
printl(names.peek()); // "Alice" (doesn't remove)
|
|
786
|
-
printl(names.size()); // 1
|
|
787
|
-
printl(names.isEmpty()); // false
|
|
788
|
-
```
|
|
789
|
-
|
|
790
|
-
**Methods:**
|
|
791
|
-
|
|
792
|
-
| Method | Description |
|
|
793
|
-
|--------|-------------|
|
|
794
|
-
| `push(value)` | Add to top |
|
|
795
|
-
| `pop()` | Remove and return top |
|
|
796
|
-
| `peek()` | View top without removing |
|
|
797
|
-
| `size()` / `length()` | Element count |
|
|
798
|
-
| `isEmpty()` / `is_empty()` | Check if empty |
|
|
799
|
-
| `contains(value)` | Check if contains |
|
|
800
|
-
| `indexOf(value)` | Find index (-1 if not found) |
|
|
801
|
-
| `toArray()` | Convert to list |
|
|
802
|
-
| `swap()` | Swap top two elements |
|
|
803
|
-
| `dup()` | Duplicate top element |
|
|
804
|
-
|
|
805
|
-
### vector\<T\> - Dynamic Array
|
|
806
|
-
|
|
807
|
-
```cssl
|
|
808
|
-
vector<int> nums;
|
|
809
|
-
nums.push(10);
|
|
810
|
-
nums.push(20);
|
|
811
|
-
|
|
812
|
-
printl(nums.at(0)); // 10
|
|
813
|
-
printl(nums.front()); // 10
|
|
814
|
-
printl(nums.back()); // 20
|
|
815
|
-
```
|
|
816
|
-
|
|
817
|
-
**Methods:**
|
|
818
|
-
|
|
819
|
-
| Method | Description |
|
|
820
|
-
|--------|-------------|
|
|
821
|
-
| `push(value)` / `push_back(value)` | Add to end |
|
|
822
|
-
| `push_front(value)` | Add to front |
|
|
823
|
-
| `pop_back()` | Remove from end |
|
|
824
|
-
| `pop_front()` | Remove from front |
|
|
825
|
-
| `at(index)` | Get element |
|
|
826
|
-
| `set(index, value)` | Set element |
|
|
827
|
-
| `front()` | Get first |
|
|
828
|
-
| `back()` | Get last |
|
|
829
|
-
| `size()` / `length()` | Element count |
|
|
830
|
-
| `empty()` / `isEmpty()` | Check if empty |
|
|
831
|
-
| `contains(value)` | Check if contains |
|
|
832
|
-
| `indexOf(value)` | Find first index |
|
|
833
|
-
| `lastIndexOf(value)` | Find last index |
|
|
834
|
-
| `slice(start, end)` | Get sub-vector |
|
|
835
|
-
| `join(separator)` | Join to string |
|
|
836
|
-
| `map(func)` | Apply function |
|
|
837
|
-
| `filter(predicate)` | Filter elements |
|
|
838
|
-
| `forEach(func)` | Execute for each |
|
|
839
|
-
| `every(predicate)` | Check all match |
|
|
840
|
-
| `some(predicate)` | Check any match |
|
|
841
|
-
| `reduce(func, initial)` | Reduce to value |
|
|
842
|
-
| `toArray()` | Convert to list |
|
|
843
|
-
|
|
844
|
-
### map\<K,V\> - Ordered Key-Value
|
|
845
|
-
|
|
846
|
-
```cssl
|
|
847
|
-
map<string, int> ages;
|
|
848
|
-
ages.insert("Alice", 30);
|
|
849
|
-
ages.insert("Bob", 25);
|
|
850
|
-
|
|
851
|
-
printl(ages.find("Alice")); // 30
|
|
852
|
-
printl(ages.contains("Bob")); // true
|
|
853
|
-
ages.erase("Bob");
|
|
854
|
-
```
|
|
855
|
-
|
|
856
|
-
**Methods:**
|
|
857
|
-
|
|
858
|
-
| Method | Description |
|
|
859
|
-
|--------|-------------|
|
|
860
|
-
| `insert(key, value)` | Insert/update pair |
|
|
861
|
-
| `find(key)` | Get value (null if not found) |
|
|
862
|
-
| `at(key)` | Get value (throws if not found) |
|
|
863
|
-
| `erase(key)` | Remove key |
|
|
864
|
-
| `contains(key)` | Check if key exists |
|
|
865
|
-
| `count(key)` | Count (0 or 1) |
|
|
866
|
-
| `size()` | Pair count |
|
|
867
|
-
| `empty()` | Check if empty |
|
|
868
|
-
| `begin()` | First key-value tuple |
|
|
869
|
-
| `end()` | Last key-value tuple |
|
|
870
|
-
| `lower_bound(key)` | First key >= given |
|
|
871
|
-
| `upper_bound(key)` | First key > given |
|
|
872
|
-
|
|
873
|
-
### datastruct\<T\> - Universal Container
|
|
874
|
-
|
|
875
|
-
Primary target for BruteInjection operations.
|
|
876
|
-
|
|
877
|
-
```cssl
|
|
878
|
-
datastruct<string> data;
|
|
879
|
-
data.add("item1");
|
|
880
|
-
data.add("item2");
|
|
881
|
-
|
|
882
|
-
printl(data.content()); // All elements
|
|
883
|
-
```
|
|
884
|
-
|
|
885
|
-
**Methods:**
|
|
886
|
-
|
|
887
|
-
| Method | Description |
|
|
888
|
-
|--------|-------------|
|
|
889
|
-
| `content()` | Get all elements |
|
|
890
|
-
| `add(value)` | Add element |
|
|
891
|
-
| `remove_where(predicate)` | Remove matching |
|
|
892
|
-
| `find_where(predicate)` | Find first matching |
|
|
893
|
-
| `convert(type)` | Convert first element |
|
|
894
|
-
|
|
895
|
-
### shuffled\<T\> - Multiple Returns
|
|
896
|
-
|
|
897
|
-
```cssl
|
|
898
|
-
shuffled string getInfo() {
|
|
899
|
-
return "Alice", "Bob", "Charlie";
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
a, b, c = getInfo();
|
|
903
|
-
printl(a); // "Alice"
|
|
904
|
-
```
|
|
905
|
-
|
|
906
|
-
---
|
|
907
|
-
|
|
908
|
-
## Built-in Functions
|
|
909
|
-
|
|
910
|
-
### String Operations
|
|
911
|
-
|
|
912
|
-
```cssl
|
|
913
|
-
string s = "Hello World";
|
|
914
|
-
|
|
915
|
-
// Case
|
|
916
|
-
upper(s); // "HELLO WORLD"
|
|
917
|
-
lower(s); // "hello world"
|
|
918
|
-
capitalize(s); // "Hello world"
|
|
919
|
-
title(s); // "Hello World"
|
|
920
|
-
|
|
921
|
-
// Trim
|
|
922
|
-
trim(" text "); // "text"
|
|
923
|
-
ltrim(" text"); // "text"
|
|
924
|
-
rtrim("text "); // "text"
|
|
925
|
-
|
|
926
|
-
// Search
|
|
927
|
-
contains(s, "World"); // true
|
|
928
|
-
startswith(s, "Hello"); // true
|
|
929
|
-
endswith(s, "World"); // true
|
|
930
|
-
indexof(s, "o"); // 4
|
|
931
|
-
lastindexof(s, "o"); // 7
|
|
932
|
-
|
|
933
|
-
// Manipulation
|
|
934
|
-
replace(s, "World", "CSSL"); // "Hello CSSL"
|
|
935
|
-
substr(s, 0, 5); // "Hello"
|
|
936
|
-
split(s, " "); // ["Hello", "World"]
|
|
937
|
-
join("-", ["a", "b"]); // "a-b"
|
|
938
|
-
repeat("ab", 3); // "ababab"
|
|
939
|
-
reverse(s); // "dlroW olleH"
|
|
940
|
-
|
|
941
|
-
// Padding
|
|
942
|
-
padleft("42", 5, "0"); // "00042"
|
|
943
|
-
padright("42", 5, "."); // "42..."
|
|
944
|
-
center("hi", 6, "-"); // "--hi--"
|
|
945
|
-
zfill("42", 5); // "00042"
|
|
946
|
-
|
|
947
|
-
// Character
|
|
948
|
-
len(s); // 11
|
|
949
|
-
chars("abc"); // ["a", "b", "c"]
|
|
950
|
-
ord("A"); // 65
|
|
951
|
-
chr(65); // "A"
|
|
952
|
-
|
|
953
|
-
// Checks
|
|
954
|
-
isalpha("abc"); // true
|
|
955
|
-
isdigit("123"); // true
|
|
956
|
-
isalnum("abc123"); // true
|
|
957
|
-
isspace(" "); // true
|
|
958
|
-
```
|
|
959
|
-
|
|
960
|
-
### Array/List Operations
|
|
961
|
-
|
|
962
|
-
```cssl
|
|
963
|
-
stack<int> arr = [1, 2, 3, 4, 5];
|
|
964
|
-
|
|
965
|
-
// Add/Remove
|
|
966
|
-
push(arr, 6); // Add to end
|
|
967
|
-
pop(arr); // Remove last
|
|
968
|
-
shift(arr); // Remove first
|
|
969
|
-
unshift(arr, 0); // Add to front
|
|
970
|
-
|
|
971
|
-
// Access
|
|
972
|
-
first(arr); // First element
|
|
973
|
-
last(arr); // Last element
|
|
974
|
-
slice(arr, 1, 3); // [2, 3]
|
|
975
|
-
|
|
976
|
-
// Transform
|
|
977
|
-
sort(arr); // Sort ascending
|
|
978
|
-
rsort(arr); // Sort descending
|
|
979
|
-
reversed(arr); // Reverse copy
|
|
980
|
-
shuffle(arr); // Random order
|
|
981
|
-
unique(arr); // Remove duplicates
|
|
982
|
-
flatten([[1,2],[3,4]]); // [1, 2, 3, 4]
|
|
983
|
-
|
|
984
|
-
// Search
|
|
985
|
-
find(arr, x => x > 3); // First matching
|
|
986
|
-
findindex(arr, x => x > 3);
|
|
987
|
-
every(arr, x => x > 0); // All match?
|
|
988
|
-
some(arr, x => x > 3); // Any match?
|
|
989
|
-
count(arr, 2); // Count of 2
|
|
990
|
-
|
|
991
|
-
// Functional
|
|
992
|
-
map(arr, x => x * 2); // [2, 4, 6, 8, 10]
|
|
993
|
-
filter(arr, x => x > 2); // [3, 4, 5]
|
|
994
|
-
reduce(arr, (a,b) => a+b, 0); // 15
|
|
995
|
-
|
|
996
|
-
// Utilities
|
|
997
|
-
range(5); // [0, 1, 2, 3, 4]
|
|
998
|
-
range(1, 5); // [1, 2, 3, 4]
|
|
999
|
-
range(0, 10, 2); // [0, 2, 4, 6, 8]
|
|
1000
|
-
enumerate(arr); // [(0,1), (1,2), ...]
|
|
1001
|
-
zip([1,2], ["a","b"]); // [(1,"a"), (2,"b")]
|
|
1002
|
-
take(arr, 3); // First 3 elements
|
|
1003
|
-
drop(arr, 2); // Skip first 2
|
|
1004
|
-
chunk(arr, 2); // [[1,2], [3,4], [5]]
|
|
1005
|
-
sample(arr, 2); // 2 random elements
|
|
1006
|
-
```
|
|
1007
|
-
|
|
1008
|
-
### Dictionary Operations
|
|
1009
|
-
|
|
1010
|
-
```cssl
|
|
1011
|
-
dict d = {"name": "Alice", "age": 30};
|
|
1012
|
-
|
|
1013
|
-
keys(d); // ["name", "age"]
|
|
1014
|
-
values(d); // ["Alice", 30]
|
|
1015
|
-
items(d); // [("name","Alice"), ...]
|
|
1016
|
-
haskey(d, "name"); // true
|
|
1017
|
-
getkey(d, "name"); // "Alice"
|
|
1018
|
-
getkey(d, "x", "default"); // "default"
|
|
1019
|
-
setkey(d, "city", "NYC"); // Add key
|
|
1020
|
-
delkey(d, "age"); // Remove key
|
|
1021
|
-
merge(d1, d2); // Merge dicts
|
|
1022
|
-
update(d, {"new": 1}); // Update in place
|
|
1023
|
-
fromkeys(["a","b"], 0); // {"a": 0, "b": 0}
|
|
1024
|
-
invert({"a": 1}); // {1: "a"}
|
|
1025
|
-
pick(d, "name"); // {"name": "Alice"}
|
|
1026
|
-
omit(d, "age"); // {"name": "Alice"}
|
|
1027
|
-
```
|
|
1028
|
-
|
|
1029
|
-
### Math Functions
|
|
1030
|
-
|
|
1031
|
-
```cssl
|
|
1032
|
-
abs(-5); // 5
|
|
1033
|
-
min(3, 1, 2); // 1
|
|
1034
|
-
max(3, 1, 2); // 3
|
|
1035
|
-
sum([1, 2, 3]); // 6
|
|
1036
|
-
avg([1, 2, 3, 4, 5]); // 3.0
|
|
1037
|
-
|
|
1038
|
-
round(3.14159, 2); // 3.14
|
|
1039
|
-
floor(3.9); // 3
|
|
1040
|
-
ceil(3.1); // 4
|
|
1041
|
-
|
|
1042
|
-
pow(2, 3); // 8
|
|
1043
|
-
sqrt(16); // 4
|
|
1044
|
-
mod(7, 3); // 1
|
|
1045
|
-
|
|
1046
|
-
sin(0); // 0.0
|
|
1047
|
-
cos(0); // 1.0
|
|
1048
|
-
tan(0); // 0.0
|
|
1049
|
-
asin(1); // 1.5708
|
|
1050
|
-
acos(0); // 1.5708
|
|
1051
|
-
atan(1); // 0.7854
|
|
1052
|
-
atan2(1, 1); // 0.7854
|
|
1053
|
-
|
|
1054
|
-
log(e()); // 1.0
|
|
1055
|
-
log10(100); // 2.0
|
|
1056
|
-
exp(1); // 2.71828
|
|
1057
|
-
|
|
1058
|
-
pi(); // 3.14159...
|
|
1059
|
-
e(); // 2.71828...
|
|
1060
|
-
radians(180); // 3.14159
|
|
1061
|
-
degrees(3.14159); // 180
|
|
1062
|
-
|
|
1063
|
-
random(); // 0.0 to 1.0
|
|
1064
|
-
randint(1, 6); // 1 to 6
|
|
1065
|
-
```
|
|
1066
|
-
|
|
1067
|
-
### Date/Time Functions
|
|
1068
|
-
|
|
1069
|
-
```cssl
|
|
1070
|
-
now(); // Unix timestamp (float)
|
|
1071
|
-
timestamp(); // Unix timestamp (int)
|
|
1072
|
-
date(); // "2025-12-30"
|
|
1073
|
-
date("%d/%m/%Y"); // "30/12/2025"
|
|
1074
|
-
time(); // "14:30:45"
|
|
1075
|
-
datetime(); // "2025-12-30 14:30:45"
|
|
1076
|
-
strftime("%Y-%m-%d", ts);
|
|
1077
|
-
|
|
1078
|
-
sleep(1.5); // Wait 1.5 seconds
|
|
1079
|
-
delay(500); // Wait 500 milliseconds
|
|
1080
|
-
```
|
|
1081
|
-
|
|
1082
|
-
### File I/O Functions
|
|
1083
|
-
|
|
1084
|
-
```cssl
|
|
1085
|
-
// Read
|
|
1086
|
-
string content = read("file.txt");
|
|
1087
|
-
string line5 = readline(5, "file.txt");
|
|
1088
|
-
stack<string> lines = readlines("file.txt");
|
|
1089
|
-
|
|
1090
|
-
// Write
|
|
1091
|
-
write("file.txt", "Hello");
|
|
1092
|
-
writeline(3, "New line", "file.txt");
|
|
1093
|
-
appendfile("file.txt", "\nMore");
|
|
1094
|
-
|
|
1095
|
-
// Path operations
|
|
1096
|
-
basename("/path/to/file.txt"); // "file.txt"
|
|
1097
|
-
dirname("/path/to/file.txt"); // "/path/to"
|
|
1098
|
-
joinpath("/path", "file.txt"); // "/path/file.txt"
|
|
1099
|
-
abspath("./file.txt");
|
|
1100
|
-
normpath("/path/../other");
|
|
1101
|
-
|
|
1102
|
-
// Checks
|
|
1103
|
-
pathexists("file.txt"); // true/false
|
|
1104
|
-
isfile("file.txt"); // true/false
|
|
1105
|
-
isdir("folder"); // true/false
|
|
1106
|
-
filesize("file.txt"); // bytes
|
|
1107
|
-
|
|
1108
|
-
// Directory
|
|
1109
|
-
listdir("./"); // ["file1", "file2"]
|
|
1110
|
-
makedirs("new/folder");
|
|
1111
|
-
removefile("file.txt");
|
|
1112
|
-
removedir("folder");
|
|
1113
|
-
copyfile("src", "dst");
|
|
1114
|
-
movefile("old", "new");
|
|
1115
|
-
```
|
|
1116
|
-
|
|
1117
|
-
### JSON Functions (json:: namespace)
|
|
1118
|
-
|
|
1119
|
-
```cssl
|
|
1120
|
-
// File operations
|
|
1121
|
-
json data = json::read("config.json");
|
|
1122
|
-
json::write("output.json", data);
|
|
1123
|
-
|
|
1124
|
-
// Parse/Stringify
|
|
1125
|
-
json obj = json::parse('{"name": "Alice"}');
|
|
1126
|
-
string str = json::stringify(obj);
|
|
1127
|
-
string pretty = json::pretty(obj);
|
|
1128
|
-
|
|
1129
|
-
// Path operations
|
|
1130
|
-
json::get(data, "user.name");
|
|
1131
|
-
json::get(data, "user.age", 0); // with default
|
|
1132
|
-
json::set(data, "user.name", "Bob");
|
|
1133
|
-
json::has(data, "user.email");
|
|
1134
|
-
|
|
1135
|
-
// Object operations
|
|
1136
|
-
json::keys(obj); // ["name"]
|
|
1137
|
-
json::values(obj); // ["Alice"]
|
|
1138
|
-
json::merge(obj1, obj2); // Deep merge
|
|
1139
|
-
```
|
|
1140
|
-
|
|
1141
|
-
### Instance Functions (instance:: namespace)
|
|
1142
|
-
|
|
1143
|
-
```cssl
|
|
1144
|
-
@module = include("lib.cssl-mod");
|
|
1145
|
-
|
|
1146
|
-
instance::getMethods(@module); // Method names
|
|
1147
|
-
instance::getClasses(@module); // Class names
|
|
1148
|
-
instance::getVars(@module); // Variable names
|
|
1149
|
-
instance::getAll(@module); // Categorized dict
|
|
1150
|
-
|
|
1151
|
-
instance::call(@module, "methodName", arg1);
|
|
1152
|
-
instance::has(@module, "attribute");
|
|
1153
|
-
instance::type(@module); // Type name
|
|
1154
|
-
|
|
1155
|
-
isavailable("sharedName"); // Check if exists
|
|
1156
|
-
```
|
|
1157
|
-
|
|
1158
|
-
### Regex Functions
|
|
1159
|
-
|
|
1160
|
-
```cssl
|
|
1161
|
-
match("\\d+", "abc123"); // Match at start
|
|
1162
|
-
search("\\d+", "abc123"); // Search anywhere
|
|
1163
|
-
findall("\\d+", "a1b2c3"); // ["1", "2", "3"]
|
|
1164
|
-
sub("\\d", "X", "a1b2"); // "aXbX"
|
|
1165
|
-
sub("\\d", "X", "a1b2", 1); // "aXb2" (count=1)
|
|
1166
|
-
```
|
|
1167
|
-
|
|
1168
|
-
### Hash Functions
|
|
1169
|
-
|
|
1170
|
-
```cssl
|
|
1171
|
-
md5("hello"); // 32 hex chars
|
|
1172
|
-
sha1("hello"); // 40 hex chars
|
|
1173
|
-
sha256("hello"); // 64 hex chars
|
|
1174
|
-
```
|
|
1274
|
+
### +<<== (Add Before)
|
|
1175
1275
|
|
|
1176
|
-
|
|
1276
|
+
```cssl
|
|
1277
|
+
void base() {
|
|
1278
|
+
printl("Base");
|
|
1279
|
+
}
|
|
1177
1280
|
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1281
|
+
base() +<<== {
|
|
1282
|
+
printl("Added");
|
|
1283
|
+
}
|
|
1181
1284
|
|
|
1182
|
-
|
|
1183
|
-
|
|
1285
|
+
base();
|
|
1286
|
+
// Output:
|
|
1287
|
+
// Added
|
|
1288
|
+
// Base
|
|
1289
|
+
```
|
|
1184
1290
|
|
|
1185
|
-
|
|
1186
|
-
deepcopy(obj); // Deep copy
|
|
1291
|
+
### -<<== (Remove)
|
|
1187
1292
|
|
|
1188
|
-
|
|
1293
|
+
```cssl
|
|
1294
|
+
void withExtra() {
|
|
1295
|
+
printl("Important");
|
|
1296
|
+
printl("Unimportant");
|
|
1297
|
+
}
|
|
1189
1298
|
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1299
|
+
withExtra() -<<== {
|
|
1300
|
+
printl("Unimportant");
|
|
1301
|
+
}
|
|
1193
1302
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
isMac();
|
|
1197
|
-
```
|
|
1303
|
+
withExtra(); // Only "Important"
|
|
1304
|
+
```
|
|
1198
1305
|
|
|
1199
|
-
###
|
|
1306
|
+
### Exit Injection
|
|
1200
1307
|
|
|
1201
|
-
```cssl
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
filter::list(); // All registered filters
|
|
1206
|
-
filter::exists("custom", "handler");
|
|
1207
|
-
```
|
|
1308
|
+
```cssl
|
|
1309
|
+
exit() <<== {
|
|
1310
|
+
printl("Cleanup...");
|
|
1311
|
+
}
|
|
1208
1312
|
|
|
1209
|
-
|
|
1313
|
+
exit(); // Executes injection
|
|
1314
|
+
```
|
|
1210
1315
|
|
|
1211
|
-
|
|
1316
|
+
---
|
|
1212
1317
|
|
|
1213
|
-
|
|
1318
|
+
## BruteInjection
|
|
1214
1319
|
|
|
1215
|
-
|
|
1320
|
+
Transfer data between containers.
|
|
1216
1321
|
|
|
1217
|
-
|
|
1218
|
-
void original() {
|
|
1219
|
-
printl("Original");
|
|
1220
|
-
}
|
|
1322
|
+
### +<== (Copy)
|
|
1221
1323
|
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1324
|
+
```cssl
|
|
1325
|
+
stack<string> source;
|
|
1326
|
+
source.push("A");
|
|
1327
|
+
source.push("B");
|
|
1225
1328
|
|
|
1226
|
-
|
|
1227
|
-
|
|
1329
|
+
datastruct<string> target;
|
|
1330
|
+
target +<== source; // Copy A, B (source unchanged)
|
|
1331
|
+
```
|
|
1228
1332
|
|
|
1229
|
-
###
|
|
1333
|
+
### -<== (Move)
|
|
1230
1334
|
|
|
1231
|
-
```cssl
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
}
|
|
1335
|
+
```cssl
|
|
1336
|
+
stack<string> src;
|
|
1337
|
+
src.push("Data");
|
|
1235
1338
|
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1339
|
+
datastruct<string> dst;
|
|
1340
|
+
dst -<== src; // src is empty after
|
|
1341
|
+
```
|
|
1239
1342
|
|
|
1240
|
-
|
|
1241
|
-
// Output:
|
|
1242
|
-
// Added
|
|
1243
|
-
// Base
|
|
1244
|
-
```
|
|
1343
|
+
### ==> (Replace)
|
|
1245
1344
|
|
|
1246
|
-
|
|
1345
|
+
```cssl
|
|
1346
|
+
stack<string> data;
|
|
1347
|
+
data.push("New");
|
|
1247
1348
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
printl("Unimportant");
|
|
1252
|
-
}
|
|
1349
|
+
datastruct<string> container;
|
|
1350
|
+
container ==> data; // Replace container content
|
|
1351
|
+
```
|
|
1253
1352
|
|
|
1254
|
-
|
|
1255
|
-
printl("Unimportant");
|
|
1256
|
-
}
|
|
1353
|
+
### ==>- (Remove Matching)
|
|
1257
1354
|
|
|
1258
|
-
|
|
1259
|
-
|
|
1355
|
+
```cssl
|
|
1356
|
+
stack<string> names;
|
|
1357
|
+
names.push("Alice");
|
|
1358
|
+
names.push("Bob");
|
|
1359
|
+
names.push("Alice");
|
|
1260
1360
|
|
|
1261
|
-
|
|
1361
|
+
stack<string> toRemove;
|
|
1362
|
+
toRemove.push("Alice");
|
|
1262
1363
|
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
}
|
|
1364
|
+
names ==>- toRemove;
|
|
1365
|
+
printl(names); // ["Bob"]
|
|
1366
|
+
```
|
|
1267
1367
|
|
|
1268
|
-
|
|
1269
|
-
```
|
|
1368
|
+
### Filter Syntax
|
|
1270
1369
|
|
|
1271
|
-
|
|
1370
|
+
```cssl
|
|
1371
|
+
target +<== [type::filter=value] source;
|
|
1272
1372
|
|
|
1273
|
-
|
|
1373
|
+
// String filters
|
|
1374
|
+
result +<== [string::where="Apple"] fruits;
|
|
1375
|
+
result +<== [string::not="Banana"] fruits;
|
|
1376
|
+
result +<== [string::contains="App"] fruits;
|
|
1377
|
+
result +<== [string::length=5] fruits;
|
|
1378
|
+
result +<== [string::cut=3] version;
|
|
1379
|
+
result +<== [string::cutAfter="."] version;
|
|
1274
1380
|
|
|
1275
|
-
|
|
1381
|
+
// Other filters
|
|
1382
|
+
result +<== [integer::where=42] numbers;
|
|
1383
|
+
result +<== [json::key="name"] objects;
|
|
1384
|
+
```
|
|
1276
1385
|
|
|
1277
|
-
|
|
1386
|
+
---
|
|
1278
1387
|
|
|
1279
|
-
|
|
1280
|
-
stack<string> source;
|
|
1281
|
-
source.push("A");
|
|
1282
|
-
source.push("B");
|
|
1388
|
+
## Value Capture
|
|
1283
1389
|
|
|
1284
|
-
|
|
1285
|
-
target +<== source; // Copy A, B (source unchanged)
|
|
1286
|
-
```
|
|
1390
|
+
Capture values at registration time with `%`:
|
|
1287
1391
|
|
|
1288
|
-
|
|
1392
|
+
```cssl
|
|
1393
|
+
string version = "1.0.0";
|
|
1394
|
+
savedVersion <<== { %version; }
|
|
1289
1395
|
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1396
|
+
version = "2.0.0";
|
|
1397
|
+
printl(savedVersion); // "1.0.0" (captured value)
|
|
1398
|
+
```
|
|
1293
1399
|
|
|
1294
|
-
|
|
1295
|
-
dst -<== src; // src is empty after
|
|
1296
|
-
```
|
|
1400
|
+
### Capturing Functions
|
|
1297
1401
|
|
|
1298
|
-
|
|
1402
|
+
```cssl
|
|
1403
|
+
originalExit <<== { %exit(); }
|
|
1299
1404
|
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1405
|
+
exit() <<== {
|
|
1406
|
+
printl("Custom cleanup");
|
|
1407
|
+
originalExit();
|
|
1408
|
+
}
|
|
1409
|
+
```
|
|
1303
1410
|
|
|
1304
|
-
|
|
1305
|
-
container ==> data; // Replace container content
|
|
1306
|
-
```
|
|
1411
|
+
---
|
|
1307
1412
|
|
|
1308
|
-
|
|
1413
|
+
## Module System
|
|
1309
1414
|
|
|
1310
|
-
|
|
1311
|
-
stack<string> names;
|
|
1312
|
-
names.push("Alice");
|
|
1313
|
-
names.push("Bob");
|
|
1314
|
-
names.push("Alice");
|
|
1415
|
+
### Import CSSL Module
|
|
1315
1416
|
|
|
1316
|
-
|
|
1317
|
-
|
|
1417
|
+
```cssl
|
|
1418
|
+
@Math = include("mathlib.cssl-mod");
|
|
1419
|
+
int result = @Math.add(5, 3);
|
|
1420
|
+
```
|
|
1318
1421
|
|
|
1319
|
-
|
|
1320
|
-
printl(names); // ["Bob"]
|
|
1321
|
-
```
|
|
1422
|
+
### Import Python Module
|
|
1322
1423
|
|
|
1323
|
-
|
|
1424
|
+
```cssl
|
|
1425
|
+
@os = pyimport("os");
|
|
1426
|
+
string cwd = @os.getcwd();
|
|
1324
1427
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1428
|
+
@datetime = pyimport("datetime");
|
|
1429
|
+
@datetime.datetime.now();
|
|
1430
|
+
```
|
|
1327
1431
|
|
|
1328
|
-
|
|
1329
|
-
result +<== [string::where="Apple"] fruits;
|
|
1330
|
-
result +<== [string::not="Banana"] fruits;
|
|
1331
|
-
result +<== [string::contains="App"] fruits;
|
|
1332
|
-
result +<== [string::length=5] fruits;
|
|
1333
|
-
result +<== [string::cut=3] version;
|
|
1334
|
-
result +<== [string::cutAfter="."] version;
|
|
1432
|
+
### Load Payload
|
|
1335
1433
|
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
```
|
|
1434
|
+
```cssl
|
|
1435
|
+
payload("helpers.cssl-pl");
|
|
1436
|
+
```
|
|
1340
1437
|
|
|
1341
|
-
|
|
1438
|
+
### Create Module (CLI)
|
|
1342
1439
|
|
|
1343
|
-
|
|
1440
|
+
```bash
|
|
1441
|
+
python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
|
|
1442
|
+
```
|
|
1344
1443
|
|
|
1345
|
-
|
|
1444
|
+
---
|
|
1346
1445
|
|
|
1347
|
-
|
|
1348
|
-
string version = "1.0.0";
|
|
1349
|
-
savedVersion <<== { %version; }
|
|
1446
|
+
## Multi-Language Support
|
|
1350
1447
|
|
|
1351
|
-
|
|
1352
|
-
printl(savedVersion); // "1.0.0" (captured value)
|
|
1353
|
-
```
|
|
1448
|
+
CSSL v4.1.0 introduces multi-language support for interoperability with other programming languages.
|
|
1354
1449
|
|
|
1355
|
-
###
|
|
1450
|
+
### libinclude - Load Language Support
|
|
1356
1451
|
|
|
1357
|
-
|
|
1358
|
-
originalExit <<== { %exit(); }
|
|
1452
|
+
Use `libinclude()` to load a language support module:
|
|
1359
1453
|
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1454
|
+
```cssl
|
|
1455
|
+
// Load language support
|
|
1456
|
+
@py = libinclude("python");
|
|
1457
|
+
cpp = libinclude("c++");
|
|
1458
|
+
java = libinclude("java");
|
|
1459
|
+
csharp = libinclude("c#");
|
|
1460
|
+
js = libinclude("javascript");
|
|
1461
|
+
```
|
|
1365
1462
|
|
|
1366
|
-
|
|
1463
|
+
**Supported Languages:**
|
|
1367
1464
|
|
|
1368
|
-
|
|
1465
|
+
| Language | Identifiers |
|
|
1466
|
+
|----------|-------------|
|
|
1467
|
+
| Python | `python`, `py` |
|
|
1468
|
+
| C++ | `c++`, `cpp` |
|
|
1469
|
+
| Java | `java` |
|
|
1470
|
+
| C# | `c#`, `csharp` |
|
|
1471
|
+
| JavaScript | `javascript`, `js` |
|
|
1369
1472
|
|
|
1370
|
-
###
|
|
1473
|
+
### supports - Multi-Language Syntax
|
|
1371
1474
|
|
|
1372
|
-
|
|
1373
|
-
@Math = include("mathlib.cssl-mod");
|
|
1374
|
-
int result = @Math.add(5, 3);
|
|
1375
|
-
```
|
|
1475
|
+
Use the `supports` keyword to write functions or classes using another language's syntax:
|
|
1376
1476
|
|
|
1377
|
-
|
|
1477
|
+
```cssl
|
|
1478
|
+
// Python-style function
|
|
1479
|
+
define calculate(numbers) : supports python {
|
|
1480
|
+
total = 0
|
|
1481
|
+
for n in numbers:
|
|
1482
|
+
total = total + n
|
|
1483
|
+
return total
|
|
1484
|
+
}
|
|
1378
1485
|
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1486
|
+
// C++ style class
|
|
1487
|
+
class Engine : supports cpp {
|
|
1488
|
+
int power;
|
|
1489
|
+
bool running;
|
|
1382
1490
|
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1491
|
+
void start() {
|
|
1492
|
+
this->running = true;
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1386
1495
|
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
```
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
###
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
|
1482
|
-
|
|
1483
|
-
| `
|
|
1484
|
-
|
|
|
1485
|
-
|
|
|
1486
|
-
| `
|
|
1487
|
-
| `
|
|
1488
|
-
| `
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1496
|
+
// JavaScript style function
|
|
1497
|
+
define fetchData(url) : supports javascript {
|
|
1498
|
+
let response = fetch(url);
|
|
1499
|
+
console.log("Fetched: " + url);
|
|
1500
|
+
return response;
|
|
1501
|
+
}
|
|
1502
|
+
```
|
|
1503
|
+
|
|
1504
|
+
### Cross-Language Instance Access
|
|
1505
|
+
|
|
1506
|
+
Access instances shared from other languages using `lang$InstanceName` syntax:
|
|
1507
|
+
|
|
1508
|
+
```cssl
|
|
1509
|
+
cpp = libinclude("c++");
|
|
1510
|
+
|
|
1511
|
+
// Access C++ shared instance
|
|
1512
|
+
engine = cpp$MyEngine;
|
|
1513
|
+
printl(engine.power);
|
|
1514
|
+
|
|
1515
|
+
// Cross-language inheritance
|
|
1516
|
+
class TurboEngine : extends cpp$Engine {
|
|
1517
|
+
int turboBoost;
|
|
1518
|
+
|
|
1519
|
+
constr TurboEngine(int boost) {
|
|
1520
|
+
this->turboBoost = boost;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
```
|
|
1524
|
+
|
|
1525
|
+
### Instance Sharing API
|
|
1526
|
+
|
|
1527
|
+
Share instances between languages using the `share()` and `get_instance()` methods:
|
|
1528
|
+
|
|
1529
|
+
```cssl
|
|
1530
|
+
// Get language support
|
|
1531
|
+
cpp = libinclude("c++");
|
|
1532
|
+
|
|
1533
|
+
// Share a CSSL instance with C++
|
|
1534
|
+
class MyClass {
|
|
1535
|
+
string value;
|
|
1536
|
+
}
|
|
1537
|
+
instance = new MyClass();
|
|
1538
|
+
cpp.share("MyClass", instance);
|
|
1539
|
+
|
|
1540
|
+
// Access from C++:
|
|
1541
|
+
// auto* obj = CSSL_GET(MyClass, "MyClass");
|
|
1542
|
+
```
|
|
1543
|
+
|
|
1544
|
+
### Language SDKs
|
|
1545
|
+
|
|
1546
|
+
SDKs are available for sharing instances from other languages into CSSL:
|
|
1547
|
+
|
|
1548
|
+
**C++ SDK:**
|
|
1549
|
+
```cpp
|
|
1550
|
+
#include "includecpp.h"
|
|
1551
|
+
|
|
1552
|
+
class Engine { public: int power = 100; };
|
|
1553
|
+
|
|
1554
|
+
Engine engine;
|
|
1555
|
+
CSSL_SHARE(Engine, &engine);
|
|
1556
|
+
// Now accessible as cpp$Engine in CSSL
|
|
1557
|
+
```
|
|
1558
|
+
|
|
1559
|
+
**Java SDK:**
|
|
1560
|
+
```java
|
|
1561
|
+
import com.includecpp.CSSL;
|
|
1562
|
+
|
|
1563
|
+
MyService svc = new MyService();
|
|
1564
|
+
CSSL.share("MyService", svc);
|
|
1565
|
+
// Now accessible as java$MyService in CSSL
|
|
1566
|
+
```
|
|
1567
|
+
|
|
1568
|
+
**C# SDK:**
|
|
1569
|
+
```csharp
|
|
1570
|
+
using IncludeCPP;
|
|
1571
|
+
|
|
1572
|
+
var service = new MyService();
|
|
1573
|
+
CSSL.Share("MyService", service);
|
|
1574
|
+
// Now accessible as csharp$MyService in CSSL
|
|
1575
|
+
```
|
|
1576
|
+
|
|
1577
|
+
**JavaScript SDK:**
|
|
1578
|
+
```javascript
|
|
1579
|
+
import { CSSL } from 'includecpp-cssl';
|
|
1580
|
+
|
|
1581
|
+
class DataProcessor { process(data) { } }
|
|
1582
|
+
CSSL.share('DataProcessor', new DataProcessor());
|
|
1583
|
+
// Now accessible as js$DataProcessor in CSSL
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
### SDK API Reference
|
|
1587
|
+
|
|
1588
|
+
All language SDKs provide these methods:
|
|
1589
|
+
|
|
1590
|
+
| Method | Description |
|
|
1591
|
+
|--------|-------------|
|
|
1592
|
+
| `share(name, instance)` | Share an instance by name |
|
|
1593
|
+
| `get(name)` | Get a shared instance |
|
|
1594
|
+
| `has(name)` | Check if instance exists |
|
|
1595
|
+
| `remove(name)` | Remove a shared instance |
|
|
1596
|
+
| `list()` | Get all instance names |
|
|
1597
|
+
| `clear()` | Clear all instances |
|
|
1598
|
+
|
|
1599
|
+
---
|
|
1600
|
+
|
|
1601
|
+
## Error Handling
|
|
1602
|
+
|
|
1603
|
+
### Try / Catch
|
|
1604
|
+
|
|
1605
|
+
```cssl
|
|
1606
|
+
try {
|
|
1607
|
+
riskyOperation();
|
|
1608
|
+
} catch (error) {
|
|
1609
|
+
printl("Error: " + error);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
try {
|
|
1613
|
+
operation();
|
|
1614
|
+
} catch (error) {
|
|
1615
|
+
printl("Error");
|
|
1616
|
+
} finally {
|
|
1617
|
+
printl("Always runs");
|
|
1618
|
+
}
|
|
1619
|
+
```
|
|
1620
|
+
|
|
1621
|
+
### Undefined Functions
|
|
1622
|
+
|
|
1623
|
+
```cssl
|
|
1624
|
+
undefined void safeOperation() {
|
|
1625
|
+
dangerousCode(); // Errors ignored
|
|
1626
|
+
}
|
|
1627
|
+
```
|
|
1628
|
+
|
|
1629
|
+
### Assert
|
|
1630
|
+
|
|
1631
|
+
```cssl
|
|
1632
|
+
assert(x > 0, "x must be positive");
|
|
1633
|
+
```
|
|
1634
|
+
|
|
1635
|
+
---
|
|
1636
|
+
|
|
1637
|
+
## Quick Reference
|
|
1638
|
+
|
|
1639
|
+
### Keywords
|
|
1640
|
+
|
|
1641
|
+
| Keyword | Description |
|
|
1642
|
+
|---------|-------------|
|
|
1643
|
+
| `void` | No return value |
|
|
1644
|
+
| `return` | Return value |
|
|
1645
|
+
| `global` | Declare global |
|
|
1646
|
+
| `if` / `else` / `elif` | Conditionals |
|
|
1647
|
+
| `switch` / `case` / `default` | Switch statement |
|
|
1648
|
+
| `for` / `foreach` / `while` | Loops |
|
|
1649
|
+
| `break` / `continue` | Loop control |
|
|
1650
|
+
| `try` / `catch` / `finally` | Error handling |
|
|
1651
|
+
| `class` / `new` / `this` | OOP |
|
|
1652
|
+
| `extends` / `overwrites` | Inheritance |
|
|
1653
|
+
| `constr` | Constructor |
|
|
1654
|
+
| `define` | Function definition |
|
|
1655
|
+
| `undefined` | Ignore errors |
|
|
1656
|
+
| `closed` / `private` | Injection protection |
|
|
1657
|
+
| `virtual` | Import-safe |
|
|
1658
|
+
| `meta` / `super` | Special function types |
|
|
1659
|
+
| `shuffled` | Multiple returns |
|
|
1660
|
+
| `open` | Any parameters |
|
|
1661
|
+
| `include` / `get` | Import modules |
|
|
1662
|
+
|
|
1663
|
+
### Injection Operators
|
|
1664
|
+
|
|
1665
|
+
| Operator | Type | Description |
|
|
1666
|
+
|----------|------|-------------|
|
|
1667
|
+
| `<<==` | CodeInfusion | Replace function |
|
|
1668
|
+
| `+<<==` | CodeInfusion | Add code before |
|
|
1669
|
+
| `-<<==` | CodeInfusion | Remove code |
|
|
1670
|
+
| `<==` | ValueCapture | Capture/assign |
|
|
1671
|
+
| `+<==` | BruteInjection | Copy data |
|
|
1672
|
+
| `-<==` | BruteInjection | Move data |
|
|
1673
|
+
| `==>` | BruteInjection | Replace data |
|
|
1674
|
+
| `==>-` | BruteInjection | Remove matching |
|
|
1675
|
+
| `++` | AppendMode | Append to parent |
|
|
1676
|
+
|
|
1677
|
+
### Special Syntax
|
|
1678
|
+
|
|
1679
|
+
| Syntax | Description |
|
|
1680
|
+
|--------|-------------|
|
|
1681
|
+
| `@name` | Global variable access |
|
|
1682
|
+
| `@name = value` | Global variable assignment |
|
|
1683
|
+
| `r@name = value` | Global reference assignment |
|
|
1684
|
+
| `$name` | Shared Python object |
|
|
1685
|
+
| `%name` | Captured value |
|
|
1686
|
+
| `this->` | Class member access |
|
|
1687
|
+
| `super::method()` | Parent method call |
|
|
1688
|
+
| `json::func()` | Namespace function |
|
|
1689
|
+
| `&ClassName::member` | Class member reference |
|
|
1690
|
+
| `&FunctionName ++` | Append to function |
|
|
1691
|
+
| `*func()` | Non-null function |
|
|
1692
|
+
| `*[type]func()` | Type exclusion filter |
|
|
1693
|
+
| `global class Name` | Global class declaration |
|
|
1694
|
+
| `class @Name` | Global class (alt syntax) |
|
|
1695
|
+
| `global define func()` | Global function declaration |
|
|
1696
|
+
| `define @func()` | Global function (alt syntax) |
|
|
1697
|
+
| `new @ClassName()` | Instantiate global class |
|
|
1698
|
+
| `libinclude("lang")` | Load language support module |
|
|
1699
|
+
| `supports lang` | Use other language syntax |
|
|
1700
|
+
| `lang$InstanceName` | Cross-language instance access |
|
|
1701
|
+
|
|
1702
|
+
### Multi-Language Keywords
|
|
1703
|
+
|
|
1704
|
+
| Keyword | Description |
|
|
1705
|
+
|---------|-------------|
|
|
1706
|
+
| `libinclude` | Load language support module |
|
|
1707
|
+
| `supports` | Use another language's syntax in function/class |
|
|
1708
|
+
|
|
1709
|
+
### Cross-Language Syntax
|
|
1710
|
+
|
|
1711
|
+
| Syntax | Description | Example |
|
|
1712
|
+
|--------|-------------|---------|
|
|
1713
|
+
| `libinclude("lang")` | Load language support | `cpp = libinclude("c++")` |
|
|
1714
|
+
| `: supports lang` | Use language syntax | `define func() : supports python { }` |
|
|
1715
|
+
| `lang$Name` | Access shared instance | `cpp$Engine`, `java$Service` |
|
|
1716
|
+
| `extends lang$Name` | Inherit from shared class | `class Child : extends cpp$Parent { }` |
|
|
1717
|
+
|
|
1718
|
+
---
|
|
1719
|
+
|
|
1720
|
+
*CSSL v4.1.0 - Developed as part of IncludeCPP*
|