IncludeCPP 4.0.1__py3-none-any.whl → 4.0.3__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/__init__.py +1 -1
- includecpp/core/cssl/cssl_runtime.py +187 -14
- includecpp/core/cssl/cssl_types.py +143 -1
- includecpp/core/cssl_bridge.py +194 -8
- includecpp/core/cssl_bridge.pyi +717 -186
- includecpp/vscode/cssl/package.json +43 -1
- includecpp/vscode/cssl/syntaxes/cssl.tmLanguage.json +140 -17
- {includecpp-4.0.1.dist-info → includecpp-4.0.3.dist-info}/METADATA +1 -1
- {includecpp-4.0.1.dist-info → includecpp-4.0.3.dist-info}/RECORD +13 -13
- {includecpp-4.0.1.dist-info → includecpp-4.0.3.dist-info}/WHEEL +0 -0
- {includecpp-4.0.1.dist-info → includecpp-4.0.3.dist-info}/entry_points.txt +0 -0
- {includecpp-4.0.1.dist-info → includecpp-4.0.3.dist-info}/licenses/LICENSE +0 -0
- {includecpp-4.0.1.dist-info → includecpp-4.0.3.dist-info}/top_level.txt +0 -0
includecpp/core/cssl_bridge.py
CHANGED
|
@@ -266,8 +266,8 @@ class CSSLFunctionModule:
|
|
|
266
266
|
|
|
267
267
|
from .cssl import CSSLRuntime, parse_cssl_program, ASTNode
|
|
268
268
|
|
|
269
|
-
# Create a dedicated runtime for this module
|
|
270
|
-
self._runtime = CSSLRuntime()
|
|
269
|
+
# Create a dedicated runtime for this module, preserving output_callback
|
|
270
|
+
self._runtime = CSSLRuntime(output_callback=self._cssl._output_callback)
|
|
271
271
|
|
|
272
272
|
# If we have a payload, load it first (defines functions/globals for main)
|
|
273
273
|
if self._payload_code:
|
|
@@ -330,7 +330,12 @@ class CSSLFunctionModule:
|
|
|
330
330
|
self._runtime.global_scope.set('parameter', Parameter(list(args)))
|
|
331
331
|
self._runtime.global_scope.set('args', list(args))
|
|
332
332
|
self._runtime.global_scope.set('argc', len(args))
|
|
333
|
-
|
|
333
|
+
# Enable running flag for function execution
|
|
334
|
+
self._runtime._running = True
|
|
335
|
+
try:
|
|
336
|
+
return self._runtime._call_function(func_node, list(args))
|
|
337
|
+
finally:
|
|
338
|
+
self._runtime._running = False
|
|
334
339
|
|
|
335
340
|
return wrapper
|
|
336
341
|
|
|
@@ -603,7 +608,8 @@ class CsslLang:
|
|
|
603
608
|
self,
|
|
604
609
|
main_script: Union[str, 'CSSLScript'],
|
|
605
610
|
payload_script: Union[str, 'CSSLScript', None] = None,
|
|
606
|
-
name: str = None
|
|
611
|
+
name: str = None,
|
|
612
|
+
bind: str = None
|
|
607
613
|
) -> 'CSSLFunctionModule':
|
|
608
614
|
"""
|
|
609
615
|
Create a CSSL module with accessible functions.
|
|
@@ -612,13 +618,22 @@ class CsslLang:
|
|
|
612
618
|
Optionally registers the module for payload() access in other scripts.
|
|
613
619
|
|
|
614
620
|
Args:
|
|
615
|
-
main_script: Main CSSL code
|
|
621
|
+
main_script: Main CSSL code, file path, or CSSLScript
|
|
616
622
|
payload_script: Optional payload code (string or CSSLScript)
|
|
617
623
|
name: Optional name to register for payload(name) access
|
|
624
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
618
625
|
|
|
619
626
|
Returns:
|
|
620
627
|
CSSLFunctionModule - module with callable function attributes
|
|
621
628
|
|
|
629
|
+
Usage (simplified - with file path and bind):
|
|
630
|
+
# First register the payload
|
|
631
|
+
cssl.makepayload("api", "lib/api/einkaufsmanager.cssl-pl")
|
|
632
|
+
|
|
633
|
+
# Then create module from file, binding to payload
|
|
634
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
635
|
+
mod.SaySomething("Hello!") # Functions are now accessible
|
|
636
|
+
|
|
622
637
|
Usage (v3.8.0 - with CSSLScript objects):
|
|
623
638
|
main = cssl.script("cssl", '''
|
|
624
639
|
printl("Main");
|
|
@@ -644,6 +659,28 @@ class CsslLang:
|
|
|
644
659
|
''')
|
|
645
660
|
module.greet("World") # Returns "Hello, World!"
|
|
646
661
|
"""
|
|
662
|
+
# Handle simplified API: makemodule(name, path, bind=...)
|
|
663
|
+
# Check if main_script looks like a short identifier and payload_script looks like a path
|
|
664
|
+
if (isinstance(main_script, str) and isinstance(payload_script, str) and
|
|
665
|
+
not '\n' in main_script and not ';' in main_script and not '{' in main_script):
|
|
666
|
+
# main_script is likely a name, payload_script is likely a path
|
|
667
|
+
module_name = main_script
|
|
668
|
+
path = payload_script
|
|
669
|
+
|
|
670
|
+
# Check if it's actually a file path
|
|
671
|
+
path_obj = Path(path)
|
|
672
|
+
if path_obj.exists():
|
|
673
|
+
main_code = path_obj.read_text(encoding='utf-8')
|
|
674
|
+
|
|
675
|
+
# If bind is specified, prepend that payload's code
|
|
676
|
+
payload_code = None
|
|
677
|
+
if bind:
|
|
678
|
+
runtime = self._get_runtime()
|
|
679
|
+
if hasattr(runtime, '_inline_payloads') and bind in runtime._inline_payloads:
|
|
680
|
+
payload_code = runtime._inline_payloads[bind]
|
|
681
|
+
|
|
682
|
+
return CSSLFunctionModule(self, main_code, payload_code, module_name)
|
|
683
|
+
|
|
647
684
|
# Extract code from CSSLScript objects if provided
|
|
648
685
|
if isinstance(main_script, CSSLScript):
|
|
649
686
|
main_code = main_script.code
|
|
@@ -657,6 +694,12 @@ class CsslLang:
|
|
|
657
694
|
else:
|
|
658
695
|
payload_code = payload_script
|
|
659
696
|
|
|
697
|
+
# If bind is specified and no payload_script, use the bound payload
|
|
698
|
+
if bind and payload_code is None:
|
|
699
|
+
runtime = self._get_runtime()
|
|
700
|
+
if hasattr(runtime, '_inline_payloads') and bind in runtime._inline_payloads:
|
|
701
|
+
payload_code = runtime._inline_payloads[bind]
|
|
702
|
+
|
|
660
703
|
return CSSLFunctionModule(self, main_code, payload_code, name)
|
|
661
704
|
|
|
662
705
|
def load(self, path: str, name: str) -> None:
|
|
@@ -781,6 +824,45 @@ class CsslLang:
|
|
|
781
824
|
runtime._inline_payloads = {}
|
|
782
825
|
runtime._inline_payloads[name] = code
|
|
783
826
|
|
|
827
|
+
def makepayload(self, name: str, path: str) -> str:
|
|
828
|
+
"""
|
|
829
|
+
Register a payload from a file path.
|
|
830
|
+
|
|
831
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
832
|
+
This is a convenience method that combines reading a file and calling code().
|
|
833
|
+
|
|
834
|
+
Usage:
|
|
835
|
+
from includecpp import CSSL
|
|
836
|
+
cssl = CSSL.CsslLang()
|
|
837
|
+
|
|
838
|
+
# Register a payload from file
|
|
839
|
+
cssl.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
840
|
+
|
|
841
|
+
# Now use in CSSL code
|
|
842
|
+
cssl.run('''
|
|
843
|
+
payload("api"); // Load the payload
|
|
844
|
+
myApiFunction(); // Call functions from it
|
|
845
|
+
''')
|
|
846
|
+
|
|
847
|
+
# Or use with makemodule for automatic binding
|
|
848
|
+
mod = cssl.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
849
|
+
mod.SaySomething("Hello!")
|
|
850
|
+
|
|
851
|
+
Args:
|
|
852
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
853
|
+
path: Path to the .cssl-pl or .cssl file
|
|
854
|
+
|
|
855
|
+
Returns:
|
|
856
|
+
The payload code that was registered
|
|
857
|
+
"""
|
|
858
|
+
path_obj = Path(path)
|
|
859
|
+
if not path_obj.exists():
|
|
860
|
+
raise FileNotFoundError(f"Payload file not found: {path}")
|
|
861
|
+
|
|
862
|
+
code = path_obj.read_text(encoding='utf-8')
|
|
863
|
+
self.code(name, code)
|
|
864
|
+
return code
|
|
865
|
+
|
|
784
866
|
def share(self, instance: Any, name: str = None) -> str:
|
|
785
867
|
"""
|
|
786
868
|
Share a Python object instance with CSSL scripts (LIVE sharing).
|
|
@@ -979,6 +1061,73 @@ class CsslLang:
|
|
|
979
1061
|
"""
|
|
980
1062
|
return self.get_shared(name)
|
|
981
1063
|
|
|
1064
|
+
def getInstance(self, name: str) -> Optional[Any]:
|
|
1065
|
+
"""
|
|
1066
|
+
Get a universal instance by name (for Python-side access).
|
|
1067
|
+
|
|
1068
|
+
Universal instances are shared containers accessible from CSSL, Python, and C++.
|
|
1069
|
+
They support dynamic member/method access and are mutable across all contexts.
|
|
1070
|
+
|
|
1071
|
+
Usage:
|
|
1072
|
+
from includecpp import CSSL
|
|
1073
|
+
cssl = CSSL.CsslLang()
|
|
1074
|
+
|
|
1075
|
+
# In CSSL: instance<"myContainer"> container;
|
|
1076
|
+
# Then in Python:
|
|
1077
|
+
container = cssl.getInstance("myContainer")
|
|
1078
|
+
container.member = "value"
|
|
1079
|
+
print(container.member) # value
|
|
1080
|
+
|
|
1081
|
+
Args:
|
|
1082
|
+
name: Name of the instance (without quotes)
|
|
1083
|
+
|
|
1084
|
+
Returns:
|
|
1085
|
+
The UniversalInstance or None if not found
|
|
1086
|
+
"""
|
|
1087
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1088
|
+
return UniversalInstance.get(name)
|
|
1089
|
+
|
|
1090
|
+
def createInstance(self, name: str) -> Any:
|
|
1091
|
+
"""
|
|
1092
|
+
Create or get a universal instance by name (for Python-side creation).
|
|
1093
|
+
|
|
1094
|
+
Usage:
|
|
1095
|
+
container = cssl.createInstance("myContainer")
|
|
1096
|
+
container.data = {"key": "value"}
|
|
1097
|
+
# Now accessible in CSSL via instance<"myContainer">
|
|
1098
|
+
|
|
1099
|
+
Args:
|
|
1100
|
+
name: Name for the instance
|
|
1101
|
+
|
|
1102
|
+
Returns:
|
|
1103
|
+
The UniversalInstance (new or existing)
|
|
1104
|
+
"""
|
|
1105
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1106
|
+
return UniversalInstance.get_or_create(name)
|
|
1107
|
+
|
|
1108
|
+
def deleteInstance(self, name: str) -> bool:
|
|
1109
|
+
"""
|
|
1110
|
+
Delete a universal instance by name.
|
|
1111
|
+
|
|
1112
|
+
Args:
|
|
1113
|
+
name: Name of the instance to delete
|
|
1114
|
+
|
|
1115
|
+
Returns:
|
|
1116
|
+
True if deleted, False if not found
|
|
1117
|
+
"""
|
|
1118
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1119
|
+
return UniversalInstance.delete(name)
|
|
1120
|
+
|
|
1121
|
+
def listInstances(self) -> list:
|
|
1122
|
+
"""
|
|
1123
|
+
List all universal instance names.
|
|
1124
|
+
|
|
1125
|
+
Returns:
|
|
1126
|
+
List of instance names
|
|
1127
|
+
"""
|
|
1128
|
+
from .cssl.cssl_types import UniversalInstance
|
|
1129
|
+
return UniversalInstance.list_all()
|
|
1130
|
+
|
|
982
1131
|
|
|
983
1132
|
# Global shared objects registry (for cross-instance sharing)
|
|
984
1133
|
_global_shared_objects: Dict[str, str] = {}
|
|
@@ -1303,14 +1452,49 @@ def module(code: str) -> CSSLModule:
|
|
|
1303
1452
|
return get_cssl().module(code)
|
|
1304
1453
|
|
|
1305
1454
|
|
|
1455
|
+
def makepayload(name: str, path: str) -> str:
|
|
1456
|
+
"""
|
|
1457
|
+
Register a payload from a file path.
|
|
1458
|
+
|
|
1459
|
+
Reads the file and registers it as a payload accessible via payload(name) in CSSL.
|
|
1460
|
+
|
|
1461
|
+
Usage:
|
|
1462
|
+
from includecpp import CSSL
|
|
1463
|
+
|
|
1464
|
+
# Register a payload from file
|
|
1465
|
+
CSSL.makepayload("api", "lib/api/myapi.cssl-pl")
|
|
1466
|
+
|
|
1467
|
+
# Use with makemodule for automatic binding
|
|
1468
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
1469
|
+
mod.SaySomething("Hello!")
|
|
1470
|
+
|
|
1471
|
+
Args:
|
|
1472
|
+
name: Name to register the payload under (used in payload(name) and bind=name)
|
|
1473
|
+
path: Path to the .cssl-pl or .cssl file
|
|
1474
|
+
|
|
1475
|
+
Returns:
|
|
1476
|
+
The payload code that was registered
|
|
1477
|
+
"""
|
|
1478
|
+
return get_cssl().makepayload(name, path)
|
|
1479
|
+
|
|
1480
|
+
|
|
1306
1481
|
def makemodule(
|
|
1307
1482
|
main_script: Union[str, CSSLScript],
|
|
1308
1483
|
payload_script: Union[str, CSSLScript, None] = None,
|
|
1309
|
-
name: str = None
|
|
1484
|
+
name: str = None,
|
|
1485
|
+
bind: str = None
|
|
1310
1486
|
) -> CSSLFunctionModule:
|
|
1311
1487
|
"""
|
|
1312
1488
|
Create a CSSL module with accessible functions.
|
|
1313
1489
|
|
|
1490
|
+
Usage (simplified - with file path and bind):
|
|
1491
|
+
# First register the payload
|
|
1492
|
+
CSSL.makepayload("api", "lib/api/einkaufsmanager.cssl-pl")
|
|
1493
|
+
|
|
1494
|
+
# Then create module from file, binding to payload
|
|
1495
|
+
mod = CSSL.makemodule("writer", "lib/writer.cssl", bind="api")
|
|
1496
|
+
mod.SaySomething("Hello!")
|
|
1497
|
+
|
|
1314
1498
|
Usage (v3.8.0 - with CSSLScript):
|
|
1315
1499
|
main = CSSL.script("cssl", '''printl("Main");''')
|
|
1316
1500
|
payload = CSSL.script("cssl-pl", '''void helper() {}''')
|
|
@@ -1323,14 +1507,15 @@ def makemodule(
|
|
|
1323
1507
|
math_mod.add(2, 3) # Returns 5
|
|
1324
1508
|
|
|
1325
1509
|
Args:
|
|
1326
|
-
main_script: Main CSSL code
|
|
1510
|
+
main_script: Main CSSL code, file path, or CSSLScript
|
|
1327
1511
|
payload_script: Optional payload code (string or CSSLScript)
|
|
1328
1512
|
name: Optional name to register for payload(name) access
|
|
1513
|
+
bind: Optional payload name to auto-prepend (from makepayload)
|
|
1329
1514
|
|
|
1330
1515
|
Returns:
|
|
1331
1516
|
CSSLFunctionModule - module with callable function attributes
|
|
1332
1517
|
"""
|
|
1333
|
-
return get_cssl().makemodule(main_script, payload_script, name)
|
|
1518
|
+
return get_cssl().makemodule(main_script, payload_script, name, bind)
|
|
1334
1519
|
|
|
1335
1520
|
|
|
1336
1521
|
# Export all
|
|
@@ -1360,6 +1545,7 @@ __all__ = [
|
|
|
1360
1545
|
'get_output',
|
|
1361
1546
|
'clear_output',
|
|
1362
1547
|
'module',
|
|
1548
|
+
'makepayload',
|
|
1363
1549
|
'makemodule',
|
|
1364
1550
|
'share',
|
|
1365
1551
|
'unshare',
|