IncludeCPP 3.6.0__py3-none-any.whl → 3.7.1__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.0 | 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
 
@@ -1000,6 +1003,83 @@ json merged = json::merge(obj1, obj2, obj3);
1000
1003
 
1001
1004
  ---
1002
1005
 
1006
+ ## Instance Management
1007
+
1008
+ CSSL provides `instance<"name">` syntax and `instance::` namespace for working with shared instances.
1009
+
1010
+ ### Instance Declaration
1011
+
1012
+ ```cssl
1013
+ // Get/create shared instance by name
1014
+ instance<"MyApp"> app;
1015
+
1016
+ // With initialization
1017
+ instance<"tk"> tk = include("tkinter.cssl-mod");
1018
+
1019
+ // Register object as shared instance
1020
+ myModule ==> $AppModule
1021
+ // Or using instance syntax:
1022
+ myModule ==> instance<"AppModule">
1023
+ ```
1024
+
1025
+ ### Instance Introspection
1026
+
1027
+ ```cssl
1028
+ @tk = include("tk.cssl-mod");
1029
+
1030
+ // Get all methods from module
1031
+ stack<string> methods = instance::getMethods(@tk);
1032
+ foreach (m in methods) {
1033
+ printl("Method: " + m);
1034
+ }
1035
+
1036
+ // Get all classes
1037
+ stack<string> classes = instance::getClasses(@tk);
1038
+
1039
+ // Get all variables
1040
+ stack<string> vars = instance::getVars(@tk);
1041
+
1042
+ // Get everything categorized
1043
+ json all = instance::getAll(@tk);
1044
+ printl(all.methods); // ["method1", "method2", ...]
1045
+ printl(all.classes); // ["Class1", "Class2", ...]
1046
+ printl(all.vars); // ["var1", "var2", ...]
1047
+ ```
1048
+
1049
+ ### Dynamic Method Calls
1050
+
1051
+ ```cssl
1052
+ // Call method dynamically by name
1053
+ result = instance::call(@module, "methodName", arg1, arg2);
1054
+
1055
+ // Check if method/attribute exists
1056
+ if (instance::has(@module, "initialize")) {
1057
+ instance::call(@module, "initialize");
1058
+ }
1059
+
1060
+ // Get type name
1061
+ string typeName = instance::type(@module);
1062
+ printl(typeName); // "module"
1063
+ ```
1064
+
1065
+ ### All Instance Functions
1066
+
1067
+ | Function | Description |
1068
+ |----------|-------------|
1069
+ | `instance<"name"> var` | Declare instance variable |
1070
+ | `obj ==> instance<"name">` | Register as shared instance |
1071
+ | `instance::getMethods(obj)` | Get all method names |
1072
+ | `instance::getClasses(obj)` | Get all class names |
1073
+ | `instance::getVars(obj)` | Get all variable names |
1074
+ | `instance::getAll(obj)` | Get categorized dict |
1075
+ | `instance::call(obj, 'name', ...)` | Call method dynamically |
1076
+ | `instance::has(obj, 'name')` | Check if attribute exists |
1077
+ | `instance::type(obj)` | Get type name |
1078
+ | `isavailable("name")` | Check if shared instance exists |
1079
+ | `instance::exists("name")` | Alias for isavailable |
1080
+
1081
+ ---
1082
+
1003
1083
  ## Live Object Sharing
1004
1084
 
1005
1085
  Share Python objects with CSSL. Changes in CSSL reflect back to Python.
@@ -1475,6 +1555,188 @@ parameter.return(myObject); // JSON/dict
1475
1555
 
1476
1556
  ---
1477
1557
 
1558
+ ## Classes & OOP
1559
+
1560
+ CSSL supports object-oriented programming with classes, constructors, and the `this->` keyword for member access.
1561
+
1562
+ ### Defining a Class
1563
+
1564
+ ```cssl
1565
+ class Person {
1566
+ // Member variables
1567
+ string name;
1568
+ int age;
1569
+
1570
+ // Constructor (same name as class)
1571
+ void Person(string n, int a) {
1572
+ this->name = n;
1573
+ this->age = a;
1574
+ }
1575
+
1576
+ // Methods
1577
+ void greet() {
1578
+ printl("Hello, I'm " + this->name);
1579
+ }
1580
+
1581
+ string getName() {
1582
+ return this->name;
1583
+ }
1584
+
1585
+ void setAge(int a) {
1586
+ this->age = a;
1587
+ }
1588
+ }
1589
+ ```
1590
+
1591
+ ### Creating Instances
1592
+
1593
+ ```cssl
1594
+ // Use 'new' keyword to instantiate
1595
+ Person p = new Person("Alice", 30);
1596
+
1597
+ // Call methods
1598
+ p.greet(); // prints: "Hello, I'm Alice"
1599
+ string name = p.getName(); // returns "Alice"
1600
+
1601
+ // Access members (if public)
1602
+ printl(p.name); // prints: "Alice"
1603
+ p.age = 31; // set member directly
1604
+ ```
1605
+
1606
+ ### The `this->` Keyword
1607
+
1608
+ Inside class methods, use `this->` to access instance members:
1609
+
1610
+ ```cssl
1611
+ class Counter {
1612
+ int count;
1613
+
1614
+ void Counter() {
1615
+ this->count = 0;
1616
+ }
1617
+
1618
+ void increment() {
1619
+ this->count = this->count + 1;
1620
+ }
1621
+
1622
+ void add(int n) {
1623
+ this->count = this->count + n;
1624
+ }
1625
+
1626
+ int get() {
1627
+ return this->count;
1628
+ }
1629
+ }
1630
+
1631
+ Counter c = new Counter();
1632
+ c.increment();
1633
+ c.add(5);
1634
+ printl(c.get()); // prints: 6
1635
+ ```
1636
+
1637
+ ### Constructor Variations
1638
+
1639
+ ```cssl
1640
+ class MyClass {
1641
+ // Constructor with same name as class
1642
+ void MyClass(int x) {
1643
+ this->value = x;
1644
+ }
1645
+ }
1646
+
1647
+ // Alternative: use __init__
1648
+ class MyClass2 {
1649
+ void __init__(int x) {
1650
+ this->value = x;
1651
+ }
1652
+ }
1653
+ ```
1654
+
1655
+ ### Method Chaining
1656
+
1657
+ ```cssl
1658
+ class Builder {
1659
+ string result;
1660
+
1661
+ void Builder() {
1662
+ this->result = "";
1663
+ }
1664
+
1665
+ Builder add(string s) {
1666
+ this->result = this->result + s;
1667
+ return this;
1668
+ }
1669
+
1670
+ string build() {
1671
+ return this->result;
1672
+ }
1673
+ }
1674
+
1675
+ Builder b = new Builder();
1676
+ string result = b.add("Hello ").add("World!").build();
1677
+ printl(result); // prints: "Hello World!"
1678
+ ```
1679
+
1680
+ ---
1681
+
1682
+ ## Map Container
1683
+
1684
+ The `map<>` type provides C++ style ordered key-value storage.
1685
+
1686
+ ### Creating Maps
1687
+
1688
+ ```cssl
1689
+ map<string, int> ages;
1690
+ map<string, string> config;
1691
+ ```
1692
+
1693
+ ### Basic Operations
1694
+
1695
+ ```cssl
1696
+ map<string, int> ages;
1697
+
1698
+ // Insert values
1699
+ ages.insert("Alice", 30);
1700
+ ages.insert("Bob", 25);
1701
+
1702
+ // Find values
1703
+ int age = ages.find("Alice"); // returns 30
1704
+
1705
+ // Check existence
1706
+ if (ages.contains("Alice")) {
1707
+ printl("Found!");
1708
+ }
1709
+
1710
+ // Erase entries
1711
+ ages.erase("Bob");
1712
+
1713
+ // Get with exception if not found
1714
+ int a = ages.at("Alice"); // throws if not found
1715
+
1716
+ // Size and empty check
1717
+ int size = ages.size();
1718
+ bool empty = ages.empty();
1719
+ ```
1720
+
1721
+ ### Iteration and Bounds
1722
+
1723
+ ```cssl
1724
+ map<string, int> data;
1725
+ data.insert("apple", 1);
1726
+ data.insert("banana", 2);
1727
+ data.insert("cherry", 3);
1728
+
1729
+ // Get first/last elements
1730
+ tuple first = data.begin(); // ("apple", 1)
1731
+ tuple last = data.end(); // ("cherry", 3)
1732
+
1733
+ // Find bounds (for sorted keys)
1734
+ string lb = data.lower_bound("b"); // "banana" (first key >= "b")
1735
+ string ub = data.upper_bound("b"); // "cherry" (first key > "b")
1736
+ ```
1737
+
1738
+ ---
1739
+
1478
1740
  ## Structures
1479
1741
 
1480
1742
  Structures are user-defined data types.
@@ -1810,4 +2072,4 @@ print(result) # ["Missing colon after def"]
1810
2072
 
1811
2073
  ---
1812
2074
 
1813
- *CSSL v3.6.0 - Developed as part of IncludeCPP*
2075
+ *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]: