IncludeCPP 3.6.0__py3-none-any.whl → 3.7.9__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,6 +1,6 @@
1
1
  # CSSL - C-Style Scripting Language
2
2
 
3
- > Version 3.6.0 | A modern scripting language with C++-style syntax and unique features like CodeInfusion and BruteInjection.
3
+ > Version 3.7.6 | A modern scripting language with C++-style syntax and unique features like CodeInfusion and BruteInjection.
4
4
 
5
5
  ---
6
6
 
@@ -17,17 +17,20 @@
17
17
  9. [String Methods](#string-methods)
18
18
  10. [File I/O](#file-io)
19
19
  11. [JSON Functions](#json-functions)
20
- 12. [Live Object Sharing](#live-object-sharing)
21
- 13. [CodeInfusion](#codeinfusion)
22
- 14. [Value Capture](#value-capture)
23
- 15. [BruteInjection](#bruteinjection)
24
- 16. [Filter Syntax](#filter-syntax)
25
- 17. [Module System](#module-system)
26
- 18. [Parameter Bridge](#parameter-bridge)
27
- 19. [Structures](#structures)
28
- 20. [Error Handling](#error-handling)
29
- 21. [CLI Commands](#cli-commands)
30
- 22. [Examples](#examples)
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)
31
34
 
32
35
  ---
33
36
 
@@ -38,22 +41,25 @@
38
41
  ```python
39
42
  from includecpp import CSSL
40
43
 
41
- # Initialize CSSL
42
- CSSL.CsslLang()
43
-
44
- # Execute code
45
- CSSL.exec("""
44
+ # Execute code (v3.7.6+: use run() instead of exec())
45
+ CSSL.run("""
46
46
  printl("Hello CSSL!");
47
47
  """)
48
48
 
49
49
  # With parameters and return value
50
- result = CSSL.exec("""
50
+ result = CSSL.run("""
51
51
  string name = parameter.get(0);
52
52
  printl("Hello " + name);
53
53
  parameter.return(true);
54
54
  """, "World")
55
55
 
56
56
  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
57
63
  ```
58
64
 
59
65
  ### CLI Execution
@@ -698,12 +704,24 @@ super void forceRun() {
698
704
 
699
705
  ### shuffled
700
706
 
701
- Allows multiple return values.
707
+ Allows multiple return values with tuple unpacking.
702
708
 
703
709
  ```cssl
704
710
  shuffled string getNames() {
705
711
  return "Alice", "Bob", "Charlie";
706
712
  }
713
+
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;
723
+ }
724
+ name, num, flag = getValues();
707
725
  ```
708
726
 
709
727
  ---
@@ -1000,6 +1018,83 @@ json merged = json::merge(obj1, obj2, obj3);
1000
1018
 
1001
1019
  ---
1002
1020
 
1021
+ ## Instance Management
1022
+
1023
+ CSSL provides `instance<"name">` syntax and `instance::` namespace for working with shared instances.
1024
+
1025
+ ### Instance Declaration
1026
+
1027
+ ```cssl
1028
+ // Get/create shared instance by name
1029
+ instance<"MyApp"> app;
1030
+
1031
+ // With initialization
1032
+ instance<"tk"> tk = include("tkinter.cssl-mod");
1033
+
1034
+ // Register object as shared instance
1035
+ myModule ==> $AppModule
1036
+ // Or using instance syntax:
1037
+ myModule ==> instance<"AppModule">
1038
+ ```
1039
+
1040
+ ### Instance Introspection
1041
+
1042
+ ```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
+ }
1050
+
1051
+ // Get all classes
1052
+ stack<string> classes = instance::getClasses(@tk);
1053
+
1054
+ // Get all variables
1055
+ stack<string> vars = instance::getVars(@tk);
1056
+
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", ...]
1062
+ ```
1063
+
1064
+ ### Dynamic Method Calls
1065
+
1066
+ ```cssl
1067
+ // Call method dynamically by name
1068
+ result = instance::call(@module, "methodName", arg1, arg2);
1069
+
1070
+ // Check if method/attribute exists
1071
+ if (instance::has(@module, "initialize")) {
1072
+ instance::call(@module, "initialize");
1073
+ }
1074
+
1075
+ // Get type name
1076
+ string typeName = instance::type(@module);
1077
+ printl(typeName); // "module"
1078
+ ```
1079
+
1080
+ ### All Instance Functions
1081
+
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 |
1095
+
1096
+ ---
1097
+
1003
1098
  ## Live Object Sharing
1004
1099
 
1005
1100
  Share Python objects with CSSL. Changes in CSSL reflect back to Python.
@@ -1063,6 +1158,10 @@ print(stats.total) # 50 - Persisted!
1063
1158
 
1064
1159
  CodeInfusion enables modifying functions at runtime.
1065
1160
 
1161
+ > **Important**: Injection operators must be written **without spaces**:
1162
+ > - ✓ `func() <<==` / `func() +<<==` / `func() -<<==` (correct)
1163
+ > - ✗ `func() < <==` / `func() + <<==` / `func() - <<==` (wrong)
1164
+
1066
1165
  ### <<== (Replace)
1067
1166
 
1068
1167
  Replaces function content.
@@ -1475,6 +1574,188 @@ parameter.return(myObject); // JSON/dict
1475
1574
 
1476
1575
  ---
1477
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
+ ---
1700
+
1701
+ ## Map Container
1702
+
1703
+ The `map<>` type provides C++ style ordered key-value storage.
1704
+
1705
+ ### Creating Maps
1706
+
1707
+ ```cssl
1708
+ map<string, int> ages;
1709
+ map<string, string> config;
1710
+ ```
1711
+
1712
+ ### Basic Operations
1713
+
1714
+ ```cssl
1715
+ map<string, int> ages;
1716
+
1717
+ // Insert values
1718
+ ages.insert("Alice", 30);
1719
+ ages.insert("Bob", 25);
1720
+
1721
+ // Find values
1722
+ int age = ages.find("Alice"); // returns 30
1723
+
1724
+ // Check existence
1725
+ if (ages.contains("Alice")) {
1726
+ printl("Found!");
1727
+ }
1728
+
1729
+ // Erase entries
1730
+ ages.erase("Bob");
1731
+
1732
+ // Get with exception if not found
1733
+ int a = ages.at("Alice"); // throws if not found
1734
+
1735
+ // Size and empty check
1736
+ int size = ages.size();
1737
+ bool empty = ages.empty();
1738
+ ```
1739
+
1740
+ ### Iteration and Bounds
1741
+
1742
+ ```cssl
1743
+ map<string, int> data;
1744
+ data.insert("apple", 1);
1745
+ data.insert("banana", 2);
1746
+ data.insert("cherry", 3);
1747
+
1748
+ // Get first/last elements
1749
+ tuple first = data.begin(); // ("apple", 1)
1750
+ tuple last = data.end(); // ("cherry", 3)
1751
+
1752
+ // Find bounds (for sorted keys)
1753
+ string lb = data.lower_bound("b"); // "banana" (first key >= "b")
1754
+ string ub = data.upper_bound("b"); // "cherry" (first key > "b")
1755
+ ```
1756
+
1757
+ ---
1758
+
1478
1759
  ## Structures
1479
1760
 
1480
1761
  Structures are user-defined data types.
@@ -1810,4 +2091,4 @@ print(result) # ["Missing colon after def"]
1810
2091
 
1811
2092
  ---
1812
2093
 
1813
- *CSSL v3.6.0 - Developed as part of IncludeCPP*
2094
+ *CSSL v3.6.3 - Developed as part of IncludeCPP*
@@ -194,6 +194,17 @@ class CSSLBuiltins:
194
194
  self._functions['json::has'] = self.builtin_json_has
195
195
  self._functions['json::merge'] = self.builtin_json_merge
196
196
 
197
+ # Instance introspection functions (instance::getMethods, etc.)
198
+ self._functions['instance::getMethods'] = self.builtin_instance_getMethods
199
+ self._functions['instance::getClasses'] = self.builtin_instance_getClasses
200
+ self._functions['instance::getVars'] = self.builtin_instance_getVars
201
+ self._functions['instance::getAll'] = self.builtin_instance_getAll
202
+ self._functions['instance::call'] = self.builtin_instance_call
203
+ self._functions['instance::has'] = self.builtin_instance_has
204
+ self._functions['instance::type'] = self.builtin_instance_type
205
+ self._functions['isavailable'] = self.builtin_isavailable
206
+ self._functions['instance::exists'] = self.builtin_isavailable # Alias
207
+
197
208
  # Regex functions
198
209
  self._functions['match'] = self.builtin_match
199
210
  self._functions['search'] = self.builtin_search
@@ -1026,6 +1037,109 @@ class CSSLBuiltins:
1026
1037
  result = deep_merge(result, d)
1027
1038
  return result
1028
1039
 
1040
+ # ============= Instance Introspection Functions =============
1041
+
1042
+ def builtin_instance_getMethods(self, obj: Any) -> list:
1043
+ """Get all methods from an object/module.
1044
+ Usage: instance::getMethods(@module) or instance::getMethods($obj)
1045
+ Returns list of method names.
1046
+ """
1047
+ import inspect
1048
+ methods = []
1049
+ for name in dir(obj):
1050
+ if not name.startswith('_'):
1051
+ attr = getattr(obj, name, None)
1052
+ if callable(attr):
1053
+ methods.append(name)
1054
+ return methods
1055
+
1056
+ def builtin_instance_getClasses(self, obj: Any) -> list:
1057
+ """Get all classes from an object/module.
1058
+ Usage: instance::getClasses(@module)
1059
+ Returns list of class names.
1060
+ """
1061
+ import inspect
1062
+ classes = []
1063
+ for name in dir(obj):
1064
+ if not name.startswith('_'):
1065
+ attr = getattr(obj, name, None)
1066
+ if inspect.isclass(attr):
1067
+ classes.append(name)
1068
+ return classes
1069
+
1070
+ def builtin_instance_getVars(self, obj: Any) -> list:
1071
+ """Get all variables/attributes (non-callable) from an object.
1072
+ Usage: instance::getVars(@module)
1073
+ Returns list of variable names.
1074
+ """
1075
+ vars_list = []
1076
+ for name in dir(obj):
1077
+ if not name.startswith('_'):
1078
+ attr = getattr(obj, name, None)
1079
+ if not callable(attr):
1080
+ vars_list.append(name)
1081
+ return vars_list
1082
+
1083
+ def builtin_instance_getAll(self, obj: Any) -> dict:
1084
+ """Get all attributes from an object, categorized.
1085
+ Usage: instance::getAll(@module)
1086
+ Returns dict with 'methods', 'classes', 'vars' keys.
1087
+ """
1088
+ import inspect
1089
+ result = {
1090
+ 'methods': [],
1091
+ 'classes': [],
1092
+ 'vars': []
1093
+ }
1094
+ for name in dir(obj):
1095
+ if not name.startswith('_'):
1096
+ attr = getattr(obj, name, None)
1097
+ if inspect.isclass(attr):
1098
+ result['classes'].append(name)
1099
+ elif callable(attr):
1100
+ result['methods'].append(name)
1101
+ else:
1102
+ result['vars'].append(name)
1103
+ return result
1104
+
1105
+ def builtin_instance_call(self, obj: Any, method_name: str, *args, **kwargs) -> Any:
1106
+ """Dynamically call a method on an object.
1107
+ Usage: instance::call(@module, 'methodName', arg1, arg2)
1108
+ """
1109
+ method = getattr(obj, method_name, None)
1110
+ if method and callable(method):
1111
+ return method(*args, **kwargs)
1112
+ raise RuntimeError(f"Method '{method_name}' not found on object")
1113
+
1114
+ def builtin_instance_has(self, obj: Any, name: str) -> bool:
1115
+ """Check if object has an attribute.
1116
+ Usage: instance::has(@module, 'methodName')
1117
+ """
1118
+ return hasattr(obj, name)
1119
+
1120
+ def builtin_instance_type(self, obj: Any) -> str:
1121
+ """Get the type name of an object.
1122
+ Usage: instance::type(@module)
1123
+ """
1124
+ return type(obj).__name__
1125
+
1126
+ def builtin_isavailable(self, name_or_obj: Any) -> bool:
1127
+ """Check if a shared instance exists.
1128
+ Usage:
1129
+ isavailable("MyInstance") - check by name string
1130
+ isavailable($MyInstance) - check shared ref (returns True if not None)
1131
+ instance::exists("MyInstance") - alias
1132
+ """
1133
+ from ..cssl_bridge import _live_objects
1134
+
1135
+
1136
+ # If it's a string, check by name
1137
+ if isinstance(name_or_obj, str):
1138
+ return name_or_obj in _live_objects
1139
+
1140
+ # Otherwise, check if the object is not None (for $name or instance<"name">)
1141
+ return name_or_obj is not None
1142
+
1029
1143
  # ============= Regex Functions =============
1030
1144
 
1031
1145
  def builtin_match(self, pattern: str, string: str) -> Optional[dict]: