IncludeCPP 4.0.0__py3-none-any.whl → 4.2.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.
- includecpp/CHANGELOG.md +175 -0
- includecpp/DOCUMENTATION.md +593 -0
- includecpp/__init__.py +1 -1
- includecpp/__init__.pyi +4 -1
- includecpp/cli/commands.py +705 -98
- includecpp/core/ai_integration.py +46 -13
- includecpp/core/cpp_api_extensions.pyi +350 -0
- includecpp/core/cssl/CSSL_DOCUMENTATION.md +186 -5
- includecpp/core/cssl/cssl_builtins.py +101 -4
- includecpp/core/cssl/cssl_languages.py +1757 -0
- includecpp/core/cssl/cssl_parser.py +437 -104
- includecpp/core/cssl/cssl_runtime.py +865 -62
- includecpp/core/cssl/cssl_syntax.py +88 -4
- includecpp/core/cssl/cssl_types.py +172 -1
- includecpp/core/cssl_bridge.py +198 -12
- includecpp/core/cssl_bridge.pyi +717 -186
- includecpp/generator/parser.cpp +121 -4
- includecpp/generator/parser.h +6 -0
- includecpp/vscode/cssl/package.json +43 -1
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +140 -17
- {includecpp-4.0.0.dist-info → includecpp-4.2.2.dist-info}/METADATA +102 -1
- {includecpp-4.0.0.dist-info → includecpp-4.2.2.dist-info}/RECORD +26 -22
- {includecpp-4.0.0.dist-info → includecpp-4.2.2.dist-info}/WHEEL +0 -0
- {includecpp-4.0.0.dist-info → includecpp-4.2.2.dist-info}/entry_points.txt +0 -0
- {includecpp-4.0.0.dist-info → includecpp-4.2.2.dist-info}/licenses/LICENSE +0 -0
- {includecpp-4.0.0.dist-info → includecpp-4.2.2.dist-info}/top_level.txt +0 -0
includecpp/core/cssl_bridge.pyi
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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,264 @@ class CsslLang:
|
|
|
55
220
|
Initialize CSSL runtime.
|
|
56
221
|
|
|
57
222
|
Args:
|
|
58
|
-
output_callback: Optional callback for output
|
|
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
|
|
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:
|
|
68
|
-
|
|
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
|
|
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
|
|
95
|
-
"""
|
|
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
|
-
|
|
99
|
-
|
|
298
|
+
This method is kept for backwards compatibility.
|
|
299
|
+
See run() for documentation.
|
|
300
|
+
"""
|
|
100
301
|
...
|
|
101
302
|
|
|
102
|
-
def
|
|
103
|
-
|
|
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
|
|
107
|
-
"""
|
|
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
|
|
111
|
-
"""
|
|
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
|
-
|
|
119
|
-
|
|
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 -
|
|
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
|
|
415
|
+
def makepayload(self, name: str, path: str) -> str:
|
|
133
416
|
"""
|
|
134
|
-
|
|
417
|
+
Register a payload from a file path.
|
|
418
|
+
|
|
419
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
420
|
+
This is a convenience method for loading payload files.
|
|
421
|
+
|
|
422
|
+
Args:
|
|
423
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
424
|
+
path: Path to the .cssl-pl or .cssl file
|
|
425
|
+
|
|
426
|
+
Returns:
|
|
427
|
+
The payload code that was registered
|
|
135
428
|
|
|
136
429
|
Usage:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
430
|
+
# Register a payload from file
|
|
431
|
+
cssl.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
432
|
+
|
|
433
|
+
# Use with makemodule for automatic binding
|
|
434
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
435
|
+
mod.SaySomething("Hello!")
|
|
436
|
+
"""
|
|
437
|
+
...
|
|
438
|
+
|
|
439
|
+
def makemodule(
|
|
440
|
+
self,
|
|
441
|
+
main_script: Union[str, CSSLScript],
|
|
442
|
+
payload_script: Union[str, CSSLScript, None] = ...,
|
|
443
|
+
name: str = ...,
|
|
444
|
+
bind: str = ...
|
|
445
|
+
) -> CSSLFunctionModule:
|
|
446
|
+
"""
|
|
447
|
+
Create a CSSL module with accessible functions as methods.
|
|
448
|
+
|
|
449
|
+
This is the recommended way to create reusable CSSL libraries.
|
|
450
|
+
Functions defined in the code become callable Python methods.
|
|
143
451
|
|
|
144
452
|
Args:
|
|
145
|
-
|
|
453
|
+
main_script: CSSL code string, file path, or CSSLScript object
|
|
454
|
+
payload_script: Optional payload code (string or CSSLScript)
|
|
455
|
+
name: Optional name to register for payload(name) access
|
|
456
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
146
457
|
|
|
147
458
|
Returns:
|
|
148
|
-
CSSLFunctionModule
|
|
459
|
+
CSSLFunctionModule with callable function attributes
|
|
460
|
+
|
|
461
|
+
Usage (simplified - with file path and bind):
|
|
462
|
+
# First register the payload
|
|
463
|
+
cssl.makepayload("api", "lib/api/einkaufsmanager.cssl-pl")
|
|
464
|
+
|
|
465
|
+
# Then create module from file, binding to payload
|
|
466
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
467
|
+
mod.SaySomething("Hello!") # Functions are now accessible
|
|
468
|
+
|
|
469
|
+
Usage (from code string):
|
|
470
|
+
math = cssl.makemodule('''
|
|
471
|
+
int add(int a, int b) { return a + b; }
|
|
472
|
+
int sub(int a, int b) { return a - b; }
|
|
473
|
+
''')
|
|
474
|
+
print(math.add(10, 5)) # 15
|
|
475
|
+
print(math.sub(10, 5)) # 5
|
|
476
|
+
|
|
477
|
+
Usage (from script objects):
|
|
478
|
+
main = cssl.script("cssl", "...")
|
|
479
|
+
helpers = cssl.script("cssl-pl", "...")
|
|
480
|
+
mod = cssl.makemodule(main, helpers, "mymodule")
|
|
149
481
|
"""
|
|
150
482
|
...
|
|
151
483
|
|
|
@@ -153,143 +485,266 @@ class CsslLang:
|
|
|
153
485
|
"""
|
|
154
486
|
Share a Python object with CSSL (LIVE sharing).
|
|
155
487
|
|
|
156
|
-
Changes in CSSL reflect
|
|
488
|
+
Changes made in CSSL immediately reflect in the Python object.
|
|
489
|
+
This enables true bidirectional communication between Python and CSSL.
|
|
157
490
|
|
|
158
|
-
Args can be passed in either order:
|
|
491
|
+
Args can be passed in either order (for convenience):
|
|
159
492
|
cssl.share(my_object, "name") # Preferred
|
|
160
493
|
cssl.share("name", my_object) # Also works
|
|
161
494
|
|
|
495
|
+
Args:
|
|
496
|
+
instance: Python object to share (can be any object)
|
|
497
|
+
name: Name to reference in CSSL as $name
|
|
498
|
+
|
|
499
|
+
Returns:
|
|
500
|
+
Path to the shared object marker file
|
|
501
|
+
|
|
162
502
|
Usage:
|
|
163
|
-
|
|
503
|
+
# Share a simple object
|
|
504
|
+
counter = {"value": 0}
|
|
505
|
+
cssl.share(counter, "cnt")
|
|
506
|
+
cssl.run('$cnt.value = $cnt.value + 1;')
|
|
507
|
+
print(counter["value"]) # 1
|
|
508
|
+
|
|
509
|
+
# Share a class instance
|
|
510
|
+
class Player:
|
|
164
511
|
def __init__(self):
|
|
165
|
-
self.
|
|
512
|
+
self.health = 100
|
|
513
|
+
self.name = "Hero"
|
|
166
514
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
515
|
+
def take_damage(self, amount):
|
|
516
|
+
self.health -= amount
|
|
517
|
+
|
|
518
|
+
player = Player()
|
|
519
|
+
cssl.share(player, "player")
|
|
520
|
+
cssl.run('''
|
|
521
|
+
$player.take_damage(25);
|
|
522
|
+
printl($player.name + " has " + $player.health + " HP");
|
|
171
523
|
''')
|
|
172
|
-
|
|
524
|
+
# Prints: Hero has 75 HP
|
|
525
|
+
"""
|
|
526
|
+
...
|
|
527
|
+
|
|
528
|
+
def unshare(self, name: str) -> bool:
|
|
529
|
+
"""
|
|
530
|
+
Remove a shared object by name.
|
|
173
531
|
|
|
174
532
|
Args:
|
|
175
|
-
|
|
176
|
-
name: Name to reference in CSSL as $name
|
|
533
|
+
name: Name of the shared object to remove
|
|
177
534
|
|
|
178
535
|
Returns:
|
|
179
|
-
|
|
536
|
+
True if object was found and removed, False otherwise
|
|
537
|
+
|
|
538
|
+
Usage:
|
|
539
|
+
cssl.share(my_obj, "temp")
|
|
540
|
+
cssl.run("...") # Use $temp
|
|
541
|
+
cssl.unshare("temp") # Clean up
|
|
180
542
|
"""
|
|
181
543
|
...
|
|
182
544
|
|
|
183
|
-
def
|
|
545
|
+
def get_shared(self, name: str) -> Optional[Any]:
|
|
184
546
|
"""
|
|
185
|
-
|
|
547
|
+
Get a shared object by name (Python-side access).
|
|
548
|
+
|
|
549
|
+
Returns the actual live object reference, not a copy.
|
|
186
550
|
|
|
187
551
|
Args:
|
|
188
|
-
name: Name of the shared object
|
|
552
|
+
name: Name of the shared object (without $ prefix)
|
|
189
553
|
|
|
190
554
|
Returns:
|
|
191
|
-
|
|
555
|
+
The live shared object, or None if not found
|
|
192
556
|
"""
|
|
193
557
|
...
|
|
194
558
|
|
|
195
|
-
def
|
|
559
|
+
def shared(self, name: str) -> Optional[Any]:
|
|
196
560
|
"""
|
|
197
|
-
|
|
561
|
+
Get a shared object by name (alias for get_shared).
|
|
562
|
+
|
|
563
|
+
Works with both Python cssl.share() and CSSL ==> $name exports.
|
|
564
|
+
|
|
565
|
+
Args:
|
|
566
|
+
name: Name of the shared object (without $ prefix)
|
|
567
|
+
|
|
568
|
+
Returns:
|
|
569
|
+
The live shared object, or None if not found
|
|
198
570
|
|
|
199
571
|
Usage:
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
cssl.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
572
|
+
# Share from Python
|
|
573
|
+
data = {"x": 1}
|
|
574
|
+
cssl.share(data, "mydata")
|
|
575
|
+
|
|
576
|
+
# Later retrieve it
|
|
577
|
+
same_data = cssl.shared("mydata")
|
|
578
|
+
same_data["x"] = 2
|
|
579
|
+
print(data["x"]) # 2 (same object)
|
|
580
|
+
"""
|
|
581
|
+
...
|
|
582
|
+
|
|
583
|
+
def getInstance(self, name: str) -> Optional[Any]:
|
|
584
|
+
"""
|
|
585
|
+
Get a universal instance by name (for Python-side access).
|
|
586
|
+
|
|
587
|
+
Universal instances are shared containers accessible from CSSL, Python, and C++.
|
|
588
|
+
They support dynamic member/method access and are mutable across all contexts.
|
|
209
589
|
|
|
210
590
|
Args:
|
|
211
|
-
name: Name
|
|
212
|
-
|
|
591
|
+
name: Name of the instance (without quotes)
|
|
592
|
+
|
|
593
|
+
Returns:
|
|
594
|
+
The UniversalInstance or None if not found
|
|
595
|
+
|
|
596
|
+
Usage:
|
|
597
|
+
# In CSSL: instance<"myContainer"> container;
|
|
598
|
+
# Then in Python:
|
|
599
|
+
container = cssl.getInstance("myContainer")
|
|
600
|
+
container.member = "value"
|
|
601
|
+
print(container.member) # value
|
|
213
602
|
"""
|
|
214
603
|
...
|
|
215
604
|
|
|
216
|
-
def
|
|
605
|
+
def createInstance(self, name: str) -> Any:
|
|
217
606
|
"""
|
|
218
|
-
|
|
607
|
+
Create or get a universal instance by name (for Python-side creation).
|
|
219
608
|
|
|
220
|
-
|
|
609
|
+
Args:
|
|
610
|
+
name: Name for the instance
|
|
611
|
+
|
|
612
|
+
Returns:
|
|
613
|
+
The UniversalInstance (new or existing)
|
|
614
|
+
|
|
615
|
+
Usage:
|
|
616
|
+
container = cssl.createInstance("myContainer")
|
|
617
|
+
container.data = {"key": "value"}
|
|
618
|
+
# Now accessible in CSSL via instance<"myContainer">
|
|
619
|
+
"""
|
|
620
|
+
...
|
|
621
|
+
|
|
622
|
+
def deleteInstance(self, name: str) -> bool:
|
|
623
|
+
"""
|
|
624
|
+
Delete a universal instance by name.
|
|
221
625
|
|
|
222
626
|
Args:
|
|
223
|
-
name: Name of the
|
|
627
|
+
name: Name of the instance to delete
|
|
224
628
|
|
|
225
629
|
Returns:
|
|
226
|
-
|
|
630
|
+
True if deleted, False if not found
|
|
227
631
|
"""
|
|
228
632
|
...
|
|
229
633
|
|
|
230
|
-
def
|
|
634
|
+
def listInstances(self) -> List[str]:
|
|
231
635
|
"""
|
|
232
|
-
|
|
636
|
+
List all universal instance names.
|
|
233
637
|
|
|
234
|
-
Returns
|
|
235
|
-
|
|
638
|
+
Returns:
|
|
639
|
+
List of instance names
|
|
640
|
+
"""
|
|
641
|
+
...
|
|
642
|
+
|
|
643
|
+
def set_global(self, name: str, value: Any) -> None:
|
|
644
|
+
"""
|
|
645
|
+
Set a global variable in the CSSL runtime.
|
|
646
|
+
|
|
647
|
+
These globals persist across multiple run() calls on the same instance.
|
|
648
|
+
|
|
649
|
+
Args:
|
|
650
|
+
name: Variable name (accessible as @name in CSSL)
|
|
651
|
+
value: Value to set
|
|
236
652
|
|
|
237
653
|
Usage:
|
|
238
|
-
|
|
239
|
-
cssl
|
|
654
|
+
cssl.set_global("config_path", "/etc/myapp.conf")
|
|
655
|
+
cssl.run('printl(@config_path);')
|
|
656
|
+
"""
|
|
657
|
+
...
|
|
240
658
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
659
|
+
def get_global(self, name: str) -> Any:
|
|
660
|
+
"""
|
|
661
|
+
Get a global variable from the CSSL runtime.
|
|
662
|
+
|
|
663
|
+
Args:
|
|
664
|
+
name: Variable name
|
|
665
|
+
|
|
666
|
+
Returns:
|
|
667
|
+
The variable's value, or None if not found
|
|
668
|
+
"""
|
|
669
|
+
...
|
|
244
670
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
671
|
+
def wait_all(self, timeout: Optional[float] = ...) -> None:
|
|
672
|
+
"""
|
|
673
|
+
Wait for all async executions (T_run) to complete.
|
|
248
674
|
|
|
249
675
|
Args:
|
|
250
|
-
|
|
676
|
+
timeout: Maximum seconds to wait (None = wait forever)
|
|
677
|
+
|
|
678
|
+
Usage:
|
|
679
|
+
cssl.T_run("script1.cssl")
|
|
680
|
+
cssl.T_run("script2.cssl")
|
|
681
|
+
cssl.wait_all() # Wait for both to finish
|
|
682
|
+
"""
|
|
683
|
+
...
|
|
684
|
+
|
|
685
|
+
def get_output(self) -> List[str]:
|
|
686
|
+
"""
|
|
687
|
+
Get the output buffer from the last execution.
|
|
251
688
|
|
|
252
689
|
Returns:
|
|
253
|
-
|
|
690
|
+
List of output lines
|
|
254
691
|
"""
|
|
255
692
|
...
|
|
256
693
|
|
|
694
|
+
def clear_output(self) -> None:
|
|
695
|
+
"""Clear the output buffer."""
|
|
696
|
+
...
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
# =============================================================================
|
|
700
|
+
# Module-Level Functions (Convenience API)
|
|
701
|
+
# =============================================================================
|
|
702
|
+
# These functions operate on a default global CSSL instance.
|
|
703
|
+
# For most use cases, you can use these directly instead of creating a CsslLang.
|
|
257
704
|
|
|
258
705
|
def get_cssl() -> CsslLang:
|
|
259
|
-
"""Get default CSSL instance."""
|
|
706
|
+
"""Get the default global CSSL instance."""
|
|
260
707
|
...
|
|
261
708
|
|
|
262
709
|
|
|
263
|
-
def
|
|
710
|
+
def run(path_or_code: str, *args: Any) -> Any:
|
|
264
711
|
"""
|
|
265
|
-
Execute CSSL code or file.
|
|
712
|
+
Execute CSSL code or file using the default instance.
|
|
266
713
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
CSSL.exec("script.cssl", arg1, arg2)
|
|
270
|
-
CSSL.exec("printl('Hello World');")
|
|
714
|
+
This is the primary way to run CSSL code. Supports both file paths
|
|
715
|
+
and inline code strings.
|
|
271
716
|
|
|
272
717
|
Args:
|
|
273
718
|
path_or_code: Path to .cssl file or CSSL code string
|
|
274
|
-
*args: Arguments
|
|
719
|
+
*args: Arguments accessible via parameter.get(index)
|
|
275
720
|
|
|
276
721
|
Returns:
|
|
277
722
|
Execution result
|
|
723
|
+
|
|
724
|
+
Usage:
|
|
725
|
+
from includecpp import CSSL
|
|
726
|
+
|
|
727
|
+
# Run inline code
|
|
728
|
+
CSSL.run('printl("Hello World!");')
|
|
729
|
+
|
|
730
|
+
# Run a file with arguments
|
|
731
|
+
CSSL.run("process.cssl", input_data, output_path)
|
|
732
|
+
|
|
733
|
+
# Get return value
|
|
734
|
+
result = CSSL.run('''
|
|
735
|
+
parameter.return(42);
|
|
736
|
+
''')
|
|
278
737
|
"""
|
|
279
738
|
...
|
|
280
739
|
|
|
281
740
|
|
|
282
|
-
def
|
|
741
|
+
def T_run(
|
|
283
742
|
path_or_code: str,
|
|
284
743
|
*args: Any,
|
|
285
744
|
callback: Optional[Callable[[Any], None]] = ...
|
|
286
745
|
) -> threading.Thread:
|
|
287
746
|
"""
|
|
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)
|
|
747
|
+
Execute CSSL code asynchronously in a background thread.
|
|
293
748
|
|
|
294
749
|
Args:
|
|
295
750
|
path_or_code: Path to .cssl file or CSSL code string
|
|
@@ -298,117 +753,142 @@ def T_exec(
|
|
|
298
753
|
|
|
299
754
|
Returns:
|
|
300
755
|
Thread object
|
|
301
|
-
"""
|
|
302
|
-
...
|
|
303
756
|
|
|
757
|
+
Usage:
|
|
758
|
+
from includecpp import CSSL
|
|
304
759
|
|
|
305
|
-
def
|
|
306
|
-
|
|
760
|
+
def on_done(result):
|
|
761
|
+
print(f"Finished: {result}")
|
|
762
|
+
|
|
763
|
+
CSSL.T_run("background_task.cssl", callback=on_done)
|
|
764
|
+
"""
|
|
307
765
|
...
|
|
308
766
|
|
|
309
767
|
|
|
310
|
-
def
|
|
311
|
-
"""
|
|
312
|
-
|
|
768
|
+
def script(script_type: str, code: str, *params: Any) -> CSSLScript:
|
|
769
|
+
"""
|
|
770
|
+
Create a typed CSSL script.
|
|
313
771
|
|
|
772
|
+
Args:
|
|
773
|
+
script_type: "cssl" for main script, "cssl-pl" for payload
|
|
774
|
+
code: The CSSL code
|
|
775
|
+
*params: Optional parameters
|
|
314
776
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
...
|
|
777
|
+
Returns:
|
|
778
|
+
CSSLScript object
|
|
318
779
|
|
|
780
|
+
Usage:
|
|
781
|
+
from includecpp import CSSL
|
|
319
782
|
|
|
320
|
-
|
|
321
|
-
|
|
783
|
+
main = CSSL.script("cssl", '''printl("Main");''')
|
|
784
|
+
payload = CSSL.script("cssl-pl", '''void helper() {}''')
|
|
785
|
+
"""
|
|
322
786
|
...
|
|
323
787
|
|
|
324
788
|
|
|
325
|
-
|
|
326
|
-
def _exec(code: str, *args: Any) -> Any:
|
|
789
|
+
def code(name: str, code: str) -> None:
|
|
327
790
|
"""
|
|
328
|
-
|
|
791
|
+
Register inline CSSL code as a named payload.
|
|
329
792
|
|
|
330
|
-
|
|
793
|
+
Payloads can be loaded in CSSL using payload("name").
|
|
794
|
+
|
|
795
|
+
Args:
|
|
796
|
+
name: Unique name for the payload
|
|
797
|
+
code: CSSL code string
|
|
331
798
|
|
|
332
799
|
Usage:
|
|
333
800
|
from includecpp import CSSL
|
|
334
|
-
CSSL._exec('''
|
|
335
|
-
global base = include("abc.cssl-mod");
|
|
336
801
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
@base.RechneWas(4, 5);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
TestFunc();
|
|
802
|
+
CSSL.code("utils", '''
|
|
803
|
+
void log(string msg) { printl("[LOG] " + msg); }
|
|
343
804
|
''')
|
|
344
805
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
Returns:
|
|
350
|
-
Execution result
|
|
806
|
+
CSSL.run('''
|
|
807
|
+
payload("utils");
|
|
808
|
+
@log("Hello!");
|
|
809
|
+
''')
|
|
351
810
|
"""
|
|
352
811
|
...
|
|
353
812
|
|
|
354
813
|
|
|
355
|
-
def
|
|
356
|
-
code: str,
|
|
357
|
-
*args: Any,
|
|
358
|
-
callback: Optional[Callable[[Any], None]] = ...
|
|
359
|
-
) -> threading.Thread:
|
|
814
|
+
def module(code: str) -> CSSLModule:
|
|
360
815
|
"""
|
|
361
|
-
|
|
816
|
+
Create a callable CSSL module from code.
|
|
362
817
|
|
|
363
818
|
Args:
|
|
364
819
|
code: CSSL code string
|
|
365
|
-
*args: Arguments to pass to the script
|
|
366
|
-
callback: Optional callback when execution completes
|
|
367
820
|
|
|
368
821
|
Returns:
|
|
369
|
-
|
|
370
|
-
"""
|
|
371
|
-
...
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
def module(code: str) -> CSSLModule:
|
|
375
|
-
"""
|
|
376
|
-
Create a callable CSSL module from code.
|
|
822
|
+
CSSLModule - callable that executes the code
|
|
377
823
|
|
|
378
824
|
Usage:
|
|
379
825
|
from includecpp import CSSL
|
|
826
|
+
|
|
380
827
|
greet = CSSL.module('''
|
|
381
828
|
printl("Hello, " + parameter.get(0) + "!");
|
|
382
829
|
''')
|
|
383
|
-
greet("World") # Prints
|
|
830
|
+
greet("World") # Prints: Hello, World!
|
|
831
|
+
"""
|
|
832
|
+
...
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
def makepayload(name: str, path: str) -> str:
|
|
836
|
+
"""
|
|
837
|
+
Register a payload from a file path.
|
|
838
|
+
|
|
839
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
384
840
|
|
|
385
841
|
Args:
|
|
386
|
-
|
|
842
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
843
|
+
path: Path to the .cssl-pl or .cssl file
|
|
387
844
|
|
|
388
845
|
Returns:
|
|
389
|
-
|
|
846
|
+
The payload code that was registered
|
|
847
|
+
|
|
848
|
+
Usage:
|
|
849
|
+
from includecpp import CSSL
|
|
850
|
+
|
|
851
|
+
# Register a payload from file
|
|
852
|
+
CSSL.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
853
|
+
|
|
854
|
+
# Use with makemodule for automatic binding
|
|
855
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
856
|
+
mod.SaySomething("Hello!")
|
|
390
857
|
"""
|
|
391
858
|
...
|
|
392
859
|
|
|
393
860
|
|
|
394
|
-
def makemodule(
|
|
861
|
+
def makemodule(
|
|
862
|
+
main_script: Union[str, CSSLScript],
|
|
863
|
+
payload_script: Union[str, CSSLScript, None] = ...,
|
|
864
|
+
name: str = ...,
|
|
865
|
+
bind: str = ...
|
|
866
|
+
) -> CSSLFunctionModule:
|
|
395
867
|
"""
|
|
396
868
|
Create a CSSL module with accessible functions.
|
|
397
869
|
|
|
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
870
|
Args:
|
|
408
|
-
|
|
871
|
+
main_script: CSSL code string, file path, or CSSLScript object
|
|
872
|
+
payload_script: Optional payload code (string or CSSLScript)
|
|
873
|
+
name: Optional name to register for payload(name) access
|
|
874
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
409
875
|
|
|
410
876
|
Returns:
|
|
411
|
-
CSSLFunctionModule
|
|
877
|
+
CSSLFunctionModule with callable function attributes
|
|
878
|
+
|
|
879
|
+
Usage (simplified):
|
|
880
|
+
from includecpp import CSSL
|
|
881
|
+
|
|
882
|
+
# Register payload and create module
|
|
883
|
+
CSSL.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
884
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
885
|
+
mod.SaySomething("Hello!")
|
|
886
|
+
|
|
887
|
+
Usage (code string):
|
|
888
|
+
math = CSSL.makemodule('''
|
|
889
|
+
int add(int a, int b) { return a + b; }
|
|
890
|
+
''')
|
|
891
|
+
result = math.add(2, 3) # 5
|
|
412
892
|
"""
|
|
413
893
|
...
|
|
414
894
|
|
|
@@ -417,11 +897,7 @@ def share(instance: Any, name: str = ...) -> str:
|
|
|
417
897
|
"""
|
|
418
898
|
Share a Python object globally for all CSSL instances (LIVE sharing).
|
|
419
899
|
|
|
420
|
-
Changes made
|
|
421
|
-
|
|
422
|
-
Args can be passed in either order:
|
|
423
|
-
share(my_object, "name") # Preferred
|
|
424
|
-
share("name", my_object) # Also works
|
|
900
|
+
Changes made in CSSL immediately reflect in the Python object.
|
|
425
901
|
|
|
426
902
|
Args:
|
|
427
903
|
instance: Python object to share
|
|
@@ -429,6 +905,14 @@ def share(instance: Any, name: str = ...) -> str:
|
|
|
429
905
|
|
|
430
906
|
Returns:
|
|
431
907
|
Path to the shared object marker file
|
|
908
|
+
|
|
909
|
+
Usage:
|
|
910
|
+
from includecpp import CSSL
|
|
911
|
+
|
|
912
|
+
data = {"count": 0}
|
|
913
|
+
CSSL.share(data, "data")
|
|
914
|
+
CSSL.run('$data.count = 10;')
|
|
915
|
+
print(data["count"]) # 10
|
|
432
916
|
"""
|
|
433
917
|
...
|
|
434
918
|
|
|
@@ -463,19 +947,6 @@ def shared(name: str) -> Optional[Any]:
|
|
|
463
947
|
"""
|
|
464
948
|
Get a shared object by name (alias for get_shared).
|
|
465
949
|
|
|
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
950
|
Args:
|
|
480
951
|
name: Name of the shared object (without $ prefix)
|
|
481
952
|
|
|
@@ -485,4 +956,64 @@ def shared(name: str) -> Optional[Any]:
|
|
|
485
956
|
...
|
|
486
957
|
|
|
487
958
|
|
|
959
|
+
def set_global(name: str, value: Any) -> None:
|
|
960
|
+
"""Set a global variable in CSSL runtime."""
|
|
961
|
+
...
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
def get_global(name: str) -> Any:
|
|
965
|
+
"""Get a global variable from CSSL runtime."""
|
|
966
|
+
...
|
|
967
|
+
|
|
968
|
+
|
|
969
|
+
def get_output() -> List[str]:
|
|
970
|
+
"""Get output buffer from last execution."""
|
|
971
|
+
...
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
def clear_output() -> None:
|
|
975
|
+
"""Clear output buffer."""
|
|
976
|
+
...
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
# =============================================================================
|
|
980
|
+
# Deprecated Aliases (for backwards compatibility)
|
|
981
|
+
# =============================================================================
|
|
982
|
+
|
|
983
|
+
def exec(path_or_code: str, *args: Any) -> Any:
|
|
984
|
+
"""DEPRECATED: Use run() instead."""
|
|
985
|
+
...
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
def T_exec(
|
|
989
|
+
path_or_code: str,
|
|
990
|
+
*args: Any,
|
|
991
|
+
callback: Optional[Callable[[Any], None]] = ...
|
|
992
|
+
) -> threading.Thread:
|
|
993
|
+
"""DEPRECATED: Use T_run() instead."""
|
|
994
|
+
...
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
def _exec(code: str, *args: Any) -> Any:
|
|
998
|
+
"""
|
|
999
|
+
Execute CSSL code directly (alias to avoid conflict with Python builtin exec).
|
|
1000
|
+
|
|
1001
|
+
Usage:
|
|
1002
|
+
from includecpp import CSSL
|
|
1003
|
+
CSSL._exec('''
|
|
1004
|
+
printl("Hello from CSSL!");
|
|
1005
|
+
''')
|
|
1006
|
+
"""
|
|
1007
|
+
...
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
def _T_exec(
|
|
1011
|
+
code: str,
|
|
1012
|
+
*args: Any,
|
|
1013
|
+
callback: Optional[Callable[[Any], None]] = ...
|
|
1014
|
+
) -> threading.Thread:
|
|
1015
|
+
"""Execute CSSL code asynchronously (alias for T_exec)."""
|
|
1016
|
+
...
|
|
1017
|
+
|
|
1018
|
+
|
|
488
1019
|
__all__: List[str]
|