clipsruby 0.0.11 → 0.0.12

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 +48 -0
  3. data/ext/clipsruby/clipsruby.c +125 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5181c11e5791e9e519d8324fb2b8a72843db339af9f0b0dbbd4c6afccf82c31
4
- data.tar.gz: cd1618021fa058de8c5b05cf7b2aedd77fb0164de1b11323f708d557be1633af
3
+ metadata.gz: 829a0ce02dc7dbe02fb75f5f3324b001240ae4a742de842c95067291481b7b85
4
+ data.tar.gz: d258273d013a710125000c07a3cfad654e22a81fe300c222e0d34b8fd805e1ff
5
5
  SHA512:
6
- metadata.gz: 79e7dc3122317674dc25526ac2957aaad06a36243ab3d611989582a1150782b2872d8662d8091191337511ecac8d51749d74106e6e26fd2e1768de829a2cc07d
7
- data.tar.gz: 02c6ce66e34dfa331ce5b8b77055debf027a39e4ed1d802a95a557bc86eb2b11abff778725dc1fb7d3251497c254ad3249406a90f65f0860dfdce709966bcc7f
6
+ metadata.gz: 30b76872939a39ca16c17f130db788c4aa55cadd7fd2d1ee07e28e1f0daba2d406ff431472f2e666bbe20083703dfc0e78ade13af51fbc0cd2fb9a40e2c7dac7
7
+ data.tar.gz: d0c18d5c756b9318682276aac714721ae2c5c7160324880985cd3e65619086e9ca9f5498c93c65101f19e80038aae7c25bc0f44fe33c3eef2dde55c090608008
data/README.md CHANGED
@@ -39,6 +39,54 @@ CLIPS::Environment.batch_star(env, "./my-batch.bat")
39
39
  env.batch_star("./my-batch.bat")
40
40
  ```
41
41
 
42
+ ### `CLIPS::Environment.bsave`
43
+ ### `env.bsave`
44
+
45
+ Pass the path in which we'll save the binary representation of the environment constructs.
46
+
47
+ ```ruby
48
+ CLIPS::Environment.bsave(env, "./my-bsave.bin")
49
+ env.bsave("./my-bsave.bin")
50
+ ```
51
+
52
+ ### `CLIPS::Environment.bload`
53
+ ### `env.bload`
54
+
55
+ Pass the path to a binary file that will load the constructs stored in the file
56
+ into the environment. Remember to `reset` the environment if you need.
57
+
58
+ ```ruby
59
+ CLIPS::Environment.bload(env, "./my-bload.bin")
60
+ env.bload("./my-bload.bin")
61
+ ```
62
+
63
+ ### `CLIPS::Environment.bsave_facts`
64
+ ### `env.bsave_facts`
65
+
66
+ Pass the path in which we'll save the binary representation of the environment facts.
67
+ The third argument is optional, and determines whether to store the visible or local facts.
68
+ By default, it'll store local.
69
+
70
+ ```ruby
71
+ CLIPS::Environment.bsave(env, "./my-bsave-facts.bin")
72
+ env.bsave("./my-bsave-facts.bin")
73
+ CLIPS::Environment.bsave(env, "./my-bsave-facts.bin", :local)
74
+ env.bsave("./my-bsave-facts.bin", :local)
75
+ CLIPS::Environment.bsave(env, "./my-bsave-facts.bin", :visible)
76
+ env.bsave("./my-bsave-facts.bin", :visible)
77
+ ```
78
+
79
+ ### `CLIPS::Environment.bload_facts`
80
+ ### `env.bload_facts`
81
+
82
+ Pass the path to a binary file that will load the facts stored in the file
83
+ into the environment.
84
+
85
+ ```ruby
86
+ CLIPS::Environment.bload(env, "./my-bload-facts.bin")
87
+ env.bload("./my-bload-facts.bin")
88
+ ```
89
+
42
90
  ### `CLIPS::Environment.assert_string`
43
91
  ### `CLIPS::Environment#assert_string`
44
92
 
@@ -747,6 +747,107 @@ static VALUE clips_environment_static_reset(VALUE self, VALUE rbEnvironment)
747
747
  return clips_environment_reset(rbEnvironment);
748
748
  }
749
749
 
750
+ static VALUE clips_environment_bsave(VALUE self, VALUE path)
751
+ {
752
+ Environment *env;
753
+
754
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
755
+
756
+ if (Bsave(env, StringValueCStr(path))) {
757
+ return Qtrue;
758
+ } else {
759
+ return Qfalse;
760
+ }
761
+ }
762
+
763
+ static VALUE clips_environment_static_bsave(VALUE self, VALUE rbEnvironment, VALUE path)
764
+ {
765
+ return clips_environment_bsave(rbEnvironment, path);
766
+ }
767
+
768
+ static VALUE clips_environment_bload(VALUE self, VALUE path)
769
+ {
770
+ Environment *env;
771
+
772
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
773
+
774
+ if (Bload(env, StringValueCStr(path))) {
775
+ return Qtrue;
776
+ } else {
777
+ return Qfalse;
778
+ }
779
+ }
780
+
781
+ static VALUE clips_environment_static_bload(VALUE self, VALUE rbEnvironment, VALUE path)
782
+ {
783
+ return clips_environment_bload(rbEnvironment, path);
784
+ }
785
+
786
+ static VALUE clips_environment_bsave_facts(int argc, VALUE *argv, VALUE rbEnvironment) {
787
+ VALUE path, scope;
788
+ Environment *env;
789
+
790
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
791
+
792
+ rb_scan_args(argc, argv, "11", &path, &scope);
793
+ if (NIL_P(scope)) {
794
+ scope = ID2SYM(rb_intern("local"));
795
+ }
796
+
797
+ if (scope == ID2SYM(rb_intern("visible"))) {
798
+ return INT2NUM(BinarySaveFacts(env, StringValueCStr(path), VISIBLE_SAVE));
799
+ } else if (scope == ID2SYM(rb_intern("local"))) {
800
+ return INT2NUM(BinarySaveFacts(env, StringValueCStr(path), LOCAL_SAVE));
801
+ } else {
802
+ rb_warn("could not bsave_facts: unsupported scope.");
803
+ return Qnil;
804
+ }
805
+ }
806
+
807
+ static VALUE clips_environment_static_bsave_facts(int argc, VALUE *argv, VALUE klass) {
808
+ VALUE rbEnvironment, path, scope;
809
+ Environment *env;
810
+
811
+ rb_scan_args(argc, argv, "21", &rbEnvironment, &path, &scope);
812
+
813
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
814
+
815
+ if (NIL_P(scope)) {
816
+ scope = ID2SYM(rb_intern("local"));
817
+ }
818
+
819
+ int number_of_facts_saved;
820
+
821
+ if (scope == ID2SYM(rb_intern("visible"))) {
822
+ number_of_facts_saved = BinarySaveFacts(env, StringValueCStr(path), VISIBLE_SAVE);
823
+ } else if (scope == ID2SYM(rb_intern("local"))) {
824
+ number_of_facts_saved = BinarySaveFacts(env, StringValueCStr(path), LOCAL_SAVE);
825
+ } else {
826
+ rb_warn("could not bsave_facts: unsupported scope.");
827
+ return Qnil;
828
+ }
829
+ return INT2NUM(number_of_facts_saved);
830
+ }
831
+
832
+ static VALUE clips_environment_bload_facts(VALUE self, VALUE path)
833
+ {
834
+ Environment *env;
835
+
836
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
837
+ int number_of_facts_loaded = BinaryLoadFacts(env, StringValueCStr(path));
838
+
839
+ if (number_of_facts_loaded == -1) {
840
+ return Qnil;
841
+ } else {
842
+ return INT2NUM(number_of_facts_loaded);
843
+ }
844
+ }
845
+
846
+ static VALUE clips_environment_static_bload_facts(VALUE self, VALUE rbEnvironment, VALUE path)
847
+ {
848
+ return clips_environment_bload_facts(rbEnvironment, path);
849
+ }
850
+
750
851
  static VALUE clips_environment_fact_slot_names(VALUE self)
751
852
  {
752
853
  Fact *fact;
@@ -911,6 +1012,20 @@ static VALUE clips_environment_fact_static_modify(VALUE self, VALUE rbFact, VALU
911
1012
  return clips_environment_fact_modify(rbFact, hash);
912
1013
  }
913
1014
 
1015
+ static VALUE clips_environment_fact_index(VALUE self)
1016
+ {
1017
+ Fact *fact;
1018
+
1019
+ TypedData_Get_Struct(self, Fact, &Fact_type, fact);
1020
+
1021
+ return INT2NUM(FactIndex(fact));
1022
+ }
1023
+
1024
+ static VALUE clips_environment_fact_static_index(VALUE self, VALUE rbFact)
1025
+ {
1026
+ return clips_environment_fact_index(rbFact);
1027
+ }
1028
+
914
1029
 
915
1030
  void Init_clipsruby(void)
916
1031
  {
@@ -941,6 +1056,14 @@ void Init_clipsruby(void)
941
1056
  rb_define_method(rbEnvironment, "clear", clips_environment_clear, 0);
942
1057
  rb_define_singleton_method(rbEnvironment, "reset", clips_environment_static_reset, 1);
943
1058
  rb_define_method(rbEnvironment, "reset", clips_environment_reset, 0);
1059
+ rb_define_singleton_method(rbEnvironment, "bsave", clips_environment_static_bsave, 2);
1060
+ rb_define_method(rbEnvironment, "bsave", clips_environment_bsave, 1);
1061
+ rb_define_singleton_method(rbEnvironment, "bload", clips_environment_static_bload, 2);
1062
+ rb_define_method(rbEnvironment, "bload", clips_environment_bload, 1);
1063
+ rb_define_singleton_method(rbEnvironment, "bsave_facts", clips_environment_static_bsave_facts, -1);
1064
+ rb_define_method(rbEnvironment, "bsave_facts", clips_environment_bsave_facts, -1);
1065
+ rb_define_singleton_method(rbEnvironment, "bload_facts", clips_environment_static_bload_facts, 2);
1066
+ rb_define_method(rbEnvironment, "bload_facts", clips_environment_bload_facts, 1);
944
1067
 
945
1068
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
946
1069
  rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
@@ -955,6 +1078,8 @@ void Init_clipsruby(void)
955
1078
  rb_define_method(rbFact, "retract", clips_environment_fact_retract, 0);
956
1079
  rb_define_singleton_method(rbFact, "modify", clips_environment_fact_static_modify, 2);
957
1080
  rb_define_method(rbFact, "modify", clips_environment_fact_modify, 1);
1081
+ rb_define_singleton_method(rbFact, "index", clips_environment_fact_static_index, 1);
1082
+ rb_define_method(rbFact, "index", clips_environment_fact_index, 0);
958
1083
 
959
1084
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
960
1085
  }
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.11
4
+ version: 0.0.12
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-06 00:00:00.000000000 Z
11
+ date: 2024-09-07 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