IncludeCPP 3.8.9__py3-none-any.whl → 4.0.2__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,9 +1,96 @@
1
1
  """
2
2
  CSSL Bridge - Type Stubs for Python API
3
+
4
+ CSSL (C-Style Scripting Language) is a scripting language that bridges Python and C++ style syntax.
5
+ This module provides the Python API for executing CSSL code and sharing objects between Python and CSSL.
6
+
7
+ Quick Start:
8
+ from includecpp import CSSL
9
+
10
+ # Execute CSSL code directly
11
+ CSSL.run('printl("Hello from CSSL!");')
12
+
13
+ # Execute a CSSL file
14
+ CSSL.run("script.cssl", arg1, arg2)
15
+
16
+ # Share Python objects with CSSL (live reference)
17
+ my_data = {"count": 0}
18
+ CSSL.share(my_data, "data")
19
+ CSSL.run('$data.count = $data.count + 1;')
20
+ print(my_data["count"]) # 1
21
+
22
+ # Create reusable modules
23
+ math_mod = CSSL.makemodule('''
24
+ int add(int a, int b) { return a + b; }
25
+ ''')
26
+ result = math_mod.add(2, 3) # 5
3
27
  """
4
28
 
5
29
  import threading
6
- from typing import Any, List, Optional, Callable, Dict
30
+ from typing import Any, List, Optional, Callable, Dict, Union
31
+
32
+
33
+ class CSSLScript:
34
+ """
35
+ A typed CSSL script object.
36
+
37
+ Created via CSSL.script() - represents a bundle of CSSL code that can be
38
+ executed multiple times or combined into modules.
39
+
40
+ Script Types:
41
+ - "cssl": Main script - the primary entry point
42
+ - "cssl-pl": Payload - helper code loaded via payload()
43
+
44
+ Usage:
45
+ from includecpp import CSSL
46
+
47
+ # Create a main script
48
+ main = CSSL.script("cssl", '''
49
+ printl("Running main script");
50
+ helper();
51
+ ''')
52
+
53
+ # Create a payload (helper functions)
54
+ helpers = CSSL.script("cssl-pl", '''
55
+ void helper() {
56
+ printl("Helper called!");
57
+ }
58
+ ''')
59
+
60
+ # Execute the script
61
+ main.run()
62
+
63
+ # Or combine into a module
64
+ mod = CSSL.makemodule(main, helpers, "mymodule")
65
+ """
66
+
67
+ def __init__(self, cssl_instance: 'CsslLang', script_type: str, code: str, *params: Any) -> None: ...
68
+
69
+ @property
70
+ def code(self) -> str:
71
+ """Get the script's CSSL source code."""
72
+ ...
73
+
74
+ @property
75
+ def is_payload(self) -> bool:
76
+ """Check if this script is a payload (cssl-pl) type."""
77
+ ...
78
+
79
+ def run(self, *args: Any) -> Any:
80
+ """
81
+ Execute this script with optional arguments.
82
+
83
+ Args:
84
+ *args: Arguments accessible in CSSL via parameter.get(index)
85
+
86
+ Returns:
87
+ Execution result
88
+ """
89
+ ...
90
+
91
+ def __call__(self, *args: Any) -> Any:
92
+ """Allow calling the script directly: script() is same as script.run()"""
93
+ ...
7
94
 
8
95
 
9
96
  class CSSLModule:
@@ -12,12 +99,34 @@ class CSSLModule:
12
99
 
13
100
  Created via CSSL.module() - the code is executed each time the module is called,
14
101
  with arguments accessible via parameter.get(index).
102
+
103
+ Usage:
104
+ from includecpp import CSSL
105
+
106
+ # Create a simple greeting module
107
+ greet = CSSL.module('''
108
+ string name = parameter.get(0);
109
+ printl("Hello, " + name + "!");
110
+ ''')
111
+
112
+ greet("World") # Prints: Hello, World!
113
+ greet("Alice") # Prints: Hello, Alice!
114
+
115
+ # Module with multiple parameters
116
+ calc = CSSL.module('''
117
+ int a = parameter.get(0);
118
+ int b = parameter.get(1);
119
+ parameter.return(a + b);
120
+ ''')
121
+ result = calc(10, 20) # Returns 30
15
122
  """
16
123
 
17
124
  def __init__(self, cssl_instance: 'CsslLang', code: str) -> None: ...
125
+
18
126
  def __call__(self, *args: Any) -> Any:
19
127
  """Execute the module code with the given arguments."""
20
128
  ...
129
+
21
130
  def __repr__(self) -> str: ...
22
131
 
23
132
 
@@ -26,28 +135,84 @@ class CSSLFunctionModule:
26
135
  A CSSL module with accessible functions as methods.
27
136
 
28
137
  Created via CSSL.makemodule() - functions defined in the CSSL code
29
- become callable attributes on this module.
138
+ become callable attributes on this module. This is the recommended way
139
+ to create reusable CSSL libraries.
140
+
141
+ Usage:
142
+ from includecpp import CSSL
143
+
144
+ # Create a math module with multiple functions
145
+ math_mod = CSSL.makemodule('''
146
+ int add(int a, int b) {
147
+ return a + b;
148
+ }
149
+
150
+ int multiply(int a, int b) {
151
+ return a * b;
152
+ }
153
+
154
+ float average(int a, int b) {
155
+ return (a + b) / 2.0;
156
+ }
157
+ ''')
158
+
159
+ # Call functions as attributes
160
+ print(math_mod.add(2, 3)) # 5
161
+ print(math_mod.multiply(4, 5)) # 20
162
+ print(math_mod.average(10, 20)) # 15.0
163
+
164
+ # List available functions
165
+ print(dir(math_mod)) # ['add', 'average', 'multiply']
30
166
  """
31
167
 
32
168
  def __init__(self, cssl_instance: 'CsslLang', code: str) -> None: ...
169
+
33
170
  def __getattr__(self, name: str) -> Callable[..., Any]:
34
- """Get a function from the module."""
171
+ """Get a function from the module by name."""
35
172
  ...
173
+
36
174
  def __dir__(self) -> List[str]:
37
- """List available functions."""
175
+ """List all available functions in this module."""
38
176
  ...
177
+
39
178
  def __repr__(self) -> str: ...
40
179
 
41
180
 
42
181
  class CsslLang:
43
182
  """
44
- CSSL Language interface for Python.
183
+ CSSL Language runtime interface for Python.
45
184
 
46
- Usage:
185
+ This is the main class for interacting with CSSL from Python. It provides
186
+ methods for executing code, sharing objects, creating modules, and more.
187
+
188
+ Basic Usage:
47
189
  from includecpp import CSSL
190
+
191
+ # Get default instance
48
192
  cssl = CSSL.CsslLang()
49
- result = cssl.exec("script.cssl", arg1, arg2)
50
- cssl.T_exec("async_script.cssl", arg1) # Threaded
193
+
194
+ # Or use module-level functions directly
195
+ CSSL.run("printl('Hello');")
196
+
197
+ Execution Methods:
198
+ - run(): Execute CSSL code or file (recommended)
199
+ - exec(): Alias for run() (deprecated)
200
+ - T_run(): Execute asynchronously in a thread
201
+
202
+ Object Sharing:
203
+ - share(): Share Python object with CSSL (live reference)
204
+ - unshare(): Remove shared object
205
+ - shared(): Get a shared object by name
206
+
207
+ Module Creation:
208
+ - module(): Create callable code block
209
+ - makemodule(): Create module with callable functions
210
+ - script(): Create typed script (cssl or cssl-pl)
211
+ - code(): Register inline payload
212
+
213
+ Globals:
214
+ - set_global(): Set CSSL global variable
215
+ - get_global(): Get CSSL global variable
51
216
  """
52
217
 
53
218
  def __init__(self, output_callback: Optional[Callable[[str, str], None]] = ...) -> None:
@@ -55,97 +220,225 @@ class CsslLang:
55
220
  Initialize CSSL runtime.
56
221
 
57
222
  Args:
58
- output_callback: Optional callback for output (text, level)
223
+ output_callback: Optional callback for capturing output.
224
+ Called with (text, level) where level is
225
+ 'normal', 'debug', 'warning', or 'error'.
226
+
227
+ Usage:
228
+ def my_output(text, level):
229
+ if level == 'error':
230
+ log_error(text)
231
+ else:
232
+ print(text)
233
+
234
+ cssl = CSSL.CsslLang(output_callback=my_output)
59
235
  """
60
236
  ...
61
237
 
62
- def exec(self, path_or_code: str, *args: Any) -> Any:
238
+ def run(self, path_or_code: str, *args: Any) -> Any:
63
239
  """
64
- Execute CSSL code or file.
240
+ Execute CSSL code or file. This is the primary execution method.
65
241
 
66
242
  Args:
67
- path_or_code: Path to .cssl file or CSSL code string
68
- *args: Arguments to pass to the script
243
+ path_or_code: Either a path to a .cssl file or CSSL code string.
244
+ File paths must end in .cssl, .cssl-pl, or .cssl-mod
245
+ *args: Arguments passed to the script, accessible via parameter.get(index)
69
246
 
70
247
  Returns:
71
- Execution result
248
+ Execution result. If parameter.return() was called in CSSL,
249
+ returns those values. Single value if one, list if multiple.
250
+
251
+ Usage:
252
+ # Execute a file
253
+ result = cssl.run("script.cssl", "arg1", 42)
254
+
255
+ # Execute inline code
256
+ cssl.run('printl("Hello World!");')
257
+
258
+ # Get return value
259
+ result = cssl.run('''
260
+ int x = parameter.get(0);
261
+ parameter.return(x * 2);
262
+ ''', 21)
263
+ print(result) # 42
72
264
  """
73
265
  ...
74
266
 
75
- def T_exec(
267
+ def T_run(
76
268
  self,
77
269
  path_or_code: str,
78
270
  *args: Any,
79
271
  callback: Optional[Callable[[Any], None]] = ...
80
272
  ) -> threading.Thread:
81
273
  """
82
- Execute CSSL code asynchronously in a thread.
274
+ Execute CSSL code asynchronously in a background thread.
83
275
 
84
276
  Args:
85
277
  path_or_code: Path to .cssl file or CSSL code string
86
278
  *args: Arguments to pass to the script
87
- callback: Optional callback when execution completes
279
+ callback: Optional callback invoked with result when execution completes
88
280
 
89
281
  Returns:
90
- Thread object
282
+ Thread object that can be joined or monitored
283
+
284
+ Usage:
285
+ def on_complete(result):
286
+ print(f"Script finished with: {result}")
287
+
288
+ thread = cssl.T_run("long_running.cssl", callback=on_complete)
289
+ # ... do other work ...
290
+ thread.join() # Wait for completion if needed
91
291
  """
92
292
  ...
93
293
 
94
- def wait_all(self, timeout: Optional[float] = ...) -> None:
95
- """Wait for all async executions to complete."""
96
- ...
294
+ def exec(self, path_or_code: str, *args: Any) -> Any:
295
+ """
296
+ Execute CSSL code or file (DEPRECATED - use run() instead).
97
297
 
98
- def get_output(self) -> List[str]:
99
- """Get output buffer from last execution."""
298
+ This method is kept for backwards compatibility.
299
+ See run() for documentation.
300
+ """
100
301
  ...
101
302
 
102
- def clear_output(self) -> None:
103
- """Clear output buffer."""
303
+ def T_exec(
304
+ self,
305
+ path_or_code: str,
306
+ *args: Any,
307
+ callback: Optional[Callable[[Any], None]] = ...
308
+ ) -> threading.Thread:
309
+ """
310
+ Execute CSSL asynchronously (DEPRECATED - use T_run() instead).
311
+
312
+ This method is kept for backwards compatibility.
313
+ See T_run() for documentation.
314
+ """
104
315
  ...
105
316
 
106
- def set_global(self, name: str, value: Any) -> None:
107
- """Set a global variable in CSSL runtime."""
317
+ def script(self, script_type: str, code: str, *params: Any) -> CSSLScript:
318
+ """
319
+ Create a typed CSSL script object.
320
+
321
+ Scripts can be executed multiple times or combined into modules.
322
+ This is useful for organizing complex CSSL projects.
323
+
324
+ Args:
325
+ script_type: "cssl" for main script, "cssl-pl" for payload
326
+ code: The CSSL source code
327
+ *params: Optional default parameters
328
+
329
+ Returns:
330
+ CSSLScript object
331
+
332
+ Usage:
333
+ # Create main script and payload
334
+ main = cssl.script("cssl", '''
335
+ printl("Main running");
336
+ @helper.greet("World");
337
+ ''')
338
+
339
+ payload = cssl.script("cssl-pl", '''
340
+ void greet(string name) {
341
+ printl("Hello, " + name + "!");
342
+ }
343
+ ''')
344
+
345
+ # Bundle into a .cssl-mod file
346
+ cssl.makemodule(main, payload, "mymodule")
347
+ """
108
348
  ...
109
349
 
110
- def get_global(self, name: str) -> Any:
111
- """Get a global variable from CSSL runtime."""
350
+ def code(self, name: str, code: str) -> None:
351
+ """
352
+ Register inline CSSL code as a named payload.
353
+
354
+ Registered payloads can be loaded in CSSL using payload("name").
355
+ This allows creating helper libraries from Python without external files.
356
+
357
+ Args:
358
+ name: Unique name for the payload
359
+ code: CSSL code string
360
+
361
+ Usage:
362
+ # Register helper functions
363
+ cssl.code("utils", '''
364
+ global version = "1.0.0";
365
+
366
+ void log(string msg) {
367
+ printl("[LOG] " + msg);
368
+ }
369
+
370
+ int double(int x) {
371
+ return x * 2;
372
+ }
373
+ ''')
374
+
375
+ # Use in CSSL code
376
+ cssl.run('''
377
+ payload("utils");
378
+ @log("Starting...");
379
+ printl(@double(21)); // 42
380
+ ''')
381
+ """
112
382
  ...
113
383
 
114
384
  def module(self, code: str) -> CSSLModule:
115
385
  """
116
386
  Create a callable CSSL module from code.
117
387
 
118
- Usage:
119
- module = cssl.module('''
120
- printl(parameter.get(0));
121
- ''')
122
- module("Hello") # Prints "Hello"
388
+ The module executes the code each time it's called.
389
+ Arguments are accessible via parameter.get(index).
123
390
 
124
391
  Args:
125
392
  code: CSSL code string
126
393
 
127
394
  Returns:
128
- CSSLModule - a callable module
395
+ CSSLModule - callable that executes the code
396
+
397
+ Usage:
398
+ # Simple greeting
399
+ greet = cssl.module('''
400
+ string name = parameter.get(0);
401
+ printl("Hello, " + name + "!");
402
+ ''')
403
+ greet("World") # Prints: Hello, World!
404
+
405
+ # With return value
406
+ calc = cssl.module('''
407
+ int a = parameter.get(0);
408
+ int b = parameter.get(1);
409
+ parameter.return(a * b);
410
+ ''')
411
+ result = calc(6, 7) # Returns 42
129
412
  """
130
413
  ...
131
414
 
132
- def makemodule(self, code: str) -> CSSLFunctionModule:
415
+ def makemodule(self, code_or_script: Union[str, CSSLScript], *more: Any) -> CSSLFunctionModule:
133
416
  """
134
- Create a CSSL module with accessible functions.
417
+ Create a CSSL module with accessible functions as methods.
135
418
 
136
- Usage:
137
- module = cssl.makemodule('''
138
- string greet(string name) {
139
- return "Hello, " + name + "!";
140
- }
141
- ''')
142
- module.greet("World") # Returns "Hello, World!"
419
+ This is the recommended way to create reusable CSSL libraries.
420
+ Functions defined in the code become callable Python methods.
143
421
 
144
422
  Args:
145
- code: CSSL code string with function definitions
423
+ code_or_script: CSSL code string or CSSLScript object
424
+ *more: Additional scripts or module name
146
425
 
147
426
  Returns:
148
- CSSLFunctionModule - module with callable function attributes
427
+ CSSLFunctionModule with callable function attributes
428
+
429
+ Usage:
430
+ # From code string
431
+ math = cssl.makemodule('''
432
+ int add(int a, int b) { return a + b; }
433
+ int sub(int a, int b) { return a - b; }
434
+ ''')
435
+ print(math.add(10, 5)) # 15
436
+ print(math.sub(10, 5)) # 5
437
+
438
+ # From script objects (for .cssl-mod creation)
439
+ main = cssl.script("cssl", "...")
440
+ helpers = cssl.script("cssl-pl", "...")
441
+ mod = cssl.makemodule(main, helpers, "mymodule")
149
442
  """
150
443
  ...
151
444
 
@@ -153,143 +446,206 @@ class CsslLang:
153
446
  """
154
447
  Share a Python object with CSSL (LIVE sharing).
155
448
 
156
- Changes in CSSL reflect back to Python immediately.
449
+ Changes made in CSSL immediately reflect in the Python object.
450
+ This enables true bidirectional communication between Python and CSSL.
157
451
 
158
- Args can be passed in either order:
452
+ Args can be passed in either order (for convenience):
159
453
  cssl.share(my_object, "name") # Preferred
160
454
  cssl.share("name", my_object) # Also works
161
455
 
162
- Usage:
163
- class Counter:
164
- def __init__(self):
165
- self.value = 0
166
-
167
- counter = Counter()
168
- cssl.share(counter, "cnt")
169
- cssl.exec('''
170
- $cnt.value = $cnt.value + 1;
171
- ''')
172
- print(counter.value) # 1
173
-
174
456
  Args:
175
- instance: Python object to share
457
+ instance: Python object to share (can be any object)
176
458
  name: Name to reference in CSSL as $name
177
459
 
178
460
  Returns:
179
461
  Path to the shared object marker file
462
+
463
+ Usage:
464
+ # Share a simple object
465
+ counter = {"value": 0}
466
+ cssl.share(counter, "cnt")
467
+ cssl.run('$cnt.value = $cnt.value + 1;')
468
+ print(counter["value"]) # 1
469
+
470
+ # Share a class instance
471
+ class Player:
472
+ def __init__(self):
473
+ self.health = 100
474
+ self.name = "Hero"
475
+
476
+ def take_damage(self, amount):
477
+ self.health -= amount
478
+
479
+ player = Player()
480
+ cssl.share(player, "player")
481
+ cssl.run('''
482
+ $player.take_damage(25);
483
+ printl($player.name + " has " + $player.health + " HP");
484
+ ''')
485
+ # Prints: Hero has 75 HP
180
486
  """
181
487
  ...
182
488
 
183
489
  def unshare(self, name: str) -> bool:
184
490
  """
185
- Remove a shared object.
491
+ Remove a shared object by name.
186
492
 
187
493
  Args:
188
494
  name: Name of the shared object to remove
189
495
 
190
496
  Returns:
191
- True if removed, False if not found
497
+ True if object was found and removed, False otherwise
498
+
499
+ Usage:
500
+ cssl.share(my_obj, "temp")
501
+ cssl.run("...") # Use $temp
502
+ cssl.unshare("temp") # Clean up
192
503
  """
193
504
  ...
194
505
 
195
- def code(self, name: str, code: str) -> None:
506
+ def get_shared(self, name: str) -> Optional[Any]:
196
507
  """
197
- Register inline CSSL code as a named payload.
508
+ Get a shared object by name (Python-side access).
198
509
 
199
- Usage:
200
- cssl.code("helpers", '''
201
- void log(string msg) {
202
- printl("[LOG] " + msg);
203
- }
204
- ''')
205
- cssl.exec('''
206
- payload("helpers");
207
- @log("Hello");
208
- ''')
510
+ Returns the actual live object reference, not a copy.
209
511
 
210
512
  Args:
211
- name: Name for the payload
212
- code: CSSL code string
513
+ name: Name of the shared object (without $ prefix)
514
+
515
+ Returns:
516
+ The live shared object, or None if not found
213
517
  """
214
518
  ...
215
519
 
216
- def get_shared(self, name: str) -> Optional[Any]:
520
+ def shared(self, name: str) -> Optional[Any]:
217
521
  """
218
- Get a shared object by name (for Python-side access).
522
+ Get a shared object by name (alias for get_shared).
219
523
 
220
- Returns the actual live object reference, not a copy.
524
+ Works with both Python cssl.share() and CSSL ==> $name exports.
221
525
 
222
526
  Args:
223
- name: Name of the shared object
527
+ name: Name of the shared object (without $ prefix)
224
528
 
225
529
  Returns:
226
- The live shared object or None if not found
530
+ The live shared object, or None if not found
531
+
532
+ Usage:
533
+ # Share from Python
534
+ data = {"x": 1}
535
+ cssl.share(data, "mydata")
536
+
537
+ # Later retrieve it
538
+ same_data = cssl.shared("mydata")
539
+ same_data["x"] = 2
540
+ print(data["x"]) # 2 (same object)
227
541
  """
228
542
  ...
229
543
 
230
- def shared(self, name: str) -> Optional[Any]:
544
+ def set_global(self, name: str, value: Any) -> None:
231
545
  """
232
- Get a shared object by name (alias for get_shared).
546
+ Set a global variable in the CSSL runtime.
233
547
 
234
- Returns the actual live object reference, not a copy.
235
- Works with both Python cssl.share() and CSSL ==> $name shared objects.
548
+ These globals persist across multiple run() calls on the same instance.
549
+
550
+ Args:
551
+ name: Variable name (accessible as @name in CSSL)
552
+ value: Value to set
236
553
 
237
554
  Usage:
238
- from includecpp import CSSL
239
- cssl = CSSL.CsslLang()
555
+ cssl.set_global("config_path", "/etc/myapp.conf")
556
+ cssl.run('printl(@config_path);')
557
+ """
558
+ ...
559
+
560
+ def get_global(self, name: str) -> Any:
561
+ """
562
+ Get a global variable from the CSSL runtime.
563
+
564
+ Args:
565
+ name: Variable name
240
566
 
241
- # Share an object
242
- my_obj = {"value": 42}
243
- cssl.share(my_obj, "data")
567
+ Returns:
568
+ The variable's value, or None if not found
569
+ """
570
+ ...
244
571
 
245
- # Retrieve it later
246
- obj = cssl.shared("data")
247
- print(obj["value"]) # 42
572
+ def wait_all(self, timeout: Optional[float] = ...) -> None:
573
+ """
574
+ Wait for all async executions (T_run) to complete.
248
575
 
249
576
  Args:
250
- name: Name of the shared object (without $ prefix)
577
+ timeout: Maximum seconds to wait (None = wait forever)
578
+
579
+ Usage:
580
+ cssl.T_run("script1.cssl")
581
+ cssl.T_run("script2.cssl")
582
+ cssl.wait_all() # Wait for both to finish
583
+ """
584
+ ...
585
+
586
+ def get_output(self) -> List[str]:
587
+ """
588
+ Get the output buffer from the last execution.
251
589
 
252
590
  Returns:
253
- The live shared object or None if not found
591
+ List of output lines
254
592
  """
255
593
  ...
256
594
 
595
+ def clear_output(self) -> None:
596
+ """Clear the output buffer."""
597
+ ...
598
+
599
+
600
+ # =============================================================================
601
+ # Module-Level Functions (Convenience API)
602
+ # =============================================================================
603
+ # These functions operate on a default global CSSL instance.
604
+ # For most use cases, you can use these directly instead of creating a CsslLang.
257
605
 
258
606
  def get_cssl() -> CsslLang:
259
- """Get default CSSL instance."""
607
+ """Get the default global CSSL instance."""
260
608
  ...
261
609
 
262
610
 
263
- def exec(path_or_code: str, *args: Any) -> Any:
611
+ def run(path_or_code: str, *args: Any) -> Any:
264
612
  """
265
- Execute CSSL code or file.
613
+ Execute CSSL code or file using the default instance.
266
614
 
267
- Usage:
268
- from includecpp import CSSL
269
- CSSL.exec("script.cssl", arg1, arg2)
270
- CSSL.exec("printl('Hello World');")
615
+ This is the primary way to run CSSL code. Supports both file paths
616
+ and inline code strings.
271
617
 
272
618
  Args:
273
619
  path_or_code: Path to .cssl file or CSSL code string
274
- *args: Arguments to pass to the script
620
+ *args: Arguments accessible via parameter.get(index)
275
621
 
276
622
  Returns:
277
623
  Execution result
624
+
625
+ Usage:
626
+ from includecpp import CSSL
627
+
628
+ # Run inline code
629
+ CSSL.run('printl("Hello World!");')
630
+
631
+ # Run a file with arguments
632
+ CSSL.run("process.cssl", input_data, output_path)
633
+
634
+ # Get return value
635
+ result = CSSL.run('''
636
+ parameter.return(42);
637
+ ''')
278
638
  """
279
639
  ...
280
640
 
281
641
 
282
- def T_exec(
642
+ def T_run(
283
643
  path_or_code: str,
284
644
  *args: Any,
285
645
  callback: Optional[Callable[[Any], None]] = ...
286
646
  ) -> threading.Thread:
287
647
  """
288
- Execute CSSL code asynchronously in a thread.
289
-
290
- Usage:
291
- from includecpp import CSSL
292
- CSSL.T_exec("async_script.cssl", arg1, callback=on_done)
648
+ Execute CSSL code asynchronously in a background thread.
293
649
 
294
650
  Args:
295
651
  path_or_code: Path to .cssl file or CSSL code string
@@ -298,117 +654,103 @@ def T_exec(
298
654
 
299
655
  Returns:
300
656
  Thread object
301
- """
302
- ...
303
657
 
658
+ Usage:
659
+ from includecpp import CSSL
304
660
 
305
- def set_global(name: str, value: Any) -> None:
306
- """Set a global variable in CSSL runtime."""
661
+ def on_done(result):
662
+ print(f"Finished: {result}")
663
+
664
+ CSSL.T_run("background_task.cssl", callback=on_done)
665
+ """
307
666
  ...
308
667
 
309
668
 
310
- def get_global(name: str) -> Any:
311
- """Get a global variable from CSSL runtime."""
312
- ...
669
+ def script(script_type: str, code: str, *params: Any) -> CSSLScript:
670
+ """
671
+ Create a typed CSSL script.
313
672
 
673
+ Args:
674
+ script_type: "cssl" for main script, "cssl-pl" for payload
675
+ code: The CSSL code
676
+ *params: Optional parameters
314
677
 
315
- def get_output() -> List[str]:
316
- """Get output buffer from last execution."""
317
- ...
678
+ Returns:
679
+ CSSLScript object
318
680
 
681
+ Usage:
682
+ from includecpp import CSSL
319
683
 
320
- def clear_output() -> None:
321
- """Clear output buffer."""
684
+ main = CSSL.script("cssl", '''printl("Main");''')
685
+ payload = CSSL.script("cssl-pl", '''void helper() {}''')
686
+ """
322
687
  ...
323
688
 
324
689
 
325
- # Aliases to avoid conflict with Python builtin exec
326
- def _exec(code: str, *args: Any) -> Any:
690
+ def code(name: str, code: str) -> None:
327
691
  """
328
- Execute CSSL code directly (alias for exec).
692
+ Register inline CSSL code as a named payload.
693
+
694
+ Payloads can be loaded in CSSL using payload("name").
329
695
 
330
- Supports triple-quoted docstrings for inline CSSL code:
696
+ Args:
697
+ name: Unique name for the payload
698
+ code: CSSL code string
331
699
 
332
700
  Usage:
333
701
  from includecpp import CSSL
334
- CSSL._exec('''
335
- global base = include("abc.cssl-mod");
336
-
337
- void TestFunc() {
338
- printl("hey");
339
- @base.RechneWas(4, 5);
340
- }
341
702
 
342
- TestFunc();
703
+ CSSL.code("utils", '''
704
+ void log(string msg) { printl("[LOG] " + msg); }
343
705
  ''')
344
706
 
345
- Args:
346
- code: CSSL code string (supports triple-quoted docstrings)
347
- *args: Arguments to pass to the script
348
-
349
- Returns:
350
- Execution result
707
+ CSSL.run('''
708
+ payload("utils");
709
+ @log("Hello!");
710
+ ''')
351
711
  """
352
712
  ...
353
713
 
354
714
 
355
- def _T_exec(
356
- code: str,
357
- *args: Any,
358
- callback: Optional[Callable[[Any], None]] = ...
359
- ) -> threading.Thread:
715
+ def module(code: str) -> CSSLModule:
360
716
  """
361
- Execute CSSL code asynchronously in a thread (alias for T_exec).
717
+ Create a callable CSSL module from code.
362
718
 
363
719
  Args:
364
720
  code: CSSL code string
365
- *args: Arguments to pass to the script
366
- callback: Optional callback when execution completes
367
721
 
368
722
  Returns:
369
- Thread object
370
- """
371
- ...
372
-
373
-
374
- def module(code: str) -> CSSLModule:
375
- """
376
- Create a callable CSSL module from code.
723
+ CSSLModule - callable that executes the code
377
724
 
378
725
  Usage:
379
726
  from includecpp import CSSL
727
+
380
728
  greet = CSSL.module('''
381
729
  printl("Hello, " + parameter.get(0) + "!");
382
730
  ''')
383
- greet("World") # Prints "Hello, World!"
384
-
385
- Args:
386
- code: CSSL code string
387
-
388
- Returns:
389
- CSSLModule - a callable module
731
+ greet("World") # Prints: Hello, World!
390
732
  """
391
733
  ...
392
734
 
393
735
 
394
- def makemodule(code: str) -> CSSLFunctionModule:
736
+ def makemodule(code_or_script: Union[str, CSSLScript], *more: Any) -> CSSLFunctionModule:
395
737
  """
396
738
  Create a CSSL module with accessible functions.
397
739
 
398
- Usage:
399
- from includecpp import CSSL
400
- math_mod = CSSL.makemodule('''
401
- int add(int a, int b) {
402
- return a + b;
403
- }
404
- ''')
405
- math_mod.add(2, 3) # Returns 5
406
-
407
740
  Args:
408
- code: CSSL code string with function definitions
741
+ code_or_script: CSSL code string or CSSLScript object
742
+ *more: Additional scripts or module name
409
743
 
410
744
  Returns:
411
- CSSLFunctionModule - module with callable function attributes
745
+ CSSLFunctionModule with callable function attributes
746
+
747
+ Usage:
748
+ from includecpp import CSSL
749
+
750
+ math = CSSL.makemodule('''
751
+ int add(int a, int b) { return a + b; }
752
+ ''')
753
+ result = math.add(2, 3) # 5
412
754
  """
413
755
  ...
414
756
 
@@ -417,11 +759,7 @@ def share(instance: Any, name: str = ...) -> str:
417
759
  """
418
760
  Share a Python object globally for all CSSL instances (LIVE sharing).
419
761
 
420
- Changes made through CSSL will reflect back to the original object.
421
-
422
- Args can be passed in either order:
423
- share(my_object, "name") # Preferred
424
- share("name", my_object) # Also works
762
+ Changes made in CSSL immediately reflect in the Python object.
425
763
 
426
764
  Args:
427
765
  instance: Python object to share
@@ -429,6 +767,14 @@ def share(instance: Any, name: str = ...) -> str:
429
767
 
430
768
  Returns:
431
769
  Path to the shared object marker file
770
+
771
+ Usage:
772
+ from includecpp import CSSL
773
+
774
+ data = {"count": 0}
775
+ CSSL.share(data, "data")
776
+ CSSL.run('$data.count = 10;')
777
+ print(data["count"]) # 10
432
778
  """
433
779
  ...
434
780
 
@@ -463,19 +809,6 @@ def shared(name: str) -> Optional[Any]:
463
809
  """
464
810
  Get a shared object by name (alias for get_shared).
465
811
 
466
- Works with both Python share() and CSSL ==> $name shared objects.
467
-
468
- Usage:
469
- from includecpp import CSSL
470
-
471
- # Share an object
472
- my_obj = {"value": 42}
473
- CSSL.share(my_obj, "data")
474
-
475
- # Retrieve it later
476
- obj = CSSL.shared("data")
477
- print(obj["value"]) # 42
478
-
479
812
  Args:
480
813
  name: Name of the shared object (without $ prefix)
481
814
 
@@ -485,4 +818,64 @@ def shared(name: str) -> Optional[Any]:
485
818
  ...
486
819
 
487
820
 
821
+ def set_global(name: str, value: Any) -> None:
822
+ """Set a global variable in CSSL runtime."""
823
+ ...
824
+
825
+
826
+ def get_global(name: str) -> Any:
827
+ """Get a global variable from CSSL runtime."""
828
+ ...
829
+
830
+
831
+ def get_output() -> List[str]:
832
+ """Get output buffer from last execution."""
833
+ ...
834
+
835
+
836
+ def clear_output() -> None:
837
+ """Clear output buffer."""
838
+ ...
839
+
840
+
841
+ # =============================================================================
842
+ # Deprecated Aliases (for backwards compatibility)
843
+ # =============================================================================
844
+
845
+ def exec(path_or_code: str, *args: Any) -> Any:
846
+ """DEPRECATED: Use run() instead."""
847
+ ...
848
+
849
+
850
+ def T_exec(
851
+ path_or_code: str,
852
+ *args: Any,
853
+ callback: Optional[Callable[[Any], None]] = ...
854
+ ) -> threading.Thread:
855
+ """DEPRECATED: Use T_run() instead."""
856
+ ...
857
+
858
+
859
+ def _exec(code: str, *args: Any) -> Any:
860
+ """
861
+ Execute CSSL code directly (alias to avoid conflict with Python builtin exec).
862
+
863
+ Usage:
864
+ from includecpp import CSSL
865
+ CSSL._exec('''
866
+ printl("Hello from CSSL!");
867
+ ''')
868
+ """
869
+ ...
870
+
871
+
872
+ def _T_exec(
873
+ code: str,
874
+ *args: Any,
875
+ callback: Optional[Callable[[Any], None]] = ...
876
+ ) -> threading.Thread:
877
+ """Execute CSSL code asynchronously (alias for T_exec)."""
878
+ ...
879
+
880
+
488
881
  __all__: List[str]