clipsruby 0.0.22 → 0.0.24

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +76 -0
  3. data/ext/clipsruby/clipsruby.c +228 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f7a174c8ca0889553334a3a6ad54580624d7d92695e3483aa44a130627b3fcb
4
- data.tar.gz: a31141c4ce2490c74218316c89d08342dab315d5c35016c8dd488c2a344f8ae7
3
+ metadata.gz: 1efd15213fd7f558c0b75e64869e6518a12c1c55da8d6d94bf306235f4879a67
4
+ data.tar.gz: b30352c0431948b03849579a92a0e96dde42368f6e78b051adc2f02b68c8c4c8
5
5
  SHA512:
6
- metadata.gz: 863a626437f0c4583e0f35618b4fd29c461b579833970e08999202dc35c2ac306a61b5eb3d029551187c7791d7b7fb22cb3d400d4106dea3c30eb1f1eccd7e73
7
- data.tar.gz: aa4858ed68e383ff113accafb0f4652d4453448e93e6ecfa5c55a5903263925ae4ed114401158cb8d08b291a85eaf82891df0020a0b8f74cd9fbabdb228f4cec
6
+ metadata.gz: 5e55eac1476475ecb1f5b5b998cab1aa108dc0fcbe86905565c3b9256c4855ac796cdd9a28602289dec062c9481ac6340d17c7d22b98b1baf2b0b9e3f338136a
7
+ data.tar.gz: 31c41a7c633cc0707bdfc77e9e9c5b97b2d97d75f8202ce0d7450f7366ec9ee0e2939bcd91d7c228d3d96459ff516eb6f81959981cb1414b53f8c8ee514c6dea
data/README.md CHANGED
@@ -514,6 +514,22 @@ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
514
514
  defmodule.get_fact_list
515
515
  ```
516
516
 
517
+ ### `CLIPS::Environment.get_deftemplate_list`
518
+ ### `CLIPS::Environment#get_deftemplate_list`
519
+
520
+ Return an array of Deftemplate names as symbols in the environment. Pass an argument of a
521
+ symbol, string, or Defmodule object in order to only get Deftemplates
522
+ in that Defmodule. If you do not, it will return all Deftemplate names in all modules.
523
+
524
+ ```ruby
525
+ CLIPS::Environment.get_deftemplate_list
526
+ env.get_deftemplate_list
527
+ CLIPS::Environment.get_deftemplate_list(:MAIN)
528
+ env.get_deftemplate_list(:MAIN)
529
+ CLIPS::Environment.get_deftemplate_list(defmodule)
530
+ env.get_deftemplate_list(defmodule)
531
+ ```
532
+
517
533
  ### `CLIPS::Environment.find_deftemplate`
518
534
  ### `CLIPS::Environment#find_deftemplate`
519
535
 
@@ -555,6 +571,66 @@ CLIPS::Environment::Deftemplate.assert_hash(deftemplate, foo: :bar)
555
571
  deftemplate.assert_hash(foo: :bar)
556
572
  ```
557
573
 
574
+ ### `CLIPS::Environment::Deftemplate.defmodule_name`
575
+ ### `CLIPS::Environment::Deftemplate#defmodule_name`
576
+
577
+ Returns the name of the defmodule in which the deftemplate is defined
578
+
579
+ ```ruby
580
+ CLIPS::Environment::Deftemplate.defmodule_name(deftemplate)
581
+ deftemplate.defmodule_name
582
+ ```
583
+
584
+ ### `CLIPS::Environment::Deftemplate.slot_names`
585
+ ### `CLIPS::Environment::Deftemplate#slot_names`
586
+
587
+ Returns the slot names of a deftemplate as symbols
588
+
589
+ ```ruby
590
+ CLIPS::Environment::Deftemplate.slot_names(deftemplate)
591
+ deftemplate.slot_names
592
+ ```
593
+
594
+ ### `CLIPS::Environment::Deftemplate.is_deletable`
595
+ ### `CLIPS::Environment::Deftemplate#is_deletable`
596
+
597
+ Returns a boolean whether the Deftemplate is deletable or not
598
+
599
+ ```ruby
600
+ CLIPS::Environment::Deftemplate.is_deletable(deftemplate)
601
+ deftemplate.is_deletable
602
+ ```
603
+
604
+ ### `CLIPS::Environment::Deftemplate.slot_allowed_values`
605
+ ### `CLIPS::Environment::Deftemplate#slot_allowed_values`
606
+
607
+ Returns the allowed values for the slot of a deftemplate as symbols
608
+
609
+ ```ruby
610
+ CLIPS::Environment::Deftemplate.slot_allowed_values(deftemplate, :foo)
611
+ deftemplate.slot_allowed_values('bar')
612
+ ```
613
+
614
+ ### `CLIPS::Environment::Deftemplate.slot_default_value`
615
+ ### `CLIPS::Environment::Deftemplate#slot_default_value`
616
+
617
+ Returns the default value(s) for the slot of a deftemplate as symbols
618
+
619
+ ```ruby
620
+ CLIPS::Environment::Deftemplate.slot_default_value(deftemplate, :foo)
621
+ deftemplate.slot_default_value('bar')
622
+ ```
623
+
624
+ ### `CLIPS::Environment::Defmodule.get_deftemplate_list`
625
+ ### `CLIPS::Environment::Defmodule#get_deftemplate_list`
626
+
627
+ Return an array of Deftemplate names as symboles in the Defmodule
628
+
629
+ ```ruby
630
+ CLIPS::Environment::Defmodule.get_deftemplate_list(defmodule)
631
+ defmodule.get_deftemplate_list
632
+ ```
633
+
558
634
  ### `CLIPS::Environment.find_deffacts`
559
635
  ### `CLIPS::Environment#find_deffacts`
560
636
 
@@ -96,6 +96,21 @@ static VALUE clips_environment_fact_static_deftemplate_name(VALUE self, VALUE rb
96
96
  return clips_environment_fact_deftemplate_name(rbFact);
97
97
  }
98
98
 
99
+ static VALUE clips_environment_deftemplate_defmodule_name(VALUE self)
100
+ {
101
+ Deftemplate *template;
102
+
103
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, template);
104
+
105
+ return ID2SYM(rb_intern(DeftemplateModule(template)));
106
+ }
107
+
108
+ static VALUE clips_environment_deftemplate_static_defmodule_name(VALUE self, VALUE rbDeftemplate)
109
+ {
110
+ return clips_environment_deftemplate_defmodule_name(rbDeftemplate);
111
+ }
112
+
113
+
99
114
  void environment_free(void *data)
100
115
  {
101
116
  DestroyEnvironment((Environment*) data);
@@ -736,6 +751,31 @@ static VALUE clips_environment_static_add_udf(int argc, VALUE *argv, VALUE klass
736
751
  return _clips_environment_add_udf(environment, method_name, clips_function_name);
737
752
  }
738
753
 
754
+ static VALUE clips_environment_deftemplate_slot_names(VALUE self)
755
+ {
756
+ Deftemplate *template;
757
+ Environment *env;
758
+ CLIPSValue value;
759
+ VALUE out;
760
+
761
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
762
+
763
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, template);
764
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
765
+
766
+ DeftemplateSlotNames(template, &value);
767
+
768
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
769
+
770
+ return out;
771
+ }
772
+
773
+ static VALUE clips_environment_deftemplate_static_slot_names(VALUE self, VALUE rbDeftemplate)
774
+ {
775
+ return clips_environment_deftemplate_slot_names(rbDeftemplate);
776
+ }
777
+
778
+
739
779
  static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) {
740
780
  VALUE integer;
741
781
  Environment *env;
@@ -1195,6 +1235,71 @@ static VALUE clips_environment_fact_static_get_slot(VALUE self, VALUE rbFact, VA
1195
1235
  return clips_environment_fact_get_slot(rbFact, slot_name);
1196
1236
  }
1197
1237
 
1238
+ static VALUE clips_environment_deftemplate_slot_allowed_values(VALUE self, VALUE slot_name)
1239
+ {
1240
+ Deftemplate *template;
1241
+ CLIPSValue slot_allowed_values;
1242
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
1243
+
1244
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, template);
1245
+
1246
+ switch (TYPE(slot_name)) {
1247
+ case T_STRING:
1248
+ DeftemplateSlotAllowedValues(template, StringValueCStr(slot_name), &slot_allowed_values);
1249
+ break;
1250
+ case T_SYMBOL:
1251
+ DeftemplateSlotAllowedValues(template, rb_id2name(SYM2ID(slot_name)), &slot_allowed_values);
1252
+ break;
1253
+ default:
1254
+ rb_warn("slot name must be string or symbol in call to slot_allowed_values!");
1255
+ return Qnil;
1256
+ }
1257
+
1258
+ VALUE out;
1259
+
1260
+ CLIPSValue_to_VALUE(&slot_allowed_values, &out, &rbEnvironment);
1261
+
1262
+ return out;
1263
+ }
1264
+
1265
+ static VALUE clips_environment_deftemplate_static_slot_allowed_values(VALUE self, VALUE rbDeftemplate, VALUE slot_name)
1266
+ {
1267
+ return clips_environment_deftemplate_slot_allowed_values(rbDeftemplate, slot_name);
1268
+ }
1269
+
1270
+ static VALUE clips_environment_deftemplate_slot_default_value(VALUE self, VALUE slot_name)
1271
+ {
1272
+ Deftemplate *template;
1273
+ CLIPSValue slot_default_value;
1274
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
1275
+
1276
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, template);
1277
+
1278
+ switch (TYPE(slot_name)) {
1279
+ case T_STRING:
1280
+ DeftemplateSlotDefaultValue(template, StringValueCStr(slot_name), &slot_default_value);
1281
+ break;
1282
+ case T_SYMBOL:
1283
+ DeftemplateSlotDefaultValue(template, rb_id2name(SYM2ID(slot_name)), &slot_default_value);
1284
+ break;
1285
+ default:
1286
+ rb_warn("slot name must be string or symbol in call to slot_default_value!");
1287
+ return Qnil;
1288
+ }
1289
+
1290
+ VALUE out;
1291
+
1292
+ CLIPSValue_to_VALUE(&slot_default_value, &out, &rbEnvironment);
1293
+
1294
+ return out;
1295
+ }
1296
+
1297
+ static VALUE clips_environment_deftemplate_static_slot_default_value(VALUE self, VALUE rbDeftemplate, VALUE slot_name)
1298
+ {
1299
+ return clips_environment_deftemplate_slot_default_value(rbDeftemplate, slot_name);
1300
+ }
1301
+
1302
+
1198
1303
  static VALUE clips_environment_fact_retract(VALUE self)
1199
1304
  {
1200
1305
  Fact *fact;
@@ -1664,7 +1769,74 @@ static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE
1664
1769
  CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1665
1770
 
1666
1771
  return out;
1772
+ }
1773
+
1774
+ static VALUE clips_environment_get_deftemplate_list(int argc, VALUE *argv, VALUE rbEnvironment) {
1775
+ VALUE defmodule_or_defmodule_name;
1776
+ Environment *env;
1777
+ Defmodule *module;
1778
+ CLIPSValue value;
1779
+ VALUE out;
1780
+
1781
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1782
+
1783
+ rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
1784
+ switch (TYPE(defmodule_or_defmodule_name)) {
1785
+ case T_NIL:
1786
+ module = NULL;
1787
+ break;
1788
+ case T_STRING:
1789
+ case T_SYMBOL:
1790
+ TypedData_Get_Struct(
1791
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1792
+ Defmodule, &Defmodule_type, module);
1793
+ break;
1794
+ case T_DATA:
1795
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1796
+ break;
1797
+ default:
1798
+ rb_warn("defmodule name must be a symbol or string");
1799
+ return Qnil;
1800
+ }
1801
+ GetDeftemplateList(env, &value, module);
1802
+
1803
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1804
+
1805
+ return out;
1806
+ }
1667
1807
 
1808
+ static VALUE clips_environment_static_get_deftemplate_list(int argc, VALUE *argv, VALUE klass) {
1809
+ VALUE rbEnvironment, defmodule_or_defmodule_name;
1810
+ Environment *env;
1811
+ Defmodule *module;
1812
+ CLIPSValue value;
1813
+ VALUE out;
1814
+
1815
+ rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
1816
+
1817
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1818
+ switch (TYPE(defmodule_or_defmodule_name)) {
1819
+ case T_NIL:
1820
+ module = NULL;
1821
+ break;
1822
+ case T_STRING:
1823
+ case T_SYMBOL:
1824
+ TypedData_Get_Struct(
1825
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1826
+ Defmodule, &Defmodule_type, module);
1827
+ break;
1828
+ case T_DATA:
1829
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1830
+ break;
1831
+ default:
1832
+ rb_warn("defmodule name must be a symbol or string");
1833
+ return Qnil;
1834
+ }
1835
+ GetDeftemplateList(env, &value, module);
1836
+
1837
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1838
+
1839
+ return out;
1668
1840
  }
1669
1841
 
1670
1842
  static VALUE clips_environment_defmodule_name(VALUE self)
@@ -1739,6 +1911,30 @@ static VALUE clips_environment_defmodule_static_get_fact_list(VALUE self, VALUE
1739
1911
  return clips_environment_defmodule_get_fact_list(rbDefmodule);
1740
1912
  }
1741
1913
 
1914
+ static VALUE clips_environment_defmodule_get_deftemplate_list(VALUE self)
1915
+ {
1916
+ Defmodule *module;
1917
+ Environment *env;
1918
+ CLIPSValue value;
1919
+ VALUE out;
1920
+
1921
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
1922
+
1923
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
1924
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1925
+
1926
+ GetDeftemplateList(env, &value, module);
1927
+
1928
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1929
+
1930
+ return out;
1931
+ }
1932
+
1933
+ static VALUE clips_environment_defmodule_static_get_deftemplate_list(VALUE self, VALUE rbDefmodule)
1934
+ {
1935
+ return clips_environment_defmodule_get_deftemplate_list(rbDefmodule);
1936
+ }
1937
+
1742
1938
  static VALUE clips_environment_defrule_name(VALUE self)
1743
1939
  {
1744
1940
  Defrule *defrule;
@@ -1785,6 +1981,24 @@ static VALUE clips_environment_defrule_static_is_deletable(VALUE self, VALUE rbD
1785
1981
  return clips_environment_defrule_is_deletable(rbDefrule);
1786
1982
  }
1787
1983
 
1984
+ static VALUE clips_environment_deftemplate_is_deletable(VALUE self)
1985
+ {
1986
+ Deftemplate *deftemplate;
1987
+
1988
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
1989
+
1990
+ if (DeftemplateIsDeletable(deftemplate)) {
1991
+ return Qtrue;
1992
+ } else {
1993
+ return Qfalse;
1994
+ }
1995
+ }
1996
+
1997
+ static VALUE clips_environment_deftemplate_static_is_deletable(VALUE self, VALUE rbDeftemplate)
1998
+ {
1999
+ return clips_environment_deftemplate_is_deletable(rbDeftemplate);
2000
+ }
2001
+
1788
2002
  static VALUE clips_environment_defrule_has_breakpoint(VALUE self)
1789
2003
  {
1790
2004
  Defrule *defrule;
@@ -1896,6 +2110,8 @@ void Init_clipsruby(void)
1896
2110
  rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
1897
2111
  rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
1898
2112
  rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
2113
+ rb_define_singleton_method(rbEnvironment, "get_deftemplate_list", clips_environment_static_get_deftemplate_list, -1);
2114
+ rb_define_method(rbEnvironment, "get_deftemplate_list", clips_environment_get_deftemplate_list, -1);
1899
2115
  rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
1900
2116
  rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
1901
2117
 
@@ -1914,6 +2130,16 @@ void Init_clipsruby(void)
1914
2130
  rb_define_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_pp_form, 0);
1915
2131
  rb_define_singleton_method(rbDeftemplate, "assert_hash", clips_environment_deftemplate_static_assert_hash, 2);
1916
2132
  rb_define_method(rbDeftemplate, "assert_hash", clips_environment_deftemplate_assert_hash, 1);
2133
+ rb_define_singleton_method(rbDeftemplate, "defmodule_name", clips_environment_deftemplate_static_defmodule_name, 1);
2134
+ rb_define_method(rbDeftemplate, "defmodule_name", clips_environment_deftemplate_defmodule_name, 0);
2135
+ rb_define_singleton_method(rbDeftemplate, "slot_names", clips_environment_deftemplate_static_slot_names, 1);
2136
+ rb_define_method(rbDeftemplate, "slot_names", clips_environment_deftemplate_slot_names, 0);
2137
+ rb_define_singleton_method(rbDeftemplate, "is_deletable", clips_environment_deftemplate_static_is_deletable, 1);
2138
+ rb_define_method(rbDeftemplate, "is_deletable", clips_environment_deftemplate_is_deletable, 0);
2139
+ rb_define_singleton_method(rbDeftemplate, "slot_allowed_values", clips_environment_deftemplate_static_slot_allowed_values, 2);
2140
+ rb_define_method(rbDeftemplate, "slot_allowed_values", clips_environment_deftemplate_slot_allowed_values, 1);
2141
+ rb_define_singleton_method(rbDeftemplate, "slot_default_value", clips_environment_deftemplate_static_slot_default_value, 2);
2142
+ rb_define_method(rbDeftemplate, "slot_default_value", clips_environment_deftemplate_slot_default_value, 1);
1917
2143
 
1918
2144
  VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
1919
2145
  rb_define_alloc_func(rbDefmodule, defmodule_alloc);
@@ -1925,6 +2151,8 @@ void Init_clipsruby(void)
1925
2151
  rb_define_method(rbDefmodule, "set_current", clips_environment_defmodule_set_current, 0);
1926
2152
  rb_define_singleton_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_static_get_fact_list, 1);
1927
2153
  rb_define_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_get_fact_list, 0);
2154
+ rb_define_singleton_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_static_get_deftemplate_list, 1);
2155
+ rb_define_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_get_deftemplate_list, 0);
1928
2156
 
1929
2157
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
1930
2158
  rb_define_alloc_func(rbFact, fact_alloc);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-13 00:00:00.000000000 Z
11
+ date: 2024-09-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Calling the CLIPS programming language from within Ruby
14
14
  email: mrryanjohnston@gmail.com