clipsruby 0.0.41 → 0.0.42

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 +51 -0
  3. data/ext/clipsruby/clipsruby.c +146 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78e7fd97fcf75571bb75e472d6275465c76a7d6cbed969624125850ec0c2cb6f
4
- data.tar.gz: 79ce7ff30742b18bc75ac486c4499fbfb8473ae0e21c2f38f0b235dc7d444b25
3
+ metadata.gz: abe99d4312fdbfdef1029a782a1fba4300a125c4509da2d567de45beedcbd6b3
4
+ data.tar.gz: e97ad52abe0327927ac725d232abb2768ba0f19664f49045400b3be9697860a2
5
5
  SHA512:
6
- metadata.gz: 1647880d18e55105b843376685b5cf675d6a790bd67b13aa7de26e1c6bc1066a0801a22459f975c952506441e555fb6eba0a2345803a129267f936b7cab86667
7
- data.tar.gz: c2bfd4e51a6febef513acb84223f3439ed52ef24511683db9de341a349f523638daac48b932a30e291e73ae49b568b9f1d2f179e341c219a15fee768ec339281
6
+ metadata.gz: c95269f840906a2dbb7cc334b4a96e94d11ad88371bed342ae184ffec38e3496cd0a09407f0d2f1de18e340212592df2993bbe601e3acbe943345cc17ef569d8
7
+ data.tar.gz: c091dc218dd4becdcb69a8670339528ab5ab247b0c01256e6e1c796e827a65880743a3599113c55439e9c1afb63bc27705599c1ea965c82ab4baef83612d9310
data/README.md CHANGED
@@ -152,6 +152,31 @@ CLIPS::Environment.load_facts(env, "./my-load-facts.clp")
152
152
  env.load_facts("./my-load-facts.clp")
153
153
  ```
154
154
 
155
+ #### `CLIPS::Environment.save_instances` / `env.save_instances`
156
+
157
+ Pass the path in which we'll save the environment instances.
158
+ The third argument is optional, and determines whether to store the visible or local instances.
159
+ By default, it'll store local.
160
+
161
+ ```ruby
162
+ CLIPS::Environment.save_instances(env, "./my-save-instances.clp")
163
+ env.save_instances("./my-save-instances.clp")
164
+ CLIPS::Environment.save_instances(env, "./my-save-instances.clp", :local)
165
+ env.save_instances("./my-save-instances.clp", :local)
166
+ CLIPS::Environment.save_instances(env, "./my-save-instances.clp", :visible)
167
+ env.save_instances("./my-save-instances.clp", :visible)
168
+ ```
169
+
170
+ #### `CLIPS::Environment.load_instances` / `env.load_instances`
171
+
172
+ Pass the path to a file that will load the instances stored in the file
173
+ into the environment.
174
+
175
+ ```ruby
176
+ CLIPS::Environment.load_instances(env, "./my-load-instances.clp")
177
+ env.load_instances("./my-load-instances.clp")
178
+ ```
179
+
155
180
  #### `CLIPS::Environment.bsave` / `env.bsave`
156
181
 
157
182
  Pass the path in which we'll save the binary representation of the environment constructs.
@@ -196,6 +221,32 @@ CLIPS::Environment.bload_facts(env, "./my-bload-facts.bin")
196
221
  env.bload_facts("./my-bload-facts.bin")
197
222
  ```
198
223
 
224
+ #### `CLIPS::Environment.bsave_instances` / `env.bsave_instances`
225
+
226
+ Pass the path in which we'll save the binary representation of the environment instances.
227
+ The third argument is optional, and determines whether to store the visible or local instances.
228
+ By default, it'll store local.
229
+
230
+ ```ruby
231
+ CLIPS::Environment.bsave_instances(env, "./my-bsave-instances.bin")
232
+ env.bsave_instances("./my-bsave-instances.bin")
233
+ CLIPS::Environment.bsave_instances(env, "./my-bsave-instances.bin", :local)
234
+ env.bsave_instances("./my-bsave-instances.bin", :local)
235
+ CLIPS::Environment.bsave_instances(env, "./my-bsave-instances.bin", :visible)
236
+ env.bsave_instances("./my-bsave-instances.bin", :visible)
237
+ ```
238
+
239
+ #### `CLIPS::Environment.bload_facts` / `env.bload_facts`
240
+
241
+ Pass the path to a binary file that will load the facts stored in the file
242
+ into the environment.
243
+
244
+ ```ruby
245
+ CLIPS::Environment.bload_facts(env, "./my-bload-facts.bin")
246
+ env.bload_facts("./my-bload-facts.bin")
247
+ ```
248
+
249
+
199
250
  #### `CLIPS::Environment.assert_string` / `CLIPS::Environment#assert_string`
200
251
 
201
252
  Assert a string as a Fact in the CLIPS environment.
@@ -1984,6 +1984,74 @@ static VALUE clips_environment_static_load_facts(VALUE self, VALUE rbEnvironment
1984
1984
  return clips_environment_load_facts(rbEnvironment, path);
1985
1985
  }
1986
1986
 
1987
+ static VALUE clips_environment_save_instances(int argc, VALUE *argv, VALUE rbEnvironment) {
1988
+ VALUE path, scope;
1989
+ Environment *env;
1990
+
1991
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1992
+
1993
+ rb_scan_args(argc, argv, "11", &path, &scope);
1994
+ if (NIL_P(scope)) {
1995
+ scope = ID2SYM(rb_intern("local"));
1996
+ }
1997
+
1998
+ int number_of_instances_saved;
1999
+
2000
+ if (scope == ID2SYM(rb_intern("visible"))) {
2001
+ number_of_instances_saved = SaveInstances(env, StringValueCStr(path), VISIBLE_SAVE);
2002
+ } else if (scope == ID2SYM(rb_intern("local"))) {
2003
+ number_of_instances_saved = SaveInstances(env, StringValueCStr(path), LOCAL_SAVE);
2004
+ } else {
2005
+ rb_warn("could not save_instances: unsupported scope.");
2006
+ return Qnil;
2007
+ }
2008
+ return INT2NUM(number_of_instances_saved);
2009
+ }
2010
+
2011
+ static VALUE clips_environment_static_save_instances(int argc, VALUE *argv, VALUE klass) {
2012
+ VALUE rbEnvironment, path, scope;
2013
+ Environment *env;
2014
+
2015
+ rb_scan_args(argc, argv, "21", &rbEnvironment, &path, &scope);
2016
+
2017
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2018
+
2019
+ if (NIL_P(scope)) {
2020
+ scope = ID2SYM(rb_intern("local"));
2021
+ }
2022
+
2023
+ int number_of_instances_saved;
2024
+
2025
+ if (scope == ID2SYM(rb_intern("visible"))) {
2026
+ number_of_instances_saved = SaveInstances(env, StringValueCStr(path), VISIBLE_SAVE);
2027
+ } else if (scope == ID2SYM(rb_intern("local"))) {
2028
+ number_of_instances_saved = SaveInstances(env, StringValueCStr(path), LOCAL_SAVE);
2029
+ } else {
2030
+ rb_warn("could not save_instances: unsupported scope.");
2031
+ return Qnil;
2032
+ }
2033
+ return INT2NUM(number_of_instances_saved);
2034
+ }
2035
+
2036
+ static VALUE clips_environment_load_instances(VALUE self, VALUE path)
2037
+ {
2038
+ Environment *env;
2039
+
2040
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
2041
+ int number_of_instances_loaded = LoadInstances(env, StringValueCStr(path));
2042
+
2043
+ if (number_of_instances_loaded == -1) {
2044
+ return Qnil;
2045
+ } else {
2046
+ return INT2NUM(number_of_instances_loaded);
2047
+ }
2048
+ }
2049
+
2050
+ static VALUE clips_environment_static_load_instances(VALUE self, VALUE rbEnvironment, VALUE path)
2051
+ {
2052
+ return clips_environment_load_instances(rbEnvironment, path);
2053
+ }
2054
+
1987
2055
  static VALUE clips_environment_bsave(VALUE self, VALUE path)
1988
2056
  {
1989
2057
  Environment *env;
@@ -2089,6 +2157,76 @@ static VALUE clips_environment_static_bload_facts(VALUE self, VALUE rbEnvironmen
2089
2157
  return clips_environment_bload_facts(rbEnvironment, path);
2090
2158
  }
2091
2159
 
2160
+ static VALUE clips_environment_bsave_instances(int argc, VALUE *argv, VALUE rbEnvironment) {
2161
+ VALUE path, scope;
2162
+ Environment *env;
2163
+
2164
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2165
+
2166
+ rb_scan_args(argc, argv, "11", &path, &scope);
2167
+ if (NIL_P(scope)) {
2168
+ scope = ID2SYM(rb_intern("local"));
2169
+ }
2170
+
2171
+ int number_of_instances_saved;
2172
+
2173
+ if (scope == ID2SYM(rb_intern("visible"))) {
2174
+ number_of_instances_saved = BinarySaveInstances(env, StringValueCStr(path), VISIBLE_SAVE);
2175
+ } else if (scope == ID2SYM(rb_intern("local"))) {
2176
+ number_of_instances_saved = BinarySaveInstances(env, StringValueCStr(path), LOCAL_SAVE);
2177
+ } else {
2178
+ rb_warn("could not bsave_instances: unsupported scope.");
2179
+ return Qnil;
2180
+ }
2181
+
2182
+ return INT2NUM(number_of_instances_saved);
2183
+ }
2184
+
2185
+ static VALUE clips_environment_static_bsave_instances(int argc, VALUE *argv, VALUE klass) {
2186
+ VALUE rbEnvironment, path, scope;
2187
+ Environment *env;
2188
+
2189
+ rb_scan_args(argc, argv, "21", &rbEnvironment, &path, &scope);
2190
+
2191
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2192
+
2193
+ if (NIL_P(scope)) {
2194
+ scope = ID2SYM(rb_intern("local"));
2195
+ }
2196
+
2197
+ int number_of_instances_saved;
2198
+
2199
+ if (scope == ID2SYM(rb_intern("visible"))) {
2200
+ number_of_instances_saved = BinarySaveInstances(env, StringValueCStr(path), VISIBLE_SAVE);
2201
+ } else if (scope == ID2SYM(rb_intern("local"))) {
2202
+ number_of_instances_saved = BinarySaveInstances(env, StringValueCStr(path), LOCAL_SAVE);
2203
+ } else {
2204
+ rb_warn("could not bsave_instances: unsupported scope.");
2205
+ return Qnil;
2206
+ }
2207
+ return INT2NUM(number_of_instances_saved);
2208
+ }
2209
+
2210
+ static VALUE clips_environment_bload_instances(VALUE self, VALUE path)
2211
+ {
2212
+ Environment *env;
2213
+
2214
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
2215
+ int number_of_instances_loaded = BinaryLoadInstances(env, StringValueCStr(path));
2216
+
2217
+ if (number_of_instances_loaded == -1) {
2218
+ return Qnil;
2219
+ } else {
2220
+ return INT2NUM(number_of_instances_loaded);
2221
+ }
2222
+ }
2223
+
2224
+ static VALUE clips_environment_static_bload_instances(VALUE self, VALUE rbEnvironment, VALUE path)
2225
+ {
2226
+ return clips_environment_bload_instances(rbEnvironment, path);
2227
+ }
2228
+
2229
+
2092
2230
  static VALUE clips_environment_fact_slot_names(VALUE self)
2093
2231
  {
2094
2232
  Fact *fact;
@@ -4573,6 +4711,10 @@ void Init_clipsruby(void)
4573
4711
  rb_define_method(rbEnvironment, "save_facts", clips_environment_save_facts, -1);
4574
4712
  rb_define_singleton_method(rbEnvironment, "load_facts", clips_environment_static_load_facts, 2);
4575
4713
  rb_define_method(rbEnvironment, "load_facts", clips_environment_load_facts, 1);
4714
+ rb_define_singleton_method(rbEnvironment, "save_instances", clips_environment_static_save_instances, -1);
4715
+ rb_define_method(rbEnvironment, "save_instances", clips_environment_save_instances, -1);
4716
+ rb_define_singleton_method(rbEnvironment, "load_instances", clips_environment_static_load_instances, 2);
4717
+ rb_define_method(rbEnvironment, "load_instances", clips_environment_load_instances, 1);
4576
4718
  rb_define_singleton_method(rbEnvironment, "bsave", clips_environment_static_bsave, 2);
4577
4719
  rb_define_method(rbEnvironment, "bsave", clips_environment_bsave, 1);
4578
4720
  rb_define_singleton_method(rbEnvironment, "bload", clips_environment_static_bload, 2);
@@ -4581,6 +4723,10 @@ void Init_clipsruby(void)
4581
4723
  rb_define_method(rbEnvironment, "bsave_facts", clips_environment_bsave_facts, -1);
4582
4724
  rb_define_singleton_method(rbEnvironment, "bload_facts", clips_environment_static_bload_facts, 2);
4583
4725
  rb_define_method(rbEnvironment, "bload_facts", clips_environment_bload_facts, 1);
4726
+ rb_define_singleton_method(rbEnvironment, "bsave_instances", clips_environment_static_bsave_instances, -1);
4727
+ rb_define_method(rbEnvironment, "bsave_instances", clips_environment_bsave_instances, -1);
4728
+ rb_define_singleton_method(rbEnvironment, "bload_instances", clips_environment_static_bload_instances, 2);
4729
+ rb_define_method(rbEnvironment, "bload_instances", clips_environment_bload_instances, 1);
4584
4730
  rb_define_singleton_method(rbEnvironment, "find_defrule", clips_environment_static_find_defrule, 2);
4585
4731
  rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
4586
4732
  rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
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.41
4
+ version: 0.0.42
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-10-02 00:00:00.000000000 Z
11
+ date: 2024-10-08 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