IncludeCPP 3.8.9__py3-none-any.whl → 4.0.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.
@@ -1,65 +1,56 @@
1
1
  # CSSL - C-Style Scripting Language
2
2
 
3
- > Version 3.8.9 | A modern scripting language with C++-style syntax and unique features like CodeInfusion, BruteInjection, and Python Interop.
3
+ > Version 4.0.0 | A modern scripting language with C++-style syntax and unique features like CodeInfusion, BruteInjection, and Python Interop.
4
4
 
5
5
  ---
6
6
 
7
7
  ## Table of Contents
8
8
 
9
9
  1. [Quick Start](#quick-start)
10
- 2. [Basics](#basics)
10
+ 2. [Syntax Basics](#syntax-basics)
11
11
  3. [Data Types](#data-types)
12
- 4. [Container Types](#container-types)
13
- 5. [Variables & Globals](#variables--globals)
14
- 6. [Control Structures](#control-structures)
12
+ 4. [Variables & Globals](#variables--globals)
13
+ 5. [Operators](#operators)
14
+ 6. [Control Flow](#control-flow)
15
15
  7. [Functions](#functions)
16
- 8. [Function Keywords](#function-keywords)
17
- 9. [String Methods](#string-methods)
18
- 10. [File I/O](#file-io)
19
- 11. [JSON Functions](#json-functions)
20
- 12. [Instance Management](#instance-management)
21
- 13. [Live Object Sharing](#live-object-sharing)
22
- 14. [CodeInfusion](#codeinfusion)
23
- 15. [Value Capture](#value-capture)
24
- 16. [BruteInjection](#bruteinjection)
25
- 17. [Filter Syntax](#filter-syntax)
26
- 18. [Module System](#module-system)
27
- 19. [Parameter Bridge](#parameter-bridge)
28
- 20. [Classes & OOP](#classes--oop)
29
- 21. [Map Container](#map-container)
30
- 22. [Structures](#structures)
31
- 23. [Error Handling](#error-handling)
32
- 24. [CLI Commands](#cli-commands)
33
- 25. [Examples](#examples)
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. [Error Handling](#error-handling)
24
+ 16. [Quick Reference](#quick-reference)
34
25
 
35
26
  ---
36
27
 
37
28
  ## Quick Start
38
29
 
39
- ### Installation & Usage
30
+ ### Installation
31
+
32
+ ```bash
33
+ pip install includecpp
34
+ ```
35
+
36
+ ### Python Usage
40
37
 
41
38
  ```python
42
39
  from includecpp import CSSL
43
40
 
44
- # Execute code (v3.7.6+: use run() instead of exec())
45
- CSSL.run("""
41
+ # Execute CSSL code
42
+ CSSL.run('''
46
43
  printl("Hello CSSL!");
47
- """)
44
+ ''')
48
45
 
49
46
  # With parameters and return value
50
- result = CSSL.run("""
47
+ result = CSSL.run('''
51
48
  string name = parameter.get(0);
52
49
  printl("Hello " + name);
53
50
  parameter.return(true);
54
- """, "World")
51
+ ''', "World")
55
52
 
56
53
  print(result) # True
57
-
58
- # Create typed scripts and modules (v3.7.6+)
59
- main = CSSL.script("cssl", '''printl("Main");''')
60
- payload = CSSL.script("cssl-pl", '''void helper() { printl("Helper!"); }''')
61
- mod = CSSL.makemodule(main, payload, "mymod")
62
- mod.helper() # Call function directly
63
54
  ```
64
55
 
65
56
  ### CLI Execution
@@ -68,92 +59,58 @@ mod.helper() # Call function directly
68
59
  # Execute CSSL file
69
60
  python -m includecpp cssl exec myfile.cssl
70
61
 
71
- # Create module
62
+ # Create module from Python file
72
63
  python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
73
64
  ```
74
65
 
75
- ### First Steps
66
+ ### First Script
76
67
 
77
68
  ```cssl
78
- // Declare variables
69
+ // Variables
79
70
  string name = "CSSL";
80
71
  int version = 3;
81
72
 
82
73
  // Output
83
74
  printl("Welcome to " + name);
84
- printl(version);
85
75
 
86
- // Define function
76
+ // Function
87
77
  void greet(string msg) {
88
78
  printl(msg);
89
79
  }
80
+
90
81
  greet("Hello World!");
91
82
  ```
92
83
 
93
84
  ---
94
85
 
95
- ## Basics
86
+ ## Syntax Basics
96
87
 
97
88
  ### Comments
98
89
 
99
90
  ```cssl
100
- // Single-line comment
101
-
102
- /*
103
- Multi-line
104
- comment
105
- */
91
+ // Single-line comment (C-style)
92
+ # Single-line comment (Python-style)
106
93
  ```
107
94
 
108
- ### Output
95
+ ### Semicolons
96
+
97
+ Semicolons are optional but recommended for clarity.
109
98
 
110
99
  ```cssl
111
- printl("Text"); // With newline
112
- printl(variable); // Print variable
113
- printl("Value: " + var); // String concatenation
114
- printl("Number: " + 42); // String + Int works!
100
+ printl("Hello") // Works
101
+ printl("Hello"); // Also works (recommended)
115
102
  ```
116
103
 
117
- ### Operators
118
-
119
- #### Arithmetic Operators
120
-
121
- | Operator | Description | Example |
122
- |----------|-------------|---------|
123
- | `+` | Addition / String concatenation | `a + b` |
124
- | `-` | Subtraction | `a - b` |
125
- | `*` | Multiplication | `a * b` |
126
- | `/` | Division | `a / b` |
127
- | `%` | Modulo (remainder) | `a % b` |
128
-
129
- #### Comparison Operators
130
-
131
- | Operator | Description | Example |
132
- |----------|-------------|---------|
133
- | `==` | Equality | `a == b` |
134
- | `!=` | Inequality | `a != b` |
135
- | `<` | Less than | `a < b` |
136
- | `>` | Greater than | `a > b` |
137
- | `<=` | Less than or equal | `a <= b` |
138
- | `>=` | Greater than or equal | `a >= b` |
139
-
140
- #### Logical Operators
141
-
142
- | Operator | Description | Example |
143
- |----------|-------------|---------|
144
- | `&&` | Logical AND | `a && b` |
145
- | `\|\|` | Logical OR | `a \|\| b` |
146
- | `!` | Logical NOT | `!condition` |
147
- | `not` | Logical NOT (alternative) | `not condition` |
104
+ ### Output Functions
148
105
 
149
- #### Increment/Decrement (only in C-style for-loops)
150
-
151
- | Operator | Description | Example |
152
- |----------|-------------|---------|
153
- | `++` | Increment | `i++` |
154
- | `--` | Decrement | `i--` |
155
- | `+=` | Addition assignment | `i += 1` |
156
- | `-=` | Subtraction assignment | `i -= 1` |
106
+ ```cssl
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
+ ```
157
114
 
158
115
  ---
159
116
 
@@ -163,232 +120,254 @@ printl("Number: " + 42); // String + Int works!
163
120
 
164
121
  | Type | Description | Example |
165
122
  |------|-------------|---------|
166
- | `string` | Text string | `string s = "Hello";` |
167
- | `int` | Integer | `int i = 42;` |
123
+ | `int` | Integer | `int x = 42;` |
168
124
  | `float` | Floating point | `float f = 3.14;` |
125
+ | `string` | Text string | `string s = "Hello";` |
169
126
  | `bool` | Boolean | `bool b = true;` |
170
- | `json` | JSON object | `json j;` |
171
- | `dynamic` | Dynamic type | `dynamic x = "anything";` |
127
+ | `dynamic` | Any type (flexible) | `dynamic x = "text";` |
128
+ | `void` | No return value | `void func() { }` |
129
+ | `null` | Absence of value | `dynamic x = null;` |
172
130
 
173
- ### Examples
131
+ ### Generic Container Types
174
132
 
175
- ```cssl
176
- // String
177
- string greeting = "Hello";
178
- string name = "World";
179
- string combined = greeting + " " + name;
180
- printl(combined); // "Hello World"
133
+ | Type | Description | Example |
134
+ |------|-------------|---------|
135
+ | `stack<T>` | LIFO stack | `stack<string> names;` |
136
+ | `vector<T>` | Dynamic array | `vector<int> nums;` |
137
+ | `array<T>` | Standard array | `array<float> values;` |
138
+ | `map<K,V>` | Ordered key-value | `map<string, int> ages;` |
139
+ | `list` | Python-like list | `list items = [1, 2, 3];` |
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;` |
181
145
 
182
- // Integer
183
- int count = 10;
184
- int doubled = count * 2;
185
- printl(doubled); // 20
146
+ ### Type Conversion
186
147
 
187
- // Float
188
- float price = 19.99;
189
- printl(price);
148
+ ```cssl
149
+ int("42"); // String to int: 42
150
+ float("3.14"); // String to float: 3.14
151
+ str(42); // Int to string: "42"
152
+ bool(1); // Int to bool: true
153
+ int("ff", 16); // Hex to int: 255
154
+ ```
190
155
 
191
- // Boolean
192
- bool active = true;
193
- bool disabled = false;
156
+ ### Type Checking
194
157
 
195
- // Dynamic (flexible, but slower)
196
- dynamic anything = "first string";
197
- anything = 123; // now int
198
- anything = 3.14; // now float
158
+ ```cssl
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
199
165
  ```
200
166
 
201
167
  ---
202
168
 
203
- ## Container Types
169
+ ## Variables & Globals
204
170
 
205
- ### stack\<T\>
171
+ ### Scope Behavior
206
172
 
207
- LIFO data structure (Last In, First Out).
173
+ Variables are **local by default**. Each function/class has its own scope - variables defined inside a function only exist within that function.
208
174
 
209
175
  ```cssl
210
- stack<string> names;
211
- names.push("Alice");
212
- names.push("Bob");
213
- names.push("Charlie");
176
+ define myFunction() {
177
+ string name = "Alice"; // Local to myFunction
178
+ printl(name); // Works
179
+ }
214
180
 
215
- printl(names); // ['Alice', 'Bob', 'Charlie']
216
- printl(names[0]); // "Alice" (index access)
217
- printl(len(names)); // 3
181
+ myFunction();
182
+ // printl(name); // Error! 'name' doesn't exist here
218
183
 
219
- string last = names.pop();
220
- printl(last); // "Charlie"
221
- ```
184
+ // Same variable name in different scopes = different variables
185
+ string name = "Bob";
222
186
 
223
- **Methods:**
187
+ define otherFunction() {
188
+ string name = "Charlie"; // Different variable, local to otherFunction
189
+ printl(name); // "Charlie"
190
+ }
224
191
 
225
- | Method | Description |
226
- |--------|-------------|
227
- | `.push(value)` | Add element |
228
- | `.pop()` | Remove and return last element |
229
- | `[index]` | Get element at index |
230
- | `len(stack)` | Number of elements |
192
+ otherFunction();
193
+ printl(name); // "Bob" - outer scope unchanged
194
+ ```
231
195
 
232
- ---
196
+ ### Everything is Local by Default
233
197
 
234
- ### vector\<T\>
198
+ All elements (variables, functions, classes) are **local by default** and must be explicitly marked global.
235
199
 
236
- Dynamic array.
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 { }` |
237
206
 
238
- ```cssl
239
- vector<int> numbers;
240
- numbers.push(10);
241
- numbers.push(20);
242
- numbers.push(30);
207
+ ### Local Variables
243
208
 
244
- printl(numbers); // [10, 20, 30]
245
- printl(numbers[1]); // 20
209
+ ```cssl
210
+ string name = "Alice";
211
+ int count = 10;
212
+ float price = 19.99;
213
+ bool active = true;
246
214
  ```
247
215
 
248
- **Methods:**
216
+ ### Global Variables
249
217
 
250
- | Method | Description |
251
- |--------|-------------|
252
- | `.push(value)` | Add element |
253
- | `.pop()` | Remove last element |
254
- | `[index]` | Element at index |
218
+ Use `global` keyword or `@`/`r@` prefix to create/access global variables:
255
219
 
256
- ---
220
+ ```cssl
221
+ // Declaration with 'global' keyword
222
+ global myGlobal = "visible everywhere";
257
223
 
258
- ### array\<T\>
224
+ // Access with '@' prefix
225
+ printl(@myGlobal);
259
226
 
260
- Static array.
227
+ // Direct global assignment with @ or r@
228
+ @anotherGlobal = "also global";
229
+ r@yetAnother = "and this too";
261
230
 
262
- ```cssl
263
- array<string> items;
264
- items.push("A");
265
- items.push("B");
266
- printl(items);
231
+ // Always read globals with @
232
+ printl(@x);
267
233
  ```
268
234
 
269
- ---
235
+ ### Global Functions
270
236
 
271
- ### datastruct\<T\>
237
+ ```cssl
238
+ // Global function with 'global' keyword
239
+ global define helper() {
240
+ printl("I'm global!");
241
+ }
272
242
 
273
- Universal container for BruteInjection operations.
243
+ // Alternative: @ prefix syntax
244
+ define @anotherHelper() {
245
+ printl("Also global!");
246
+ }
274
247
 
275
- ```cssl
276
- datastruct<string> data;
277
- data +<== someStack; // Copy data into it
248
+ // Global typed function
249
+ global void @utilityFunc(string msg) {
250
+ printl(msg);
251
+ }
278
252
  ```
279
253
 
280
- ---
254
+ ### Global Classes
281
255
 
282
- ### dataspace\<T\>
256
+ ```cssl
257
+ // Global class with 'global' keyword
258
+ global class SharedClass {
259
+ string value;
260
+ }
283
261
 
284
- Extended data space for complex operations.
262
+ // Alternative: @ prefix syntax
263
+ class @AnotherShared {
264
+ int count;
265
+ }
285
266
 
286
- ```cssl
287
- dataspace<dynamic> storage;
267
+ // Instantiate global class with @ prefix
268
+ instance = new @SharedClass();
288
269
  ```
289
270
 
290
- ---
271
+ ### Prefix Reference
291
272
 
292
- ### combo\<T\>
273
+ | Prefix | Name | Usage |
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` |
293
280
 
294
- Combo space for filtered searches.
281
+ ### Shared Objects ($)
282
+
283
+ Access Python objects shared via `CSSL.share()`:
295
284
 
296
285
  ```cssl
297
- combo<string> searchSpace;
298
- combo<open&string> filter = combo<open&string>::like="Hannes";
299
- ```
286
+ // Access shared Python object
287
+ $counter.value = 100;
288
+ $counter.increment();
300
289
 
301
- ---
290
+ // Delete shared object
291
+ delete("counter");
292
+ ```
302
293
 
303
- ### iterator\<T\>
294
+ ### Captured References (%)
304
295
 
305
- For iterations over data structures.
296
+ Capture value at registration time:
306
297
 
307
298
  ```cssl
308
- iterator<int> it;
309
-
310
- // 2D iterator with 16 fields
311
- iterator<iterator<int, 16>> Map;
312
- Map.insert(3, 12);
313
- Map.fill(0);
314
- int value = Map.at(3);
299
+ string version = "1.0";
300
+ savedVersion <<== { %version; }
301
+ version = "2.0";
302
+ printl(savedVersion); // Still "1.0"
315
303
  ```
316
304
 
317
- ---
318
-
319
- ### shuffled\<T\>
305
+ ### Class Member Access (this->)
320
306
 
321
- Container for multiple return values.
307
+ Inside classes, use `this->` to access instance members:
322
308
 
323
309
  ```cssl
324
- shuffled<string> results;
310
+ class Person {
311
+ string name;
325
312
 
326
- shuffled string getMultiple() {
327
- return "first", "second", "third";
313
+ void setName(string n) {
314
+ this->name = n; // Instance member
315
+ }
328
316
  }
329
317
  ```
330
318
 
331
319
  ---
332
320
 
333
- ## Variables & Globals
334
-
335
- ### Local Variables
336
-
337
- ```cssl
338
- string local = "only visible here";
339
- int number = 42;
340
- ```
341
-
342
- ### Global Variables
343
-
344
- ```cssl
345
- // Declaration with 'global'
346
- global myGlobal = "visible everywhere";
347
-
348
- // Access with '@' prefix
349
- printl(@myGlobal);
321
+ ## Operators
350
322
 
351
- // Or access directly without '@' (since v3.5.9)
352
- printl(myGlobal); // Works the same!
323
+ ### Arithmetic
353
324
 
354
- // Alternative: r@ syntax for declaration
355
- r@anotherGlobal = "also global";
356
- printl(@anotherGlobal);
357
- printl(anotherGlobal); // Also works
358
- ```
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` |
359
332
 
360
- ### Lookup Order
333
+ ### Comparison
361
334
 
362
- When accessing a variable, CSSL checks in order:
363
- 1. Local scope
364
- 2. Global scope
365
- 3. Promoted globals
366
- 4. Built-in functions
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` |
367
343
 
368
- ### Usage in Functions
344
+ ### Logical
369
345
 
370
- ```cssl
371
- global counter = 0;
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` |
372
354
 
373
- void increment() {
374
- @counter = @counter + 1;
375
- printl(@counter);
376
- }
355
+ ### Increment/Decrement (in for-loops)
377
356
 
378
- increment(); // 1
379
- increment(); // 2
380
- increment(); // 3
381
- ```
357
+ | Operator | Description | Example |
358
+ |----------|-------------|---------|
359
+ | `++` | Increment | `i++` |
360
+ | `--` | Decrement | `i--` |
361
+ | `+=` | Add assign | `i += 1` |
362
+ | `-=` | Subtract assign | `i -= 1` |
382
363
 
383
364
  ---
384
365
 
385
- ## Control Structures
366
+ ## Control Flow
386
367
 
387
368
  ### If / Else If / Else
388
369
 
389
370
  ```cssl
390
- int x = 10;
391
-
392
371
  if (x < 5) {
393
372
  printl("Small");
394
373
  } else if (x < 15) {
@@ -397,29 +376,17 @@ if (x < 5) {
397
376
  printl("Large");
398
377
  }
399
378
 
400
- // With logical operators
401
- if (x > 0 && x < 100) {
402
- printl("In range");
403
- }
404
-
405
- // Negation
406
- if (!active) {
407
- printl("Not active");
408
- }
409
-
410
- // Alternative negation
411
- if (not active) {
412
- printl("Not active");
379
+ // elif also works
380
+ if (x < 5) {
381
+ printl("Small");
382
+ } elif (x < 15) {
383
+ printl("Medium");
413
384
  }
414
385
  ```
415
386
 
416
- ---
417
-
418
387
  ### Switch / Case
419
388
 
420
389
  ```cssl
421
- int day = 3;
422
-
423
390
  switch (day) {
424
391
  case 1:
425
392
  printl("Monday");
@@ -427,16 +394,11 @@ switch (day) {
427
394
  case 2:
428
395
  printl("Tuesday");
429
396
  break;
430
- case 3:
431
- printl("Wednesday");
432
- break;
433
397
  default:
434
- printl("Other day");
398
+ printl("Other");
435
399
  }
436
400
  ```
437
401
 
438
- ---
439
-
440
402
  ### While Loop
441
403
 
442
404
  ```cssl
@@ -447,19 +409,17 @@ while (i < 5) {
447
409
  }
448
410
  ```
449
411
 
450
- ---
451
-
452
412
  ### For Loop (Python-Style)
453
413
 
454
414
  ```cssl
455
415
  // Range-based
456
- for (i in range(0, 5)) {
416
+ for (i in range(5)) {
457
417
  printl(i); // 0, 1, 2, 3, 4
458
418
  }
459
419
 
460
420
  // With start and end
461
- for (x in range(10, 15)) {
462
- printl(x); // 10, 11, 12, 13, 14
421
+ for (i in range(10, 15)) {
422
+ printl(i); // 10, 11, 12, 13, 14
463
423
  }
464
424
 
465
425
  // With step
@@ -468,66 +428,42 @@ for (i in range(0, 10, 2)) {
468
428
  }
469
429
  ```
470
430
 
471
- ---
472
-
473
431
  ### For Loop (C-Style)
474
432
 
475
433
  ```cssl
476
- // Classic C-style syntax
477
434
  for (int i = 0; i < 10; i++) {
478
435
  printl(i);
479
436
  }
480
437
 
481
- // With decrement
482
438
  for (int i = 10; i > 0; i--) {
483
439
  printl(i);
484
440
  }
485
-
486
- // With +=
487
- for (int i = 0; i < 100; i += 10) {
488
- printl(i); // 0, 10, 20, ...
489
- }
490
441
  ```
491
442
 
492
- ---
493
-
494
443
  ### Foreach
495
444
 
496
445
  ```cssl
497
446
  stack<string> names;
498
447
  names.push("Alice");
499
448
  names.push("Bob");
500
- names.push("Charlie");
501
449
 
502
- // Syntax 1: foreach (item in collection)
450
+ // Syntax 1
503
451
  foreach (name in names) {
504
452
  printl(name);
505
453
  }
506
454
 
507
- // Syntax 2: foreach collection as item
455
+ // Syntax 2
508
456
  foreach names as name {
509
457
  printl(name);
510
458
  }
511
459
  ```
512
460
 
513
- ---
514
-
515
461
  ### Break & Continue
516
462
 
517
463
  ```cssl
518
- // Break - exit loop early
519
- for (i in range(0, 10)) {
520
- if (i == 5) {
521
- break; // Stops at 5
522
- }
523
- printl(i);
524
- }
525
-
526
- // Continue - skip iteration
527
- for (i in range(0, 10)) {
528
- if (i == 3) {
529
- continue; // Skips 3
530
- }
464
+ for (i in range(10)) {
465
+ if (i == 5) break; // Exit loop
466
+ if (i == 3) continue; // Skip iteration
531
467
  printl(i);
532
468
  }
533
469
  ```
@@ -553,619 +489,731 @@ string getName() {
553
489
  int add(int a, int b) {
554
490
  return a + b;
555
491
  }
556
-
557
- // Call
558
- sayHello();
559
- string n = getName();
560
- int sum = add(5, 3);
561
- ```
562
-
563
- ### Named Parameters
564
-
565
- Functions can be called with named parameters for clarity.
566
-
567
- ```cssl
568
- // Define function
569
- int calculate(int base, int multiplier, int offset) {
570
- return base * multiplier + offset;
571
- }
572
-
573
- // Call with positional arguments
574
- int r1 = calculate(10, 5, 3); // 53
575
-
576
- // Call with named parameters
577
- int r2 = calculate(base=10, multiplier=5, offset=3); // 53
578
-
579
- // Mix positional and named (positional must come first)
580
- int r3 = calculate(10, multiplier=5, offset=3); // 53
581
-
582
- // Named parameters can be in any order
583
- int r4 = calculate(offset=3, base=10, multiplier=5); // 53
584
492
  ```
585
493
 
586
- ### Nested Functions
494
+ ### Define Functions
587
495
 
588
496
  ```cssl
589
- void inner() {
590
- printl("Inner function");
497
+ // Simple function without type
498
+ define greet() {
499
+ printl("Hello!");
591
500
  }
592
501
 
593
- void outer() {
594
- printl("Outer function");
595
- inner();
502
+ // With parameters
503
+ define greet(string name) {
504
+ printl("Hello " + name);
596
505
  }
597
-
598
- outer();
599
506
  ```
600
507
 
601
- ---
602
-
603
- ## Function Keywords
604
-
605
- ### undefined
508
+ ### Function Modifiers
606
509
 
607
- Function silently ignores errors.
608
-
609
- ```cssl
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
610
529
  undefined void mayFail() {
611
- riskyOperation(); // Errors are ignored
530
+ riskyOperation();
612
531
  }
613
- mayFail(); // No crash
614
- ```
615
-
616
- ---
617
-
618
- ### dynamic
619
-
620
- No type declaration needed.
621
-
622
- ```cssl
623
- dynamic x = "string";
624
- x = 123; // now int
625
- x = 3.14; // now float
626
- ```
627
-
628
- ---
629
-
630
- ### define
631
532
 
632
- Constant function without type and return.
633
-
634
- ```cssl
635
- define LOG_MESSAGE() {
636
- printl("Log message");
533
+ // Protected from injection
534
+ closed void protected() {
535
+ printl("Protected");
637
536
  }
638
- LOG_MESSAGE();
639
- ```
640
-
641
- ---
642
-
643
- ### closed
644
537
 
645
- Protects from external code injection.
646
-
647
- ```cssl
648
- closed void protectedFunc() {
649
- printl("Protected from external injections");
538
+ // Multiple returns
539
+ shuffled string getNames() {
540
+ return "Alice", "Bob", "Charlie";
650
541
  }
651
- // This injection will be BLOCKED:
652
- protectedFunc() <<== { printl("Blocked!"); }
653
- ```
654
542
 
655
- ---
543
+ a, b, c = getNames();
656
544
 
657
- ### private
545
+ // Any order of modifiers works
546
+ private string *@Myfunc() {
547
+ println("Hello from global private non-null function!");
548
+ return "Hey";
549
+ }
658
550
 
659
- Blocks ALL injections.
551
+ // Const function
552
+ const void immutableFunc() {
553
+ printl("I'm constant");
554
+ }
660
555
 
661
- ```cssl
662
- private void superSecure() {
663
- printl("Absolutely protected");
556
+ // Global private const
557
+ global private const void @MyGlobalFunc() {
558
+ printl("Complex modifiers in any order");
664
559
  }
665
560
  ```
666
561
 
667
- ---
668
-
669
- ### virtual
562
+ ### Typed Functions (Enforced Returns)
670
563
 
671
- Allows import cycles.
564
+ Functions with a return type (like `int`, `string`, `vector<T>`) MUST return that type:
672
565
 
673
566
  ```cssl
674
- virtual void safeForImport() {
675
- printl("Import-cycle-safe");
567
+ // MUST return string
568
+ string getName() {
569
+ return "Alice"; // OK
570
+ // return 42; // Error! Expected string
676
571
  }
677
- ```
678
572
 
679
- ---
680
-
681
- ### meta
682
-
683
- Declares function as source (must return).
573
+ // MUST return int
574
+ int getAge() {
575
+ return 30; // OK
576
+ }
684
577
 
685
- ```cssl
686
- meta string getSource() {
687
- return "Meta source";
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
688
582
  }
689
583
  ```
690
584
 
691
- ---
692
-
693
- ### super
585
+ ### Non-Null Functions (*)
694
586
 
695
- Forces execution without exceptions.
587
+ Functions that must never return null:
696
588
 
697
589
  ```cssl
698
- super void forceRun() {
699
- printl("Will ALWAYS execute");
590
+ // Non-null function
591
+ define *alwaysReturns() {
592
+ return "Always a value";
700
593
  }
701
- ```
702
594
 
703
- ---
595
+ // Non-null assertion on value
596
+ this->name = *$System.os; // Error if null
597
+ ```
704
598
 
705
- ### shuffled
599
+ ### Type Exclusion Filter (*[type])
706
600
 
707
- Allows multiple return values with tuple unpacking.
601
+ Functions that must NOT return a specific type:
708
602
 
709
603
  ```cssl
710
- shuffled string getNames() {
711
- return "Alice", "Bob", "Charlie";
604
+ // Must NOT return string
605
+ shuffled *[string] getNumbers() {
606
+ return 1, 2, 3; // OK
607
+ // return "text"; // Error!
712
608
  }
713
609
 
714
- // Tuple unpacking (v3.7.6+)
715
- a, b, c = getNames();
716
- printl(a); // "Alice"
717
- printl(b); // "Bob"
718
- printl(c); // "Charlie"
719
-
720
- // Works with any types
721
- shuffled getValues() {
722
- return "text", 42, true;
610
+ // Must NOT return null
611
+ define *[null] getValue() {
612
+ return 42; // OK
723
613
  }
724
- name, num, flag = getValues();
725
614
  ```
726
615
 
727
- ---
728
-
729
- ### open
730
-
731
- Accepts any parameters.
616
+ ### Open Parameters
732
617
 
733
618
  ```cssl
734
619
  open define flexibleFunc(open Params) {
735
620
  string name = OpenFind<string>(0);
736
621
  int num = OpenFind<int>(0);
737
- printl(name);
738
- printl(num);
622
+ printl(name + " " + num);
739
623
  }
740
624
 
741
- flexibleFunc("Hello", 123, true, "World");
625
+ flexibleFunc("Hello", 123, true);
742
626
  ```
743
627
 
744
628
  ---
745
629
 
746
- ## String Methods
747
-
748
- CSSL offers 40+ string methods:
630
+ ## Classes & OOP
749
631
 
750
- ### Search & Check
632
+ ### Class Definition
751
633
 
752
634
  ```cssl
753
- string s = "Hello World";
635
+ class Person {
636
+ string name;
637
+ int age;
754
638
 
755
- // Contains
756
- bool has = s.contains("World"); // true
639
+ // Constructor
640
+ void Person(string n, int a) {
641
+ this->name = n;
642
+ this->age = a;
643
+ }
757
644
 
758
- // Find position
759
- int pos = s.indexOf("o"); // 4
760
- int last = s.lastIndexOf("o"); // 7
645
+ void greet() {
646
+ printl("Hello, I'm " + this->name);
647
+ }
761
648
 
762
- // Start/end check
763
- bool start = s.startsWith("Hello"); // true
764
- bool end = s.endsWith("World"); // true
649
+ string getName() {
650
+ return this->name;
651
+ }
652
+ }
765
653
  ```
766
654
 
767
- ### Manipulation
655
+ ### Creating Instances
768
656
 
769
657
  ```cssl
770
- string s = "Hello World";
658
+ Person p = new Person("Alice", 30);
659
+ p.greet();
660
+ printl(p.name);
661
+ ```
771
662
 
772
- // Replace
773
- string r1 = s.replace("World", "CSSL"); // "Hello CSSL"
774
- string r2 = s.replaceAll("l", "L"); // "HeLLo WorLd"
663
+ ### Constructor with `constr` Keyword
775
664
 
776
- // Case
777
- string upper = s.toUpperCase(); // "HELLO WORLD"
778
- string lower = s.toLowerCase(); // "hello world"
665
+ ```cssl
666
+ class Vehicle {
667
+ string brand;
779
668
 
780
- // Trim
781
- string padded = " text ";
782
- string trimmed = padded.trim(); // "text"
669
+ constr Initialize(string b) {
670
+ this->brand = b;
671
+ }
783
672
 
784
- // Repeat
785
- string rep = "ab".repeat(3); // "ababab"
673
+ constr SetupDefaults() {
674
+ printl("Vehicle ready");
675
+ }
676
+ }
786
677
 
787
- // Reverse
788
- string rev = s.reverse(); // "dlroW olleH"
678
+ Vehicle v = new Vehicle("Toyota");
789
679
  ```
790
680
 
791
- ### Split & Join
681
+ ### Class Inheritance
792
682
 
793
683
  ```cssl
794
- string csv = "a,b,c,d";
795
-
796
- // Split
797
- stack<string> parts = csv.split(","); // ["a", "b", "c", "d"]
684
+ class Animal {
685
+ string name;
798
686
 
799
- // Join
800
- string joined = parts.join("-"); // "a-b-c-d"
801
- ```
687
+ void Animal(string n) {
688
+ this->name = n;
689
+ }
802
690
 
803
- ### Extract
691
+ void speak() {
692
+ printl("Sound");
693
+ }
694
+ }
804
695
 
805
- ```cssl
806
- string s = "Hello World";
696
+ class Dog : extends Animal {
697
+ void Dog(string n) {
698
+ this->name = n;
699
+ }
807
700
 
808
- // Substring
809
- string sub = s.substring(0, 5); // "Hello"
810
- string slc = s.slice(6, 11); // "World"
701
+ void speak() {
702
+ printl("Woof! I'm " + this->name);
703
+ }
704
+ }
811
705
 
812
- // Character
813
- string ch = s.charAt(0); // "H"
814
- int code = s.charCodeAt(0); // 72
706
+ Dog d = new Dog("Buddy");
707
+ d.speak(); // "Woof! I'm Buddy"
815
708
  ```
816
709
 
817
- ### Padding
710
+ ### super() and super::method()
818
711
 
819
712
  ```cssl
820
- string num = "42";
713
+ class Child : extends Parent {
714
+ constr ChildInit(string name) {
715
+ super(name); // Call parent constructor
716
+ }
821
717
 
822
- string padded1 = num.padStart(5, "0"); // "00042"
823
- string padded2 = num.padEnd(5, "."); // "42..."
718
+ void speak() {
719
+ super::speak(); // Call parent method
720
+ printl("Child speaking");
721
+ }
722
+ }
824
723
  ```
825
724
 
826
- ### All String Methods
827
-
828
- | Method | Description |
829
- |--------|-------------|
830
- | `.contains(str)` | Check if string contains |
831
- | `.indexOf(str)` | First position of str |
832
- | `.lastIndexOf(str)` | Last position of str |
833
- | `.startsWith(str)` | Starts with str? |
834
- | `.endsWith(str)` | Ends with str? |
835
- | `.find(str)` | Find position (-1 if not found) |
836
- | `.split(delimiter)` | Split into array |
837
- | `.join(delimiter)` | Join array to string |
838
- | `.replace(old, new)` | Replace first occurrence |
839
- | `.replaceAll(old, new)` | Replace all occurrences |
840
- | `.substring(start, end)` | Extract substring |
841
- | `.slice(start, end)` | Substring (like substring) |
842
- | `.substr(start, length)` | Substring with length |
843
- | `.toLowerCase()` | To lowercase |
844
- | `.toUpperCase()` | To uppercase |
845
- | `.trim()` | Remove whitespace |
846
- | `.charAt(index)` | Character at position |
847
- | `.charCodeAt(index)` | ASCII code at position |
848
- | `.padStart(len, char)` | Pad left |
849
- | `.padEnd(len, char)` | Pad right |
850
- | `.repeat(n)` | Repeat n times |
851
- | `.reverse()` | Reverse |
852
- | `.count(str)` | Count occurrences |
853
- | `len(string)` | String length |
725
+ ### Append Mode (++)
854
726
 
855
- ---
727
+ Extend constructors/functions while keeping original code:
856
728
 
857
- ## File I/O
729
+ ```cssl
730
+ // Original function
731
+ define BaseFunc() {
732
+ printl("Base functionality");
733
+ }
858
734
 
859
- CSSL provides built-in functions for file operations.
735
+ // Append to BaseFunc
736
+ define ExtendedFunc() &BaseFunc ++ {
737
+ printl("Extended functionality");
738
+ }
860
739
 
861
- ### Basic File Operations
740
+ ExtendedFunc();
741
+ // Output:
742
+ // Base functionality
743
+ // Extended functionality
744
+ ```
862
745
 
863
746
  ```cssl
864
- // Read entire file
865
- string content = read("/path/to/file.txt");
866
- printl(content);
747
+ class MyClass {
748
+ constr MyClassConstructor() {
749
+ printl("MyClass constructor");
750
+ this->value = 10;
751
+ }
752
+ }
867
753
 
868
- // Read specific line (1-indexed)
869
- string line5 = readline(5, "/path/to/file.txt");
870
- printl(line5);
754
+ class BetterClass :: extends MyClass {
755
+ constr BetterConstructor() &MyClass::MyClassConstructor ++ {
756
+ printl("BetterClass - added code");
757
+ this->extra = 20;
758
+ }
759
+ }
760
+ ```
871
761
 
872
- // Write to file (overwrites)
873
- write("/path/to/file.txt", "Hello World");
762
+ ### Non-Null Class
874
763
 
875
- // Write/replace specific line
876
- writeline(3, "New line content", "/path/to/file.txt");
764
+ ```cssl
765
+ class *MyClass {
766
+ // All methods must return non-null
767
+ string getValue() {
768
+ return "Value";
769
+ }
770
+ }
877
771
  ```
878
772
 
879
- ### Extended File Functions
773
+ ---
774
+
775
+ ## Container Types
776
+
777
+ ### stack\<T\> - LIFO Stack
880
778
 
881
779
  ```cssl
882
- // Read all lines as array
883
- stack<string> lines = readlines("/path/to/file.txt");
780
+ stack<string> names;
781
+ names.push("Alice");
782
+ names.push("Bob");
884
783
 
885
- // Append to file
886
- appendfile("/path/to/file.txt", "\nNew content");
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 |
887
804
 
888
- // File checks
889
- bool exists = pathexists("/path/to/file.txt");
890
- bool isFile = isfile("/path/to/file.txt");
891
- bool isDir = isdir("/path/to/folder");
805
+ ### vector\<T\> - Dynamic Array
892
806
 
893
- // File size
894
- int size = filesize("/path/to/file.txt");
807
+ ```cssl
808
+ vector<int> nums;
809
+ nums.push(10);
810
+ nums.push(20);
895
811
 
896
- // Directory listing
897
- stack<string> files = listdir("/path/to/folder");
812
+ printl(nums.at(0)); // 10
813
+ printl(nums.front()); // 10
814
+ printl(nums.back()); // 20
898
815
  ```
899
816
 
900
- ### Path Functions
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
901
845
 
902
846
  ```cssl
903
- // Path manipulation
904
- string base = basename("/path/to/file.txt"); // "file.txt"
905
- string dir = dirname("/path/to/file.txt"); // "/path/to"
906
- string full = joinpath("/path", "to", "file.txt"); // "/path/to/file.txt"
907
- string abs = abspath("./file.txt"); // "/current/dir/file.txt"
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");
908
854
  ```
909
855
 
910
- ### All File I/O Functions
856
+ **Methods:**
911
857
 
912
- | Function | Description |
913
- |----------|-------------|
914
- | `read(path)` | Read entire file content |
915
- | `readline(line, path)` | Read specific line (1-indexed) |
916
- | `write(path, content)` | Write content to file |
917
- | `writeline(line, content, path)` | Write/replace specific line |
918
- | `readfile(path)` | Read file (alias for read) |
919
- | `writefile(path, content)` | Write file (alias for write) |
920
- | `readlines(path)` | Read all lines as array |
921
- | `appendfile(path, content)` | Append to file |
922
- | `pathexists(path)` | Check if path exists |
923
- | `isfile(path)` | Check if is file |
924
- | `isdir(path)` | Check if is directory |
925
- | `filesize(path)` | Get file size in bytes |
926
- | `listdir(path)` | List directory contents |
927
- | `makedirs(path)` | Create directories |
928
- | `removefile(path)` | Delete file |
929
- | `removedir(path)` | Delete empty directory |
930
- | `copyfile(src, dst)` | Copy file |
931
- | `movefile(src, dst)` | Move file |
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 |
932
872
 
933
- ---
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
+ ```
934
884
 
935
- ## JSON Functions
885
+ **Methods:**
936
886
 
937
- CSSL provides namespace-style JSON functions with the `json::` prefix.
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 |
938
894
 
939
- ### Reading & Writing JSON Files
895
+ ### shuffled\<T\> - Multiple Returns
940
896
 
941
897
  ```cssl
942
- // Read and parse JSON file
943
- json data = json::read("/path/to/config.json");
944
- printl(data.name);
898
+ shuffled string getInfo() {
899
+ return "Alice", "Bob", "Charlie";
900
+ }
945
901
 
946
- // Write data to JSON file
947
- json::write("/path/to/output.json", data);
902
+ a, b, c = getInfo();
903
+ printl(a); // "Alice"
948
904
  ```
949
905
 
950
- ### JSON Parsing & Stringifying
906
+ ---
907
+
908
+ ## Built-in Functions
909
+
910
+ ### String Operations
951
911
 
952
912
  ```cssl
953
- // Parse JSON string
954
- string jsonStr = '{"name": "Alice", "age": 30}';
955
- json obj = json::parse(jsonStr);
913
+ string s = "Hello World";
956
914
 
957
- // Convert to JSON string
958
- string str = json::stringify(obj);
915
+ // Case
916
+ upper(s); // "HELLO WORLD"
917
+ lower(s); // "hello world"
918
+ capitalize(s); // "Hello world"
919
+ title(s); // "Hello World"
959
920
 
960
- // Pretty print with indentation
961
- string pretty = json::pretty(obj);
962
- printl(pretty);
963
- ```
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"
964
946
 
965
- ### JSON Path Operations
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
966
970
 
967
- ```cssl
968
- json data = json::read("config.json");
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]
969
983
 
970
- // Get value by dot-path
971
- string name = json::get(data, "user.name");
972
- int age = json::get(data, "user.profile.age");
973
- string city = json::get(data, "address.city", "Unknown"); // with default
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
974
990
 
975
- // Set value by dot-path
976
- data = json::set(data, "user.name", "Bob");
977
- data = json::set(data, "settings.theme", "dark");
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
978
995
 
979
- // Check if path exists
980
- if (json::has(data, "user.email")) {
981
- printl("Email exists");
982
- }
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"}
983
1027
  ```
984
1028
 
985
- ### JSON Object Operations
1029
+ ### Math Functions
986
1030
 
987
1031
  ```cssl
988
- json obj = json::read("data.json");
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
989
1037
 
990
- // Get all keys
991
- stack<string> keys = json::keys(obj);
992
- foreach (key in keys) {
993
- printl(key);
994
- }
1038
+ round(3.14159, 2); // 3.14
1039
+ floor(3.9); // 3
1040
+ ceil(3.1); // 4
995
1041
 
996
- // Get all values
997
- stack<dynamic> values = json::values(obj);
1042
+ pow(2, 3); // 8
1043
+ sqrt(16); // 4
1044
+ mod(7, 3); // 1
998
1045
 
999
- // Deep merge objects
1000
- json merged = json::merge(obj1, obj2, obj3);
1001
- ```
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
1002
1053
 
1003
- ### All JSON Functions
1054
+ log(e()); // 1.0
1055
+ log10(100); // 2.0
1056
+ exp(1); // 2.71828
1004
1057
 
1005
- | Function | Description |
1006
- |----------|-------------|
1007
- | `json::read(path)` | Read and parse JSON file |
1008
- | `json::write(path, data)` | Write data to JSON file |
1009
- | `json::parse(str)` | Parse JSON string to object |
1010
- | `json::stringify(data)` | Convert to JSON string |
1011
- | `json::pretty(data)` | Pretty print JSON |
1012
- | `json::get(data, path, default)` | Get value by dot-path |
1013
- | `json::set(data, path, value)` | Set value by dot-path |
1014
- | `json::has(data, path)` | Check if path exists |
1015
- | `json::keys(data)` | Get all keys |
1016
- | `json::values(data)` | Get all values |
1017
- | `json::merge(obj1, obj2, ...)` | Deep merge objects |
1058
+ pi(); // 3.14159...
1059
+ e(); // 2.71828...
1060
+ radians(180); // 3.14159
1061
+ degrees(3.14159); // 180
1018
1062
 
1019
- ---
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
+ ```
1020
1081
 
1021
- ## Instance Management
1082
+ ### File I/O Functions
1022
1083
 
1023
- CSSL provides `instance<"name">` syntax and `instance::` namespace for working with shared instances.
1084
+ ```cssl
1085
+ // Read
1086
+ string content = read("file.txt");
1087
+ string line5 = readline(5, "file.txt");
1088
+ stack<string> lines = readlines("file.txt");
1024
1089
 
1025
- ### Instance Declaration
1090
+ // Write
1091
+ write("file.txt", "Hello");
1092
+ writeline(3, "New line", "file.txt");
1093
+ appendfile("file.txt", "\nMore");
1026
1094
 
1027
- ```cssl
1028
- // Get/create shared instance by name
1029
- instance<"MyApp"> app;
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");
1030
1101
 
1031
- // With initialization
1032
- instance<"tk"> tk = include("tkinter.cssl-mod");
1102
+ // Checks
1103
+ pathexists("file.txt"); // true/false
1104
+ isfile("file.txt"); // true/false
1105
+ isdir("folder"); // true/false
1106
+ filesize("file.txt"); // bytes
1033
1107
 
1034
- // Register object as shared instance
1035
- myModule ==> $AppModule
1036
- // Or using instance syntax:
1037
- myModule ==> instance<"AppModule">
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");
1038
1115
  ```
1039
1116
 
1040
- ### Instance Introspection
1117
+ ### JSON Functions (json:: namespace)
1041
1118
 
1042
1119
  ```cssl
1043
- @tk = include("tk.cssl-mod");
1044
-
1045
- // Get all methods from module
1046
- stack<string> methods = instance::getMethods(@tk);
1047
- foreach (m in methods) {
1048
- printl("Method: " + m);
1049
- }
1120
+ // File operations
1121
+ json data = json::read("config.json");
1122
+ json::write("output.json", data);
1050
1123
 
1051
- // Get all classes
1052
- stack<string> classes = instance::getClasses(@tk);
1124
+ // Parse/Stringify
1125
+ json obj = json::parse('{"name": "Alice"}');
1126
+ string str = json::stringify(obj);
1127
+ string pretty = json::pretty(obj);
1053
1128
 
1054
- // Get all variables
1055
- stack<string> vars = instance::getVars(@tk);
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");
1056
1134
 
1057
- // Get everything categorized
1058
- json all = instance::getAll(@tk);
1059
- printl(all.methods); // ["method1", "method2", ...]
1060
- printl(all.classes); // ["Class1", "Class2", ...]
1061
- printl(all.vars); // ["var1", "var2", ...]
1135
+ // Object operations
1136
+ json::keys(obj); // ["name"]
1137
+ json::values(obj); // ["Alice"]
1138
+ json::merge(obj1, obj2); // Deep merge
1062
1139
  ```
1063
1140
 
1064
- ### Dynamic Method Calls
1141
+ ### Instance Functions (instance:: namespace)
1065
1142
 
1066
1143
  ```cssl
1067
- // Call method dynamically by name
1068
- result = instance::call(@module, "methodName", arg1, arg2);
1144
+ @module = include("lib.cssl-mod");
1069
1145
 
1070
- // Check if method/attribute exists
1071
- if (instance::has(@module, "initialize")) {
1072
- instance::call(@module, "initialize");
1073
- }
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
1074
1154
 
1075
- // Get type name
1076
- string typeName = instance::type(@module);
1077
- printl(typeName); // "module"
1155
+ isavailable("sharedName"); // Check if exists
1078
1156
  ```
1079
1157
 
1080
- ### All Instance Functions
1158
+ ### Regex Functions
1081
1159
 
1082
- | Function | Description |
1083
- |----------|-------------|
1084
- | `instance<"name"> var` | Declare instance variable |
1085
- | `obj ==> instance<"name">` | Register as shared instance |
1086
- | `instance::getMethods(obj)` | Get all method names |
1087
- | `instance::getClasses(obj)` | Get all class names |
1088
- | `instance::getVars(obj)` | Get all variable names |
1089
- | `instance::getAll(obj)` | Get categorized dict |
1090
- | `instance::call(obj, 'name', ...)` | Call method dynamically |
1091
- | `instance::has(obj, 'name')` | Check if attribute exists |
1092
- | `instance::type(obj)` | Get type name |
1093
- | `isavailable("name")` | Check if shared instance exists |
1094
- | `instance::exists("name")` | Alias for isavailable |
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
+ ```
1095
1167
 
1096
- ---
1168
+ ### Hash Functions
1097
1169
 
1098
- ## Live Object Sharing
1170
+ ```cssl
1171
+ md5("hello"); // 32 hex chars
1172
+ sha1("hello"); // 40 hex chars
1173
+ sha256("hello"); // 64 hex chars
1174
+ ```
1099
1175
 
1100
- Share Python objects with CSSL. Changes in CSSL reflect back to Python.
1176
+ ### System Functions
1101
1177
 
1102
- ### Python Side
1178
+ ```cssl
1179
+ exit(0); // Exit with code
1180
+ input("Enter name: "); // Read user input
1103
1181
 
1104
- ```python
1105
- from includecpp import CSSL
1182
+ env("PATH"); // Get env variable
1183
+ setenv("MY_VAR", "val"); // Set env variable
1106
1184
 
1107
- class Counter:
1108
- def __init__(self):
1109
- self.value = 100
1185
+ copy(obj); // Shallow copy
1186
+ deepcopy(obj); // Deep copy
1110
1187
 
1111
- counter = Counter()
1112
- cssl = CSSL.CsslLang()
1113
- cssl.share(counter, "cnt")
1188
+ clear(); // Clear console
1114
1189
 
1115
- # Changes in CSSL will reflect in Python!
1116
- cssl.exec('''
1117
- $cnt.value = $cnt.value - 10;
1118
- printl($cnt.value); // 90
1119
- ''')
1190
+ pyimport("os"); // Import Python module
1191
+ include("lib.cssl-mod"); // Import CSSL module
1192
+ payload("helper.cssl-pl"); // Load payload
1120
1193
 
1121
- print(counter.value) # 90 - Changed!
1194
+ isLinux(); // Platform checks
1195
+ isWindows();
1196
+ isMac();
1122
1197
  ```
1123
1198
 
1124
- ### CSSL Syntax
1125
-
1126
- | Syntax | Description |
1127
- |--------|-------------|
1128
- | `$name` | Access shared object |
1129
- | `$name.property` | Access/modify properties |
1130
- | `$name.method()` | Call methods |
1131
- | `delete("name")` | Remove shared object |
1132
-
1133
- ### Loop Modifications
1134
-
1135
- ```python
1136
- # Python
1137
- class Stats:
1138
- def __init__(self):
1139
- self.total = 100
1140
-
1141
- stats = Stats()
1142
- cssl = CSSL.CsslLang()
1143
- cssl.share(stats, "s")
1144
-
1145
- cssl.exec('''
1146
- for (i in range(0, 5)) {
1147
- $s.total = $s.total - 10;
1148
- }
1149
- printl($s.total); // 50
1150
- ''')
1199
+ ### Filter Functions (filter:: namespace)
1151
1200
 
1152
- print(stats.total) # 50 - Persisted!
1201
+ ```cssl
1202
+ // Register custom filter
1203
+ filter::register("custom", "handler", callback);
1204
+ filter::unregister("custom", "handler");
1205
+ filter::list(); // All registered filters
1206
+ filter::exists("custom", "handler");
1153
1207
  ```
1154
1208
 
1155
1209
  ---
1156
1210
 
1157
1211
  ## CodeInfusion
1158
1212
 
1159
- CodeInfusion enables modifying functions at runtime.
1160
-
1161
- > **Important**: Injection operators must be written **without spaces**:
1162
- > - ✓ `func() <<==` / `func() +<<==` / `func() -<<==` (correct)
1163
- > - ✗ `func() < <==` / `func() + <<==` / `func() - <<==` (wrong)
1213
+ Modify functions at runtime.
1164
1214
 
1165
1215
  ### <<== (Replace)
1166
1216
 
1167
- Replaces function content.
1168
-
1169
1217
  ```cssl
1170
1218
  void original() {
1171
1219
  printl("Original");
@@ -1178,11 +1226,7 @@ original() <<== {
1178
1226
  original(); // "Replaced"
1179
1227
  ```
1180
1228
 
1181
- ---
1182
-
1183
- ### +<<== (Add)
1184
-
1185
- Adds code to function (executes BEFORE original).
1229
+ ### +<<== (Add Before)
1186
1230
 
1187
1231
  ```cssl
1188
1232
  void base() {
@@ -1199,12 +1243,8 @@ base();
1199
1243
  // Base
1200
1244
  ```
1201
1245
 
1202
- ---
1203
-
1204
1246
  ### -<<== (Remove)
1205
1247
 
1206
- Removes code from function.
1207
-
1208
1248
  ```cssl
1209
1249
  void withExtra() {
1210
1250
  printl("Important");
@@ -1218,114 +1258,35 @@ withExtra() -<<== {
1218
1258
  withExtra(); // Only "Important"
1219
1259
  ```
1220
1260
 
1221
- ---
1222
-
1223
- ### exit() Injection
1224
-
1225
- Special injection for program end.
1261
+ ### Exit Injection
1226
1262
 
1227
1263
  ```cssl
1228
1264
  exit() <<== {
1229
- printl("Cleanup before exit...");
1265
+ printl("Cleanup...");
1230
1266
  }
1231
1267
 
1232
- // Later:
1233
1268
  exit(); // Executes injection
1234
1269
  ```
1235
1270
 
1236
1271
  ---
1237
1272
 
1238
- ## Value Capture
1239
-
1240
- The `%identifier` syntax captures values at registration time, useful for saving original functions before replacement.
1241
-
1242
- ### Capturing Variables
1243
-
1244
- ```cssl
1245
- string version = "1.0.0";
1246
-
1247
- // Capture current value
1248
- v <== { %version; }
1249
- printl(v); // "1.0.0"
1250
-
1251
- // Even if version changes later, v keeps captured value
1252
- version = "2.0.0";
1253
- printl(v); // Still "1.0.0"
1254
- ```
1255
-
1256
- ### Capturing Functions
1257
-
1258
- ```cssl
1259
- // Save original exit function before replacing
1260
- originalExit <<== { %exit(); }
1261
-
1262
- // Replace exit with custom behavior
1263
- exit() <<== {
1264
- printl("Custom cleanup...");
1265
- originalExit(); // Call saved original
1266
- }
1267
-
1268
- exit();
1269
- // Output:
1270
- // Custom cleanup...
1271
- // (original exit behavior)
1272
- ```
1273
-
1274
- ### Use Cases
1275
-
1276
- ```cssl
1277
- // 1. Preserving original behavior
1278
- void myFunc() {
1279
- printl("Original");
1280
- }
1281
-
1282
- savedFunc <<== { %myFunc(); }
1283
-
1284
- myFunc() <<== {
1285
- printl("Modified");
1286
- }
1287
-
1288
- myFunc(); // "Modified"
1289
- savedFunc(); // "Original"
1290
-
1291
- // 2. Capturing configuration at startup
1292
- global config = loadConfig();
1293
- startupConfig <== { %config; }
1294
-
1295
- // 3. Snapshot values for later comparison
1296
- int counter = 0;
1297
- initial <== { %counter; }
1298
- // ... operations ...
1299
- if (counter != initial) {
1300
- printl("Counter changed!");
1301
- }
1302
- ```
1303
-
1304
- ---
1305
-
1306
1273
  ## BruteInjection
1307
1274
 
1308
- BruteInjection copies/moves data between containers.
1275
+ Transfer data between containers.
1309
1276
 
1310
1277
  ### +<== (Copy)
1311
1278
 
1312
- Copies data to target (source unchanged).
1313
-
1314
1279
  ```cssl
1315
1280
  stack<string> source;
1316
1281
  source.push("A");
1317
1282
  source.push("B");
1318
1283
 
1319
1284
  datastruct<string> target;
1320
- target +<== source; // Copies A, B
1285
+ target +<== source; // Copy A, B (source unchanged)
1321
1286
  ```
1322
1287
 
1323
- ---
1324
-
1325
1288
  ### -<== (Move)
1326
1289
 
1327
- Moves data (removes from source).
1328
-
1329
1290
  ```cssl
1330
1291
  stack<string> src;
1331
1292
  src.push("Data");
@@ -1334,25 +1295,17 @@ datastruct<string> dst;
1334
1295
  dst -<== src; // src is empty after
1335
1296
  ```
1336
1297
 
1337
- ---
1338
-
1339
1298
  ### ==> (Replace)
1340
1299
 
1341
- Replaces target data completely.
1342
-
1343
1300
  ```cssl
1344
1301
  stack<string> data;
1345
1302
  data.push("New");
1346
1303
 
1347
1304
  datastruct<string> container;
1348
- container ==> data;
1305
+ container ==> data; // Replace container content
1349
1306
  ```
1350
1307
 
1351
- ---
1352
-
1353
- ### ==>- (Receive Minus)
1354
-
1355
- Removes matching items from target.
1308
+ ### ==>- (Remove Matching)
1356
1309
 
1357
1310
  ```cssl
1358
1311
  stack<string> names;
@@ -1363,1142 +1316,186 @@ names.push("Alice");
1363
1316
  stack<string> toRemove;
1364
1317
  toRemove.push("Alice");
1365
1318
 
1366
- // Remove all "Alice" from names
1367
1319
  names ==>- toRemove;
1368
1320
  printl(names); // ["Bob"]
1369
1321
  ```
1370
1322
 
1371
- ---
1372
-
1373
- ## Filter Syntax
1374
-
1375
- Filters enable targeted data operations in BruteInjection.
1376
-
1377
- ### Syntax
1323
+ ### Filter Syntax
1378
1324
 
1379
1325
  ```cssl
1380
1326
  target +<== [type::filter=value] source;
1381
- ```
1382
-
1383
- ### String Filters
1384
-
1385
- ```cssl
1386
- stack<string> fruits;
1387
- fruits.push("Apple");
1388
- fruits.push("Banana");
1389
- fruits.push("Apricot");
1390
-
1391
- datastruct<string> result;
1392
1327
 
1393
- // Exact match
1328
+ // String filters
1394
1329
  result +<== [string::where="Apple"] fruits;
1395
-
1396
- // Everything except
1397
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;
1398
1335
 
1399
- // Contains substring
1400
- result +<== [string::contains="App"] fruits; // Apple, Apricot
1401
-
1402
- // String length
1403
- result +<== [string::length=5] fruits; // Apple
1336
+ // Other filters
1337
+ result +<== [integer::where=42] numbers;
1338
+ result +<== [json::key="name"] objects;
1404
1339
  ```
1405
1340
 
1406
- ### String Cutting Filters
1341
+ ---
1342
+
1343
+ ## Value Capture
1407
1344
 
1408
- Cut strings at specific positions or substrings.
1345
+ Capture values at registration time with `%`:
1409
1346
 
1410
1347
  ```cssl
1411
- string version = "1.0.0-beta";
1348
+ string version = "1.0.0";
1349
+ savedVersion <<== { %version; }
1412
1350
 
1413
- // Cut at position (integer index)
1414
- x = <==[string::cut=3] version;
1415
- printl(x); // "1.0" (first 3 chars)
1351
+ version = "2.0.0";
1352
+ printl(savedVersion); // "1.0.0" (captured value)
1353
+ ```
1416
1354
 
1417
- // Cut at substring position
1418
- x = <==[string::cut="0-"] version;
1419
- printl(x); // "1.0." (before "0-")
1355
+ ### Capturing Functions
1420
1356
 
1421
- // Get everything after substring
1422
- x = <==[string::cutAfter=".0."] version;
1423
- printl(x); // "0-beta" (after ".0.")
1357
+ ```cssl
1358
+ originalExit <<== { %exit(); }
1424
1359
 
1425
- // Cut after at position
1426
- x = <==[string::cutAfter=4] version;
1427
- printl(x); // ".0-beta" (after index 4)
1360
+ exit() <<== {
1361
+ printl("Custom cleanup");
1362
+ originalExit();
1363
+ }
1428
1364
  ```
1429
1365
 
1430
- ### All Filters
1431
-
1432
- | Filter | Description |
1433
- |--------|-------------|
1434
- | `string::where=VALUE` | Exact string match |
1435
- | `string::not=VALUE` | Everything except this value |
1436
- | `string::contains=VALUE` | Contains substring |
1437
- | `string::length=LENGTH` | Exact string length |
1438
- | `string::cut=INDEX` | Cut at index (returns first N chars) |
1439
- | `string::cut="SUBSTR"` | Cut at substring position |
1440
- | `string::cutAfter=INDEX` | Get everything after index |
1441
- | `string::cutAfter="SUBSTR"` | Get everything after substring |
1442
- | `integer::where=VALUE` | Exact int match |
1443
- | `json::key=KEYNAME` | Filter by JSON key |
1444
- | `json::value=VALUE` | Filter by JSON value |
1445
- | `array::index=INDEX` | By array index |
1446
- | `vector::where=VALUE` | Exact vector match |
1447
- | `combo::filterdb` | Combo FilterDB |
1448
-
1449
1366
  ---
1450
1367
 
1451
1368
  ## Module System
1452
1369
 
1453
- ### Create Module
1454
-
1455
- Create CSSL module from Python file:
1456
-
1457
- ```bash
1458
- python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
1459
- ```
1460
-
1461
- ### Import Module
1370
+ ### Import CSSL Module
1462
1371
 
1463
1372
  ```cssl
1464
- // Import Python module
1465
- @Math = include("mymath.cssl-mod");
1466
-
1467
- // Import CSSL file
1468
- @Utils = include("utils.cssl");
1469
-
1470
- // Call module functions
1373
+ @Math = include("mathlib.cssl-mod");
1471
1374
  int result = @Math.add(5, 3);
1472
- string text = @Utils.format("Hello");
1473
1375
  ```
1474
1376
 
1475
- ### Example: Python Module
1476
-
1477
- **mathlib.py:**
1478
- ```python
1479
- def add(a, b):
1480
- return a + b
1377
+ ### Import Python Module
1481
1378
 
1482
- def multiply(a, b):
1483
- return a * b
1379
+ ```cssl
1380
+ @os = pyimport("os");
1381
+ string cwd = @os.getcwd();
1484
1382
 
1485
- def square(x):
1486
- return x * x
1383
+ @datetime = pyimport("datetime");
1384
+ @datetime.datetime.now();
1487
1385
  ```
1488
1386
 
1489
- **Create module:**
1490
- ```bash
1491
- python -m includecpp cssl makemodule mathlib.py -o mathlib.cssl-mod
1492
- ```
1387
+ ### Load Payload
1493
1388
 
1494
- **Use in CSSL:**
1495
1389
  ```cssl
1496
- @Math = include("mathlib.cssl-mod");
1390
+ payload("helpers.cssl-pl");
1391
+ ```
1497
1392
 
1498
- int sum = @Math.add(10, 20); // 30
1499
- int product = @Math.multiply(5, 6); // 30
1500
- int sq = @Math.square(8); // 64
1393
+ ### Create Module (CLI)
1501
1394
 
1502
- printl(sum);
1503
- printl(product);
1504
- printl(sq);
1395
+ ```bash
1396
+ python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
1505
1397
  ```
1506
1398
 
1507
1399
  ---
1508
1400
 
1509
- ## Parameter Bridge
1510
-
1511
- Communication between Python and CSSL.
1512
-
1513
- ### parameter.get()
1401
+ ## Error Handling
1514
1402
 
1515
- Receive parameters from Python:
1403
+ ### Try / Catch
1516
1404
 
1517
1405
  ```cssl
1518
- // In CSSL
1519
- string name = parameter.get(0); // First parameter
1520
- int count = parameter.get(1); // Second parameter
1521
- printl(name);
1522
- printl(count);
1523
- ```
1524
-
1525
- ```python
1526
- # In Python
1527
- CSSL.exec(code, "Alice", 42)
1528
- ```
1529
-
1530
- ### parameter.return()
1531
-
1532
- Return value to Python:
1533
-
1534
- ```cssl
1535
- // In CSSL
1536
- int result = 10 + 20;
1537
- parameter.return(result);
1538
- ```
1539
-
1540
- ```python
1541
- # In Python
1542
- result = CSSL.exec(code)
1543
- print(result) # 30
1544
- ```
1545
-
1546
- ### Complete Example
1547
-
1548
- ```python
1549
- from includecpp import CSSL
1550
-
1551
- CSSL.CsslLang()
1552
-
1553
- code = """
1554
- int a = parameter.get(0);
1555
- int b = parameter.get(1);
1556
- int sum = a + b;
1557
- parameter.return(sum);
1558
- """
1559
-
1560
- result = CSSL.exec(code, 15, 27)
1561
- print(f"Result: {result}") # Result: 42
1562
- ```
1563
-
1564
- ### Supported Return Types
1565
-
1566
- ```cssl
1567
- parameter.return(true); // bool
1568
- parameter.return(42); // int
1569
- parameter.return(3.14); // float
1570
- parameter.return("Hello"); // string
1571
- parameter.return(myStack); // stack/array
1572
- parameter.return(myObject); // JSON/dict
1573
- ```
1574
-
1575
- ---
1576
-
1577
- ## Classes & OOP
1578
-
1579
- CSSL supports object-oriented programming with classes, constructors, and the `this->` keyword for member access.
1580
-
1581
- ### Defining a Class
1582
-
1583
- ```cssl
1584
- class Person {
1585
- // Member variables
1586
- string name;
1587
- int age;
1588
-
1589
- // Constructor (same name as class)
1590
- void Person(string n, int a) {
1591
- this->name = n;
1592
- this->age = a;
1593
- }
1594
-
1595
- // Methods
1596
- void greet() {
1597
- printl("Hello, I'm " + this->name);
1598
- }
1599
-
1600
- string getName() {
1601
- return this->name;
1602
- }
1603
-
1604
- void setAge(int a) {
1605
- this->age = a;
1606
- }
1607
- }
1608
- ```
1609
-
1610
- ### Creating Instances
1611
-
1612
- ```cssl
1613
- // Use 'new' keyword to instantiate
1614
- Person p = new Person("Alice", 30);
1615
-
1616
- // Call methods
1617
- p.greet(); // prints: "Hello, I'm Alice"
1618
- string name = p.getName(); // returns "Alice"
1619
-
1620
- // Access members (if public)
1621
- printl(p.name); // prints: "Alice"
1622
- p.age = 31; // set member directly
1623
- ```
1624
-
1625
- ### The `this->` Keyword
1626
-
1627
- Inside class methods, use `this->` to access instance members:
1628
-
1629
- ```cssl
1630
- class Counter {
1631
- int count;
1632
-
1633
- void Counter() {
1634
- this->count = 0;
1635
- }
1636
-
1637
- void increment() {
1638
- this->count = this->count + 1;
1639
- }
1640
-
1641
- void add(int n) {
1642
- this->count = this->count + n;
1643
- }
1644
-
1645
- int get() {
1646
- return this->count;
1647
- }
1648
- }
1649
-
1650
- Counter c = new Counter();
1651
- c.increment();
1652
- c.add(5);
1653
- printl(c.get()); // prints: 6
1654
- ```
1655
-
1656
- ### Constructor Variations
1657
-
1658
- ```cssl
1659
- class MyClass {
1660
- // Constructor with same name as class
1661
- void MyClass(int x) {
1662
- this->value = x;
1663
- }
1664
- }
1665
-
1666
- // Alternative: use __init__
1667
- class MyClass2 {
1668
- void __init__(int x) {
1669
- this->value = x;
1670
- }
1671
- }
1672
- ```
1673
-
1674
- ### Method Chaining
1675
-
1676
- ```cssl
1677
- class Builder {
1678
- string result;
1679
-
1680
- void Builder() {
1681
- this->result = "";
1682
- }
1683
-
1684
- Builder add(string s) {
1685
- this->result = this->result + s;
1686
- return this;
1687
- }
1688
-
1689
- string build() {
1690
- return this->result;
1691
- }
1692
- }
1693
-
1694
- Builder b = new Builder();
1695
- string result = b.add("Hello ").add("World!").build();
1696
- printl(result); // prints: "Hello World!"
1697
- ```
1698
-
1699
- ### Class Inheritance (extends)
1700
-
1701
- CSSL supports class inheritance using the `: extends` syntax:
1702
-
1703
- ```cssl
1704
- // Base class
1705
- class Animal {
1706
- string name;
1707
-
1708
- void Animal(string n) {
1709
- this->name = n;
1710
- }
1711
-
1712
- void speak() {
1713
- printl("Some sound");
1714
- }
1715
- }
1716
-
1717
- // Derived class - inherits all members and methods from Animal
1718
- class Dog : extends Animal {
1719
- void Dog(string n) {
1720
- this->name = n;
1721
- }
1722
-
1723
- // Override parent method
1724
- void speak() {
1725
- printl("Woof! I'm " + this->name);
1726
- }
1727
-
1728
- // New method only in Dog
1729
- void fetch() {
1730
- printl(this->name + " fetches the ball!");
1731
- }
1732
- }
1733
-
1734
- Dog d = new Dog("Buddy");
1735
- d.speak(); // "Woof! I'm Buddy"
1736
- d.fetch(); // "Buddy fetches the ball!"
1737
- ```
1738
-
1739
- ### Extending Python Objects
1740
-
1741
- You can extend Python classes/objects directly:
1742
-
1743
- ```cssl
1744
- // Extend a Python object using $
1745
- class ExtendedGame : extends $GameEngine {
1746
- void newFeature() {
1747
- printl("New CSSL feature!");
1748
- }
1749
-
1750
- // Override a Python method
1751
- void showUsername() {
1752
- printl("Custom username display: " + this->username);
1753
- }
1754
- }
1755
- ```
1756
-
1757
- In Python:
1758
- ```python
1759
- class GameEngine:
1760
- def __init__(self):
1761
- self.username = "Player1"
1762
- def showUsername(self):
1763
- print(f"Username: {self.username}")
1764
-
1765
- cssl = CSSL.CsslLang()
1766
- cssl.share('GameEngine', GameEngine())
1767
- cssl.run('''
1768
- class MyGame : extends $GameEngine {
1769
- void customMethod() {
1770
- printl("Extended from Python!");
1771
- }
1772
- }
1773
- ''')
1774
- ```
1775
-
1776
- ### Class Overwrites
1777
-
1778
- Use `: overwrites` to replace methods in an existing class/object:
1779
-
1780
- ```cssl
1781
- // Overwrite methods in a Python object
1782
- class MyOverrides : extends $GameEngine : overwrites $GameEngine {
1783
- // This method will REPLACE the original showUsername() in $GameEngine
1784
- void showUsername() {
1785
- printl("OVERWRITTEN: " + this->username);
1786
- }
1787
- }
1788
- ```
1789
-
1790
- When you use `: overwrites TargetClass`, all methods defined in your class will replace the corresponding methods in the target. This works with:
1791
- - Other CSSL classes
1792
- - Python objects via `$ObjectName`
1793
- - Shared objects
1794
-
1795
- ### python::csslize() - Import Python Objects
1796
-
1797
- Convert Python objects to CSSL-compatible wrappers:
1798
-
1799
- ```cssl
1800
- // Import a Python object
1801
- py_obj <== python::csslize($MyPythonInstance);
1802
-
1803
- // Now use it like a CSSL object
1804
- py_obj.someMethod();
1805
- printl(py_obj.someProperty);
1806
-
1807
- // Or use it as a base class
1808
- class Extended : extends py_obj {
1809
- void newMethod() { ... }
1810
- }
1811
- ```
1812
-
1813
- In Python:
1814
- ```python
1815
- class MyPythonClass:
1816
- def __init__(self, name):
1817
- self.name = name
1818
- def greet(self):
1819
- return f"Hello, {self.name}!"
1820
-
1821
- cssl = CSSL.CsslLang()
1822
- cssl.share('MyPython', MyPythonClass("World"))
1823
- result = cssl.run('''
1824
- py_obj <== python::csslize($MyPython);
1825
- printl(py_obj.greet()); // "Hello, World!"
1826
- ''')
1827
- ```
1828
-
1829
- ### Function Extends & Overwrites
1830
-
1831
- Functions can also extend or overwrite other functions:
1832
-
1833
- ```cssl
1834
- // Base function
1835
- define baseFunction() {
1836
- string greeting = "Hello";
1837
- int count = 42;
1838
- printl(greeting);
1839
- }
1840
-
1841
- // Extend: inherit local variables from baseFunction
1842
- define extendedFunc : extends baseFunction() {
1843
- // 'greeting' and 'count' are available here!
1844
- printl(greeting + " World! Count: " + count);
1845
- }
1846
-
1847
- // Overwrite: replace the original function
1848
- define myReplacement : overwrites baseFunction() {
1849
- printl("This replaces baseFunction entirely!");
1850
- }
1851
-
1852
- // After defining myReplacement, calling baseFunction()
1853
- // will now execute myReplacement instead
1854
- baseFunction(); // prints: "This replaces baseFunction entirely!"
1855
- ```
1856
-
1857
- Overwriting Python functions:
1858
- ```cssl
1859
- // Replace a shared Python function
1860
- define myVersion : overwrites $pythonFunc() {
1861
- printl("CSSL implementation replaces Python!");
1862
- }
1863
- ```
1864
-
1865
- ### Non-Null Declarations
1866
-
1867
- Use `*` prefix to declare non-nullable items:
1868
-
1869
- ```cssl
1870
- // Non-null variable - can never be None
1871
- vector<dynamic> *myList; // Always initialized, never null
1872
-
1873
- // Non-null function - must never return None
1874
- define *alwaysReturns() {
1875
- return "Always a value"; // Error if returns null
1876
- }
1877
-
1878
- // Non-null class - all methods return non-null
1879
- class *MyClass {
1880
- string getValue() {
1881
- return "Value"; // All methods must return non-null
1882
- }
1883
- }
1884
-
1885
- // Non-null open parameter - filters out None values
1886
- define process(open *Params) {
1887
- // Params will never contain None values
1888
- foreach item in Params {
1889
- printl(item); // Guaranteed non-null
1890
- }
1891
- }
1892
- ```
1893
-
1894
- ### Class Constructors with `constr` Keyword
1895
-
1896
- The `constr` keyword defines explicit constructors inside classes. Multiple constructors can be defined and will be executed in order.
1897
-
1898
- ```cssl
1899
- // Class with constructor parameters in declaration
1900
- class Vehicle (string brand, int year) {
1901
- string make;
1902
- int modelYear;
1903
-
1904
- // Constructor using constr keyword
1905
- constr Initialize() {
1906
- // brand and year are available from class parameters
1907
- this->make = brand;
1908
- this->modelYear = year;
1909
- }
1910
-
1911
- // Additional constructor - executed after Initialize
1912
- constr SetupDefaults() {
1913
- printl("Vehicle created: " + this->make);
1914
- }
1915
- }
1916
-
1917
- Vehicle v = new Vehicle("Toyota", 2024);
1918
- ```
1919
-
1920
- ### Constructor Inheritance with `super()`
1921
-
1922
- Use `super()` to call parent class constructors and methods:
1923
-
1924
- ```cssl
1925
- class Animal {
1926
- string name;
1927
-
1928
- void Animal(string n) {
1929
- this->name = n;
1930
- }
1931
-
1932
- void speak() {
1933
- printl("Generic sound");
1934
- }
1935
- }
1936
-
1937
- class Dog : extends Animal {
1938
- string breed;
1939
-
1940
- constr DogInit(string n, string b) {
1941
- super(n); // Call parent constructor with name
1942
- this->breed = b;
1943
- }
1944
-
1945
- void speak() {
1946
- super::speak(); // Call parent's speak method
1947
- printl("Woof! I'm " + this->name);
1948
- }
1949
- }
1950
-
1951
- Dog d = new Dog("Buddy", "Labrador");
1952
- d.speak();
1953
- // Output:
1954
- // Generic sound
1955
- // Woof! I'm Buddy
1956
- ```
1957
-
1958
- ### Constructor Extends with Arguments
1959
-
1960
- Pass arguments to parent constructors in class declaration:
1961
-
1962
- ```cssl
1963
- class Parent {
1964
- int value;
1965
-
1966
- void Parent(int v) {
1967
- this->value = v;
1968
- }
1969
- }
1970
-
1971
- // Pass arguments to parent constructor using extends (arg1, arg2)
1972
- class Child : extends Parent ("defaultValue") {
1973
- constr ChildInit() {
1974
- // Parent constructor already called with "defaultValue"
1975
- printl("Child value: " + this->value);
1976
- }
1977
- }
1978
- ```
1979
-
1980
- ### Method-Level Extends & Overwrites
1981
-
1982
- Functions and methods can extend or overwrite specific methods in parent classes using `::` syntax:
1983
-
1984
- ```cssl
1985
- class Base {
1986
- constr Init() {
1987
- printl("Base init");
1988
- }
1989
-
1990
- void process() {
1991
- printl("Base processing");
1992
- }
1993
- }
1994
-
1995
- class Derived : extends Base {
1996
- // Extend specific parent constructor
1997
- constr DerivedInit() :: extends Base::Init {
1998
- // Base::Init local vars are available here
1999
- printl("Derived init");
2000
- }
2001
-
2002
- // Or define a method that extends parent method
2003
- define customProcess :: extends Base::process() {
2004
- // Has access to Base::process local variables
2005
- printl("Extended processing");
2006
- }
2007
- }
2008
- ```
2009
-
2010
- ### Append Mode with `++` Operator
2011
-
2012
- The `++` append operator allows you to extend constructors and functions by keeping the original code and adding new code. This is useful for extending behavior without completely replacing it.
2013
-
2014
- #### Basic Function Append
2015
-
2016
- ```cssl
2017
- // Original function
2018
- define BaseFunc() {
2019
- printl("Base functionality");
2020
- }
2021
-
2022
- // Append to BaseFunc - keeps original + adds new
2023
- define ExtendedFunc() &BaseFunc ++ {
2024
- printl("Extended functionality");
2025
- }
2026
-
2027
- ExtendedFunc();
2028
- // Output:
2029
- // Base functionality
2030
- // Extended functionality
2031
- ```
2032
-
2033
- #### Constructor Append with Class Reference
2034
-
2035
- ```cssl
2036
- class MyClass {
2037
- constr MyClassConstructor() {
2038
- printl("MyClass constructor");
2039
- this->value = 10;
2040
- }
2041
- }
2042
-
2043
- class BetterClass :: extends MyClass {
2044
- // Append to specific parent constructor
2045
- constr BetterConstructor() &MyClass::MyClassConstructor ++ {
2046
- printl("BetterClass - added code");
2047
- this->extra = 20;
2048
- }
2049
- }
2050
-
2051
- $instance = new BetterClass();
2052
- // Output:
2053
- // MyClass constructor
2054
- // BetterClass - added code
2055
- printl($instance.value); // 10
2056
- printl($instance.extra); // 20
2057
- ```
2058
-
2059
- #### Method Append
2060
-
2061
- ```cssl
2062
- class Parent {
2063
- define greet() {
2064
- printl("Hello from Parent");
2065
- }
2066
- }
2067
-
2068
- class Child :: extends Parent {
2069
- // Append to parent method
2070
- define betterGreet() &Parent::greet ++ {
2071
- printl("And also from Child!");
2072
- }
2073
- }
2074
-
2075
- $child = new Child();
2076
- $child.betterGreet();
2077
- // Output:
2078
- // Hello from Parent
2079
- // And also from Child!
2080
- ```
2081
-
2082
- #### Dynamic Instance Reference
2083
-
2084
- You can also reference methods from instances using `&$instanceVar::member`:
2085
-
2086
- ```cssl
2087
- global $myInstance = new SomeClass();
2088
-
2089
- class Extended {
2090
- define extendedMethod() &$myInstance::originalMethod ++ {
2091
- printl("Added to instance method");
2092
- }
2093
- }
2094
- ```
2095
-
2096
- #### Append Mode Syntax Summary
2097
-
2098
- | Syntax | Description |
2099
- |--------|-------------|
2100
- | `&FunctionName ++` | Append to a function |
2101
- | `&ClassName::member ++` | Append to a class member (constructor/method) |
2102
- | `&$instanceVar::member ++` | Append to an instance member |
2103
- | `&ClassName::constructors ++` | Append to all constructors of a class |
2104
-
2105
- ---
2106
-
2107
- ## Map Container
2108
-
2109
- The `map<>` type provides C++ style ordered key-value storage.
2110
-
2111
- ### Creating Maps
2112
-
2113
- ```cssl
2114
- map<string, int> ages;
2115
- map<string, string> config;
2116
- ```
2117
-
2118
- ### Basic Operations
2119
-
2120
- ```cssl
2121
- map<string, int> ages;
2122
-
2123
- // Insert values
2124
- ages.insert("Alice", 30);
2125
- ages.insert("Bob", 25);
2126
-
2127
- // Find values
2128
- int age = ages.find("Alice"); // returns 30
2129
-
2130
- // Check existence
2131
- if (ages.contains("Alice")) {
2132
- printl("Found!");
2133
- }
2134
-
2135
- // Erase entries
2136
- ages.erase("Bob");
2137
-
2138
- // Get with exception if not found
2139
- int a = ages.at("Alice"); // throws if not found
2140
-
2141
- // Size and empty check
2142
- int size = ages.size();
2143
- bool empty = ages.empty();
2144
- ```
2145
-
2146
- ### Iteration and Bounds
2147
-
2148
- ```cssl
2149
- map<string, int> data;
2150
- data.insert("apple", 1);
2151
- data.insert("banana", 2);
2152
- data.insert("cherry", 3);
2153
-
2154
- // Get first/last elements
2155
- tuple first = data.begin(); // ("apple", 1)
2156
- tuple last = data.end(); // ("cherry", 3)
2157
-
2158
- // Find bounds (for sorted keys)
2159
- string lb = data.lower_bound("b"); // "banana" (first key >= "b")
2160
- string ub = data.upper_bound("b"); // "cherry" (first key > "b")
2161
- ```
2162
-
2163
- ---
2164
-
2165
- ## Structures
2166
-
2167
- Structures are user-defined data types.
2168
-
2169
- ```cssl
2170
- structure Person {
2171
- string name;
2172
- int age;
2173
- string email;
2174
- }
2175
-
2176
- // Create instance
2177
- Person user;
2178
- user.name = "Max";
2179
- user.age = 25;
2180
- user.email = "max@example.com";
2181
-
2182
- printl(user.name); // "Max"
2183
- printl(user.age); // 25
2184
- ```
2185
-
2186
- ### With Functions
2187
-
2188
- ```cssl
2189
- structure Rectangle {
2190
- int width;
2191
- int height;
2192
- }
2193
-
2194
- int calculateArea(Rectangle rect) {
2195
- return rect.width * rect.height;
1406
+ try {
1407
+ riskyOperation();
1408
+ } catch (error) {
1409
+ printl("Error: " + error);
2196
1410
  }
2197
1411
 
2198
- Rectangle r;
2199
- r.width = 10;
2200
- r.height = 5;
2201
- int area = calculateArea(r);
2202
- printl(area); // 50
2203
- ```
2204
-
2205
- ---
2206
-
2207
- ## Error Handling
2208
-
2209
- ### Try / Catch
2210
-
2211
- ```cssl
2212
1412
  try {
2213
- // Risky code
2214
- int result = riskyOperation();
2215
- printl(result);
2216
- } catch {
2217
- printl("An error occurred");
1413
+ operation();
1414
+ } catch (error) {
1415
+ printl("Error");
1416
+ } finally {
1417
+ printl("Always runs");
2218
1418
  }
2219
1419
  ```
2220
1420
 
2221
- ### With undefined
1421
+ ### Undefined Functions
2222
1422
 
2223
1423
  ```cssl
2224
1424
  undefined void safeOperation() {
2225
- // Errors are silently ignored
2226
- dangerousCode();
1425
+ dangerousCode(); // Errors ignored
2227
1426
  }
2228
-
2229
- safeOperation(); // No crash
2230
1427
  ```
2231
1428
 
2232
- ---
2233
-
2234
- ## CLI Commands
2235
-
2236
- ### Execute
2237
-
2238
- ```bash
2239
- # Execute CSSL file
2240
- python -m includecpp cssl exec script.cssl
2241
-
2242
- # Execute CSSL code directly
2243
- python -m includecpp cssl exec -c "printl('Hello');"
2244
- ```
2245
-
2246
- ### Create Module
2247
-
2248
- ```bash
2249
- # From Python file
2250
- python -m includecpp cssl makemodule mylib.py -o mylib.cssl-mod
2251
-
2252
- # With output path
2253
- python -m includecpp cssl makemodule src/utils.py -o modules/utils.cssl-mod
2254
- ```
2255
-
2256
- ### Help
2257
-
2258
- ```bash
2259
- python -m includecpp cssl --help
2260
- python -m includecpp cssl exec --help
2261
- python -m includecpp cssl makemodule --help
2262
- ```
2263
-
2264
- ---
2265
-
2266
- ## Examples
2267
-
2268
- ### Tkinter GUI Calendar
1429
+ ### Assert
2269
1430
 
2270
1431
  ```cssl
2271
- // Import modules
2272
- @Gui = include("modules/tkgui.cssl-mod");
2273
-
2274
- // Global state
2275
- global currentMonth = 0;
2276
- global currentYear = 0;
2277
-
2278
- // Initialize
2279
- void init() {
2280
- @currentYear = @Gui.get_current_year();
2281
- @currentMonth = @Gui.get_current_month();
2282
- }
2283
-
2284
- // Build calendar
2285
- void buildCalendar() {
2286
- stack<string> days;
2287
- days.push("Mo");
2288
- days.push("Tu");
2289
- days.push("We");
2290
- days.push("Th");
2291
- days.push("Fr");
2292
- days.push("Sa");
2293
- days.push("Su");
2294
-
2295
- // Header with for-loop
2296
- for (i in range(0, 7)) {
2297
- @Gui.add_label(days[i], i * 40, 50);
2298
- }
2299
-
2300
- // Days with C-style for
2301
- int daysInMonth = @Gui.get_days_in_month(@currentYear, @currentMonth);
2302
- for (int d = 1; d <= daysInMonth; d++) {
2303
- @Gui.add_button("" + d, d);
2304
- }
2305
- }
2306
-
2307
- // Main
2308
- init();
2309
- @Gui.create_window("CSSL Calendar", 350, 400);
2310
- buildCalendar();
2311
- @Gui.run();
1432
+ assert(x > 0, "x must be positive");
2312
1433
  ```
2313
1434
 
2314
1435
  ---
2315
1436
 
2316
- ### Task Manager with CodeInfusion
2317
-
2318
- ```cssl
2319
- global tasks = stack<string>;
2320
-
2321
- void addTask(string task) {
2322
- @tasks.push(task);
2323
- printl("+ " + task);
2324
- }
2325
-
2326
- void showTasks() {
2327
- printl("=== Tasks ===");
2328
- foreach (task in @tasks) {
2329
- printl("- " + task);
2330
- }
2331
- }
2332
-
2333
- void completeTask() {
2334
- string done = @tasks.pop();
2335
- printl("Completed: " + done);
2336
- }
2337
-
2338
- // Add logging via CodeInfusion
2339
- addTask() +<<== {
2340
- printl("[LOG] Adding task...");
2341
- }
2342
-
2343
- // Exit handler
2344
- exit() <<== {
2345
- printl("Shutting down Task Manager...");
2346
- }
2347
-
2348
- // Application
2349
- addTask("Write code");
2350
- addTask("Run tests");
2351
- addTask("Update documentation");
2352
- showTasks();
2353
- completeTask();
2354
- exit();
2355
- ```
2356
-
2357
- ---
2358
-
2359
- ### Data Pipeline with BruteInjection
2360
-
2361
- ```cssl
2362
- // Source data
2363
- stack<string> rawData;
2364
- rawData.push("Alice");
2365
- rawData.push("Bob");
2366
- rawData.push("Charlie");
2367
- rawData.push("Alex");
2368
- rawData.push("Anna");
2369
-
2370
- // Filter: Only names containing "A"
2371
- datastruct<string> aNames;
2372
- aNames +<== [string::contains="A"] rawData;
2373
-
2374
- // Output
2375
- printl("Names with A:");
2376
- foreach (name in aNames) {
2377
- printl(" - " + name);
2378
- }
2379
- // Output: Alice, Alex, Anna
2380
- ```
2381
-
2382
- ---
2383
-
2384
- ### Python-CSSL Bridge
2385
-
2386
- ```python
2387
- from includecpp import CSSL
2388
-
2389
- CSSL.CsslLang()
2390
-
2391
- # Syntax checker in CSSL
2392
- checker = """
2393
- global errors = stack<string>;
2394
-
2395
- void checkLine(string line) {
2396
- if (line.startsWith("def ") && !line.endsWith(":")) {
2397
- @errors.push("Missing colon after def");
2398
- }
2399
- if (line.startsWith("if ") && !line.endsWith(":")) {
2400
- @errors.push("Missing colon after if");
2401
- }
2402
- }
2403
-
2404
- define analyze() {
2405
- string code = parameter.get(0);
2406
- stack<string> lines = code.split("\\n");
2407
-
2408
- foreach (line in lines) {
2409
- checkLine(line);
2410
- }
2411
-
2412
- if (len(@errors) == 0) {
2413
- parameter.return("OK");
2414
- } else {
2415
- parameter.return(@errors);
2416
- }
2417
- }
2418
-
2419
- analyze();
2420
- """
2421
-
2422
- # Check Python code
2423
- test_code = """def hello()
2424
- print("world")"""
2425
-
2426
- result = CSSL.exec(checker, test_code)
2427
- print(result) # ["Missing colon after def"]
2428
- ```
2429
-
2430
- ---
2431
-
2432
- ## Reference Table
1437
+ ## Quick Reference
2433
1438
 
2434
1439
  ### Keywords
2435
1440
 
2436
1441
  | Keyword | Description |
2437
1442
  |---------|-------------|
2438
- | `void` | Function without return |
1443
+ | `void` | No return value |
2439
1444
  | `return` | Return value |
2440
- | `global` | Declare global variable |
2441
- | `r@` | Alternative global syntax |
2442
- | `@` | Access global variable |
2443
- | `if` / `else if` / `else` | Conditions |
1445
+ | `global` | Declare global |
1446
+ | `if` / `else` / `elif` | Conditionals |
2444
1447
  | `switch` / `case` / `default` | Switch statement |
2445
1448
  | `for` / `foreach` / `while` | Loops |
2446
1449
  | `break` / `continue` | Loop control |
2447
- | `try` / `catch` | Error handling |
1450
+ | `try` / `catch` / `finally` | Error handling |
1451
+ | `class` / `new` / `this` | OOP |
1452
+ | `extends` / `overwrites` | Inheritance |
1453
+ | `constr` | Constructor |
1454
+ | `define` | Function definition |
2448
1455
  | `undefined` | Ignore errors |
2449
- | `dynamic` | Dynamic type |
2450
- | `define` | Constant function |
2451
- | `closed` | Block external injection |
2452
- | `private` | Block all injections |
2453
- | `virtual` | Import-cycle-safe |
2454
- | `meta` | Source function |
2455
- | `super` | Forced execution |
1456
+ | `closed` / `private` | Injection protection |
1457
+ | `virtual` | Import-safe |
1458
+ | `meta` / `super` | Special function types |
2456
1459
  | `shuffled` | Multiple returns |
2457
1460
  | `open` | Any parameters |
2458
- | `structure` | User-defined type |
2459
- | `include` | Import module |
1461
+ | `include` / `get` | Import modules |
2460
1462
 
2461
1463
  ### Injection Operators
2462
1464
 
2463
1465
  | Operator | Type | Description |
2464
1466
  |----------|------|-------------|
2465
1467
  | `<<==` | CodeInfusion | Replace function |
2466
- | `+<<==` | CodeInfusion | Add code (before) |
1468
+ | `+<<==` | CodeInfusion | Add code before |
2467
1469
  | `-<<==` | CodeInfusion | Remove code |
2468
- | `<==` | ValueCapture | Capture/assign value |
1470
+ | `<==` | ValueCapture | Capture/assign |
2469
1471
  | `+<==` | BruteInjection | Copy data |
2470
1472
  | `-<==` | BruteInjection | Move data |
2471
1473
  | `==>` | BruteInjection | Replace data |
2472
- | `==>-` | BruteInjection | Remove matching items |
2473
- | `++` | AppendMode | Append to parent (with `&ref`) |
1474
+ | `==>-` | BruteInjection | Remove matching |
1475
+ | `++` | AppendMode | Append to parent |
2474
1476
 
2475
1477
  ### Special Syntax
2476
1478
 
2477
1479
  | Syntax | Description |
2478
1480
  |--------|-------------|
2479
- | `%identifier` | Capture value at registration time |
2480
- | `json::func()` | Namespace function call |
2481
- | `@name` | Access global variable |
2482
- | `$name` | Access shared Python object |
2483
- | `s@name` | Self-reference to struct |
2484
- | `r@name` | Global variable declaration |
2485
- | `&ClassName::member` | Reference class member for append mode |
2486
- | `&$instance::member` | Reference instance member for append mode |
2487
- | `&FunctionName ++` | Append to function (keeps old + adds new) |
2488
-
2489
- ---
2490
-
2491
- ## Tips & Best Practices
2492
-
2493
- 1. **Type Safety**: Use explicit types instead of `dynamic` for better performance
2494
- 2. **Global Variables**: Use sparingly, always access with `@`
2495
- 3. **For Loops**: Python-style for simple iterations, C-style when `++`/`--` needed
2496
- 4. **CodeInfusion**: Protect with `closed`/`private` when necessary
2497
- 5. **Modules**: Python modules for complex logic, CSSL for business logic
2498
- 6. **Error Handling**: `try/catch` for external calls, `undefined` for optional operations
2499
- 7. **String Operations**: Use built-in methods instead of manual manipulation
2500
- 8. **Live Objects**: Use `$name` syntax for bidirectional Python-CSSL data sharing
1481
+ | `@name` | Global variable access |
1482
+ | `@name = value` | Global variable assignment |
1483
+ | `r@name = value` | Global reference assignment |
1484
+ | `$name` | Shared Python object |
1485
+ | `%name` | Captured value |
1486
+ | `this->` | Class member access |
1487
+ | `super::method()` | Parent method call |
1488
+ | `json::func()` | Namespace function |
1489
+ | `&ClassName::member` | Class member reference |
1490
+ | `&FunctionName ++` | Append to function |
1491
+ | `*func()` | Non-null function |
1492
+ | `*[type]func()` | Type exclusion filter |
1493
+ | `global class Name` | Global class declaration |
1494
+ | `class @Name` | Global class (alt syntax) |
1495
+ | `global define func()` | Global function declaration |
1496
+ | `define @func()` | Global function (alt syntax) |
1497
+ | `new @ClassName()` | Instantiate global class |
2501
1498
 
2502
1499
  ---
2503
1500
 
2504
- *CSSL v3.6.3 - Developed as part of IncludeCPP*
1501
+ *CSSL v4.0.0 - Developed as part of IncludeCPP*