IncludeCPP 4.0.2__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.
@@ -412,7 +412,37 @@ class CsslLang:
412
412
  """
413
413
  ...
414
414
 
415
- def makemodule(self, code_or_script: Union[str, CSSLScript], *more: Any) -> CSSLFunctionModule:
415
+ def makepayload(self, name: str, path: str) -> str:
416
+ """
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
428
+
429
+ Usage:
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:
416
446
  """
417
447
  Create a CSSL module with accessible functions as methods.
418
448
 
@@ -420,14 +450,23 @@ class CsslLang:
420
450
  Functions defined in the code become callable Python methods.
421
451
 
422
452
  Args:
423
- code_or_script: CSSL code string or CSSLScript object
424
- *more: Additional scripts or module name
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)
425
457
 
426
458
  Returns:
427
459
  CSSLFunctionModule with callable function attributes
428
460
 
429
- Usage:
430
- # From code string
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):
431
470
  math = cssl.makemodule('''
432
471
  int add(int a, int b) { return a + b; }
433
472
  int sub(int a, int b) { return a - b; }
@@ -435,7 +474,7 @@ class CsslLang:
435
474
  print(math.add(10, 5)) # 15
436
475
  print(math.sub(10, 5)) # 5
437
476
 
438
- # From script objects (for .cssl-mod creation)
477
+ Usage (from script objects):
439
478
  main = cssl.script("cssl", "...")
440
479
  helpers = cssl.script("cssl-pl", "...")
441
480
  mod = cssl.makemodule(main, helpers, "mymodule")
@@ -541,6 +580,66 @@ class CsslLang:
541
580
  """
542
581
  ...
543
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.
589
+
590
+ Args:
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
602
+ """
603
+ ...
604
+
605
+ def createInstance(self, name: str) -> Any:
606
+ """
607
+ Create or get a universal instance by name (for Python-side creation).
608
+
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.
625
+
626
+ Args:
627
+ name: Name of the instance to delete
628
+
629
+ Returns:
630
+ True if deleted, False if not found
631
+ """
632
+ ...
633
+
634
+ def listInstances(self) -> List[str]:
635
+ """
636
+ List all universal instance names.
637
+
638
+ Returns:
639
+ List of instance names
640
+ """
641
+ ...
642
+
544
643
  def set_global(self, name: str, value: Any) -> None:
545
644
  """
546
645
  Set a global variable in the CSSL runtime.
@@ -733,20 +832,59 @@ def module(code: str) -> CSSLModule:
733
832
  ...
734
833
 
735
834
 
736
- def makemodule(code_or_script: Union[str, CSSLScript], *more: Any) -> CSSLFunctionModule:
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.
840
+
841
+ Args:
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
844
+
845
+ Returns:
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!")
857
+ """
858
+ ...
859
+
860
+
861
+ def makemodule(
862
+ main_script: Union[str, CSSLScript],
863
+ payload_script: Union[str, CSSLScript, None] = ...,
864
+ name: str = ...,
865
+ bind: str = ...
866
+ ) -> CSSLFunctionModule:
737
867
  """
738
868
  Create a CSSL module with accessible functions.
739
869
 
740
870
  Args:
741
- code_or_script: CSSL code string or CSSLScript object
742
- *more: Additional scripts or module name
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)
743
875
 
744
876
  Returns:
745
877
  CSSLFunctionModule with callable function attributes
746
878
 
747
- Usage:
879
+ Usage (simplified):
748
880
  from includecpp import CSSL
749
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):
750
888
  math = CSSL.makemodule('''
751
889
  int add(int a, int b) { return a + b; }
752
890
  ''')
@@ -599,13 +599,81 @@ ModuleDescriptor API::parse_cp_file(const std::string& filepath) {
599
599
  }
600
600
  }
601
601
 
602
- // Parse FIELD(type, name) entries
602
+ // v4.1.1: Parse CONSTRUCTOR, METHOD, and FIELD entries for STRUCT
603
603
  auto field_lines = split(field_block, '\n');
604
604
  for (const auto& fline : field_lines) {
605
605
  std::string ftrim = trim(fline);
606
606
  if (ftrim.empty()) continue;
607
607
 
608
- if (ftrim.find("FIELD(") != std::string::npos) {
608
+ // v4.1.1: Parse CONSTRUCTOR(type1, type2, ...) for parametrized constructors
609
+ if (ftrim.find("CONSTRUCTOR") != std::string::npos) {
610
+ size_t c_start = ftrim.find('(');
611
+ size_t c_end = ftrim.rfind(')');
612
+ if (c_start != std::string::npos && c_end != std::string::npos) {
613
+ std::string params_str = ftrim.substr(c_start + 1, c_end - c_start - 1);
614
+ ConstructorInfo ctor;
615
+ if (!params_str.empty()) {
616
+ auto params = split(params_str, ',');
617
+ for (auto& p : params) {
618
+ std::string param_type = trim(p);
619
+ if (!param_type.empty()) {
620
+ ctor.param_types.push_back(param_type);
621
+ }
622
+ }
623
+ }
624
+ sb.constructors.push_back(ctor);
625
+ }
626
+ }
627
+ // v4.1.1: Parse METHOD and METHOD_CONST for STRUCT
628
+ else if (ftrim.find("METHOD") != std::string::npos) {
629
+ MethodSignature sig;
630
+ bool is_const_method = ftrim.find("METHOD_CONST") != std::string::npos;
631
+
632
+ size_t m_start = ftrim.find('(');
633
+ size_t m_end = ftrim.rfind(')');
634
+
635
+ if (m_start != std::string::npos && m_end != std::string::npos) {
636
+ std::string content = ftrim.substr(m_start + 1, m_end - m_start - 1);
637
+
638
+ // Parse method name and optional parameter types
639
+ std::vector<std::string> parts;
640
+ int template_depth = 0;
641
+ std::string current_part;
642
+
643
+ for (char c : content) {
644
+ if (c == '<') {
645
+ template_depth++;
646
+ current_part += c;
647
+ } else if (c == '>') {
648
+ template_depth--;
649
+ current_part += c;
650
+ } else if (c == ',' && template_depth == 0) {
651
+ parts.push_back(trim(current_part));
652
+ current_part.clear();
653
+ } else {
654
+ current_part += c;
655
+ }
656
+ }
657
+ if (!current_part.empty()) {
658
+ parts.push_back(trim(current_part));
659
+ }
660
+
661
+ if (!parts.empty()) {
662
+ sig.name = parts[0];
663
+ sig.is_const = is_const_method;
664
+
665
+ // Remaining parts are parameter types
666
+ for (size_t k = 1; k < parts.size(); ++k) {
667
+ sig.param_types.push_back(parts[k]);
668
+ }
669
+
670
+ sb.method_signatures.push_back(sig);
671
+ sb.methods.push_back(sig.name);
672
+ }
673
+ }
674
+ }
675
+ // Parse FIELD(name) or FIELD(type, name)
676
+ else if (ftrim.find("FIELD(") != std::string::npos) {
609
677
  size_t f_start = ftrim.find('(');
610
678
  size_t f_end = ftrim.find(')');
611
679
  if (f_start != std::string::npos && f_end != std::string::npos) {
@@ -616,6 +684,10 @@ ModuleDescriptor API::parse_cp_file(const std::string& filepath) {
616
684
  std::string field_type = trim(field_parts[0]);
617
685
  std::string field_name = trim(field_parts[1]);
618
686
  sb.fields.push_back({field_type, field_name});
687
+ } else if (field_parts.size() == 1) {
688
+ // Simple FIELD(name) - type will be inferred
689
+ std::string field_name = trim(field_parts[0]);
690
+ sb.fields.push_back({"auto", field_name});
619
691
  }
620
692
  }
621
693
  }
@@ -870,7 +942,24 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
870
942
 
871
943
  code << " py::class_<" << cpp_type << ">(";
872
944
  code << mod.module_name << "_module, \"" << struct_full_name << "\")\n";
873
- code << " .def(py::init<>())\n";
945
+
946
+ // v4.1.1: Generate all constructor overloads from CONSTRUCTOR() entries
947
+ if (sb.constructors.empty()) {
948
+ // Backward compatibility: default constructor if none specified
949
+ code << " .def(py::init<>())\n";
950
+ } else {
951
+ for (const auto& ctor : sb.constructors) {
952
+ code << " .def(py::init<";
953
+ for (size_t i = 0; i < ctor.param_types.size(); ++i) {
954
+ if (i > 0) code << ", ";
955
+ // Replace T with actual template type
956
+ std::string ptype = ctor.param_types[i];
957
+ if (ptype == "T") ptype = ttype;
958
+ code << ptype;
959
+ }
960
+ code << ">())\n";
961
+ }
962
+ }
874
963
 
875
964
  // Fields - readwrite access
876
965
  for (const auto& [field_type, field_name] : sb.fields) {
@@ -884,6 +973,15 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
884
973
  << cpp_type << "::" << field_name << ")\n";
885
974
  }
886
975
 
976
+ // v4.1.1: Generate method bindings
977
+ for (const auto& sig : sb.method_signatures) {
978
+ if (sig.is_const) {
979
+ code << " .def(\"" << sig.name << "\", &" << cpp_type << "::" << sig.name << ")\n";
980
+ } else {
981
+ code << " .def(\"" << sig.name << "\", &" << cpp_type << "::" << sig.name << ")\n";
982
+ }
983
+ }
984
+
887
985
  // Auto-generate to_dict() method
888
986
  code << " .def(\"to_dict\", [](" << cpp_type << "& self) {\n";
889
987
  code << " py::dict d;\n";
@@ -917,7 +1015,21 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
917
1015
  // Non-template struct
918
1016
  code << " py::class_<" << sb.struct_name << ">(";
919
1017
  code << mod.module_name << "_module, \"" << sb.struct_name << "\")\n";
920
- code << " .def(py::init<>())\n";
1018
+
1019
+ // v4.1.1: Generate all constructor overloads from CONSTRUCTOR() entries
1020
+ if (sb.constructors.empty()) {
1021
+ // Backward compatibility: default constructor if none specified
1022
+ code << " .def(py::init<>())\n";
1023
+ } else {
1024
+ for (const auto& ctor : sb.constructors) {
1025
+ code << " .def(py::init<";
1026
+ for (size_t i = 0; i < ctor.param_types.size(); ++i) {
1027
+ if (i > 0) code << ", ";
1028
+ code << ctor.param_types[i];
1029
+ }
1030
+ code << ">())\n";
1031
+ }
1032
+ }
921
1033
 
922
1034
  // Fields
923
1035
  for (const auto& [field_type, field_name] : sb.fields) {
@@ -925,6 +1037,11 @@ std::string generate_struct_bindings(const StructBinding& sb, const ModuleDescri
925
1037
  << sb.struct_name << "::" << field_name << ")\n";
926
1038
  }
927
1039
 
1040
+ // v4.1.1: Generate method bindings
1041
+ for (const auto& sig : sb.method_signatures) {
1042
+ code << " .def(\"" << sig.name << "\", &" << sb.struct_name << "::" << sig.name << ")\n";
1043
+ }
1044
+
928
1045
  // Auto-generate to_dict() method
929
1046
  code << " .def(\"to_dict\", [](" << sb.struct_name << "& self) {\n";
930
1047
  code << " py::dict d;\n";
@@ -127,6 +127,7 @@ struct VariableBinding {
127
127
  };
128
128
 
129
129
  // v2.0: STRUCT() Bindings for Plain-Old-Data types
130
+ // v4.1.1: Added CONSTRUCTOR and METHOD support (same as CLASS)
130
131
  struct StructBinding {
131
132
  std::string module_name;
132
133
  std::string struct_name;
@@ -135,6 +136,11 @@ struct StructBinding {
135
136
  bool is_template = false;
136
137
  std::string documentation;
137
138
 
139
+ // v4.1.1: CONSTRUCTOR and METHOD support for STRUCT (same as CLASS)
140
+ std::vector<ConstructorInfo> constructors;
141
+ std::vector<MethodSignature> method_signatures;
142
+ std::vector<std::string> methods; // Simple method names for backward compatibility
143
+
138
144
  // Helper methods
139
145
  std::string get_full_name() const {
140
146
  return struct_name;
@@ -2,7 +2,7 @@
2
2
  "name": "cssl",
3
3
  "displayName": "CSSL Language",
4
4
  "description": "Professional syntax highlighting, snippets, and language support for CSSL scripts (.cssl, .cssl-pl, .cssl-mod)",
5
- "version": "1.6.0",
5
+ "version": "1.7.1",
6
6
  "publisher": "IncludeCPP",
7
7
  "icon": "images/cssl.png",
8
8
  "engines": {
@@ -151,6 +151,48 @@
151
151
  "description": "Show output panel when running CSSL files"
152
152
  }
153
153
  }
154
+ },
155
+ "configurationDefaults": {
156
+ "editor.tokenColorCustomizations": {
157
+ "textMateRules": [
158
+ {
159
+ "scope": "storage.modifier.cssl",
160
+ "settings": {
161
+ "fontStyle": "italic"
162
+ }
163
+ },
164
+ {
165
+ "scope": "storage.modifier.extends.cssl",
166
+ "settings": {
167
+ "fontStyle": "italic"
168
+ }
169
+ },
170
+ {
171
+ "scope": "storage.modifier.overwrites.cssl",
172
+ "settings": {
173
+ "fontStyle": "italic"
174
+ }
175
+ },
176
+ {
177
+ "scope": "support.type.cssl",
178
+ "settings": {
179
+ "foreground": "#C586C0"
180
+ }
181
+ },
182
+ {
183
+ "scope": "variable.other.declaration.cssl",
184
+ "settings": {
185
+ "foreground": "#9CDCFE"
186
+ }
187
+ },
188
+ {
189
+ "scope": "variable.parameter.cssl",
190
+ "settings": {
191
+ "foreground": "#9CDCFE"
192
+ }
193
+ }
194
+ ]
195
+ }
154
196
  }
155
197
  }
156
198
  }