clipsruby 0.0.34 → 0.0.36

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 +97 -4
  3. data/ext/clipsruby/clipsruby.c +600 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d62cc0e5ccc41bfc4e88590c7a3873859271163fa5dd73b416c0cf2d61b7ed1
4
- data.tar.gz: d3cd61d58609c516b8c952dbc32393d54251f09bdc3a8a5f15f531cdf2d707ee
3
+ metadata.gz: 50cc209eb6a473cd3a980b8d551079a4db6632f86afbc43bff8a582a89efb2cf
4
+ data.tar.gz: 2e2dd6648850df2dc496111334e68aebb9048fb2f823a6b6ddd865449cb34254
5
5
  SHA512:
6
- metadata.gz: c6473260b0da57bb78894841385c6cc1b4ecddb4448dc80edf7c0542e654b8dca6884efdc37b9be976d6b0bed22fadd24da5313ef8ba59b5cd71639a18cd2f42
7
- data.tar.gz: 90af7d185f0ca31b1d543e0550cf4520d021525225e3bba8087d5f449591ffe40fa6a34380293b689876ec9d84dc9b3d8860c18b50b525610b3ca890ff727c5a
6
+ metadata.gz: 9bf9b814174620c68ee826d8051f09bb4d3e989537f4dcce642ba84a651b9dcdfa5acb403378865e05429b1dd03019e07568163c121a58e05368bc664ebd96e4
7
+ data.tar.gz: e3690e9f5b2f28203366e75d845d06dc3ad22173db4ed0a0cdb0ff7246cb0b31f804fc60fde0b6e2be58b29b074f3692ade5f3da6c4f947a2acfc40b1ab1ae21
data/README.md CHANGED
@@ -454,14 +454,14 @@ CLIPS::Environment::Instance.pp_form(instance)
454
454
  instance.pp_form
455
455
  ```
456
456
 
457
- ### `CLIPS::Environment::Instance._class`
458
- ### `CLIPS::Environment::Instance#_class`
457
+ ### `CLIPS::Environment::Instance.defclass`
458
+ ### `CLIPS::Environment::Instance#defclass`
459
459
 
460
460
  Returns the Defclass of an Instance
461
461
 
462
462
  ```ruby
463
- CLIPS::Environment::Instance._class(instance)
464
- instance._class
463
+ CLIPS::Environment::Instance.defclass(instance)
464
+ instance.defclass
465
465
  ```
466
466
 
467
467
  ### `CLIPS::Environment::Defclass.name`
@@ -494,6 +494,46 @@ CLIPS::Environment::Defclass.defmodule_name(defclass)
494
494
  defclass.defmodule_name
495
495
  ```
496
496
 
497
+ ### `CLIPS::Environment::Defclass.get_instance_list`
498
+ ### `CLIPS::Environment::Defclass#get_instance_list`
499
+
500
+ Return an array of Instances of the Defclass.
501
+ Pass `true` as an argument to include instances of subclasses
502
+ of this Defclass.
503
+
504
+ ```ruby
505
+ CLIPS::Environment::Defclass.get_instance_list(defclass)
506
+ CLIPS::Environment::Defclass.get_instance_list(defclass, true)
507
+ defclass.get_instance_list
508
+ defclass.get_instance_list(true)
509
+ ```
510
+
511
+ ### `CLIPS::Environment::Defclass.superclasses`
512
+ ### `CLIPS::Environment::Defclass#superclasses`
513
+
514
+ Return an array of superclasses of the Defclass.
515
+ Pass `true` as an argument to include inherited superclasses.
516
+
517
+ ```ruby
518
+ CLIPS::Environment::Defclass.superclasses(defclass)
519
+ CLIPS::Environment::Defclass.superclasses(defclass, true)
520
+ defclass.superclasses
521
+ defclass.superclasses(true)
522
+ ```
523
+
524
+ ### `CLIPS::Environment::Defclass.subclasses`
525
+ ### `CLIPS::Environment::Defclass#subclasses`
526
+
527
+ Return an array of subclasses of the Defclass.
528
+ Pass `true` as an argument to include inherited subclasses.
529
+
530
+ ```ruby
531
+ CLIPS::Environment::Defclass.subclasses(defclass)
532
+ CLIPS::Environment::Defclass.subclasses(defclass, true)
533
+ defclass.subclasses
534
+ defclass.subclasses(true)
535
+ ```
536
+
497
537
  ### `CLIPS::Environment.find_defrule`
498
538
  ### `CLIPS::Environment#find_defrule`
499
539
 
@@ -504,6 +544,24 @@ CLIPS::Environment.find_defrule(:a)
504
544
  env.find_defrule("foo")
505
545
  ```
506
546
 
547
+ ### `CLIPS::Environment.find_instance`
548
+ ### `CLIPS::Environment#find_instance`
549
+
550
+ Finds an instance by name and returns a CLIPS::Environment::Instance object.
551
+ Can take an optional second and third argument for Defmodule or Demodule name
552
+ and a boolean that represents whether or not the instance should be searched for
553
+ in imported modules.
554
+ If the second argument is `nil`, `find_instance` will search the current module only.
555
+
556
+ ```ruby
557
+ CLIPS::Environment.find_definstance(:a)
558
+ env.find_definstance("foo")
559
+ CLIPS::Environment.find_definstance(:a, :my_module)
560
+ env.find_definstance("foo", "my_module")
561
+ CLIPS::Environment.find_definstance(:a, :my_module, true)
562
+ env.find_definstance("foo", nil, true)
563
+ ```
564
+
507
565
  ### `CLIPS::Environment::Defrule.name`
508
566
  ### `CLIPS::Environment::Defrule#name`
509
567
 
@@ -634,6 +692,21 @@ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
634
692
  defmodule.get_fact_list
635
693
  ```
636
694
 
695
+ ### `CLIPS::Environment::Defmodule.find_instance`
696
+ ### `CLIPS::Environment::Defmodule#find_instance`
697
+
698
+ Finds an instance by name and returns a CLIPS::Environment::Instance object.
699
+ Can take an optional second argument
700
+ of a boolean that represents whether or not the instance should be searched for
701
+ in imported modules.
702
+
703
+ ```ruby
704
+ CLIPS::Environment::Defmodule.find_instance(:a)
705
+ defmodule.find_instance("foo")
706
+ CLIPS::Environment::Defmodule.find_instance(:a, true)
707
+ defmodule.find_instance("foo", true)
708
+ ```
709
+
637
710
  ### `CLIPS::Environment.get_defclass_list`
638
711
  ### `CLIPS::Environment#get_defclass_list`
639
712
 
@@ -650,6 +723,26 @@ CLIPS::Environment.get_defclass_list(env, defmodule)
650
723
  env.get_defclass_list(defmodule)
651
724
  ```
652
725
 
726
+ ### `CLIPS::Environment.get_instance_list`
727
+ ### `CLIPS::Environment#get_instance_list`
728
+
729
+ Return an array of Instances in the environment. Pass an argument of a
730
+ symbol, string, or Defclass object in order to only get Instances
731
+ in that Defclass. If you do not, it will return all Instances of all Defclasses.
732
+ If you do, you may also pass `true` as the second argument
733
+ to include instances of subclasses of this Defclass.
734
+
735
+ ```ruby
736
+ CLIPS::Environment.get_instance_list(env)
737
+ env.get_instance_list
738
+ CLIPS::Environment.get_instance_list(env, :foo_class)
739
+ env.get_instance_list(:"my-class")
740
+ CLIPS::Environment.get_instance_list(env, defclass)
741
+ env.get_instance_list(defclass)
742
+ CLIPS::Environment.get_instance_list(env, defclass, true)
743
+ env.get_instance_list(defclass, true)
744
+ ```
745
+
653
746
  ### `CLIPS::Environment.get_deftemplate_list`
654
747
  ### `CLIPS::Environment#get_deftemplate_list`
655
748
 
@@ -293,6 +293,93 @@ static VALUE clips_environment_defclass_static_pp_form(VALUE self, VALUE rbDefcl
293
293
  return clips_environment_defclass_pp_form(rbDefclass);
294
294
  }
295
295
 
296
+ static VALUE clips_environment_defclass_get_instance_list(int argc, VALUE *argv, VALUE rbDefclass)
297
+ {
298
+ VALUE rbEnvironment, rbInstance, include_subclasses, returnArray;
299
+ Defclass *defclass;
300
+ Instance *theInstance;
301
+ UDFValue iterator;
302
+
303
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
304
+
305
+ returnArray = rb_ary_new2(0);
306
+
307
+ rb_scan_args(argc, argv, "01", &include_subclasses);
308
+
309
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
310
+
311
+ if (include_subclasses != Qtrue) {
312
+ for (
313
+ theInstance = GetNextInstanceInClass(defclass,NULL);
314
+ theInstance != NULL;
315
+ theInstance = GetNextInstanceInClass(defclass,theInstance)
316
+ ) {
317
+ rbInstance =
318
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
319
+
320
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
321
+ rb_ary_push(returnArray, rbInstance);
322
+ }
323
+ } else {
324
+ for (
325
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,NULL,&iterator);
326
+ theInstance != NULL;
327
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,theInstance,&iterator)
328
+ ) {
329
+ rbInstance =
330
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
331
+
332
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
333
+ rb_ary_push(returnArray, rbInstance);
334
+ }
335
+ }
336
+ return returnArray;
337
+ }
338
+
339
+ static VALUE clips_environment_defclass_static_get_instance_list(int argc, VALUE *argv, VALUE rbDefclass)
340
+ {
341
+ VALUE rbEnvironment, rbInstance, include_subclasses, returnArray;
342
+ Defclass *defclass;
343
+ Instance *theInstance;
344
+ UDFValue iterator;
345
+
346
+ returnArray = rb_ary_new2(0);
347
+
348
+ rb_scan_args(argc, argv, "11", &rbDefclass, &include_subclasses);
349
+
350
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
351
+
352
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
353
+
354
+ if (include_subclasses != Qtrue) {
355
+ for (
356
+ theInstance = GetNextInstanceInClass(defclass,NULL);
357
+ theInstance != NULL;
358
+ theInstance = GetNextInstanceInClass(defclass,theInstance)
359
+ ) {
360
+ rbInstance =
361
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
362
+
363
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
364
+ rb_ary_push(returnArray, rbInstance);
365
+ }
366
+ } else {
367
+ for (
368
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,NULL,&iterator);
369
+ theInstance != NULL;
370
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,theInstance,&iterator)
371
+ ) {
372
+ rbInstance =
373
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
374
+
375
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
376
+ rb_ary_push(returnArray, rbInstance);
377
+ }
378
+ }
379
+ return returnArray;
380
+ }
381
+
382
+
296
383
  static VALUE clips_environment_make_instance(VALUE self, VALUE string)
297
384
  {
298
385
  Environment *env;
@@ -380,7 +467,7 @@ static VALUE clips_environment_instance_static_delete(VALUE self, VALUE rbInstan
380
467
  return clips_environment_instance_delete(rbInstance);
381
468
  }
382
469
 
383
- static VALUE clips_environment_instance_class(VALUE self)
470
+ static VALUE clips_environment_instance_defclass(VALUE self)
384
471
  {
385
472
  Defclass *defclass;
386
473
  Instance *instance;
@@ -400,9 +487,9 @@ static VALUE clips_environment_instance_class(VALUE self)
400
487
  return rb_defclass;
401
488
  }
402
489
 
403
- static VALUE clips_environment_instance_static_class(VALUE self, VALUE rbInstance)
490
+ static VALUE clips_environment_instance_static_defclass(VALUE self, VALUE rbInstance)
404
491
  {
405
- return clips_environment_instance_class(rbInstance);
492
+ return clips_environment_instance_defclass(rbInstance);
406
493
  }
407
494
 
408
495
  static VALUE clips_environment_instance_name(VALUE self)
@@ -787,8 +874,13 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnviron
787
874
 
788
875
  rb_iv_set(*value, "@environment", *rbEnvironment);
789
876
  break;
790
- case EXTERNAL_ADDRESS_TYPE:
791
877
  case INSTANCE_ADDRESS_TYPE:
878
+ *value =
879
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(*rbEnvironment), rb_intern("Instance")), &Instance_type, from->instanceValue);
880
+
881
+ rb_iv_set(*value, "@environment", *rbEnvironment);
882
+ break;
883
+ case EXTERNAL_ADDRESS_TYPE:
792
884
  default:
793
885
  WriteString(env,STDERR,"Unsupported data type returned from function\n");
794
886
  *value = Qnil;
@@ -839,8 +931,13 @@ static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, VALUE *rbEnvironment
839
931
 
840
932
  rb_iv_set(*value, "@environment", *rbEnvironment);
841
933
  break;
842
- case EXTERNAL_ADDRESS_TYPE:
843
934
  case INSTANCE_ADDRESS_TYPE:
935
+ *value =
936
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(*rbEnvironment), rb_intern("Instance")), &Instance_type, from->instanceValue);
937
+
938
+ rb_iv_set(*value, "@environment", *rbEnvironment);
939
+ break;
940
+ case EXTERNAL_ADDRESS_TYPE:
844
941
  default:
845
942
  WriteString(env,STDERR,"Unsupported data type returned from function\n");
846
943
  *value = Qnil;
@@ -1018,6 +1115,93 @@ static VALUE clips_environment_deftemplate_static_slot_names(VALUE self, VALUE r
1018
1115
  return clips_environment_deftemplate_slot_names(rbDeftemplate);
1019
1116
  }
1020
1117
 
1118
+ static VALUE clips_environment_defclass_superclasses(int argc, VALUE *argv, VALUE rbDefclass)
1119
+ {
1120
+ VALUE rbEnvironment, inherit;
1121
+ Defclass *defclass;
1122
+ CLIPSValue value;
1123
+ VALUE out;
1124
+
1125
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1126
+
1127
+ rb_scan_args(argc, argv, "01", &inherit);
1128
+
1129
+ if (NIL_P(inherit)) {
1130
+ inherit = Qfalse;
1131
+ }
1132
+
1133
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1134
+
1135
+ ClassSuperclasses(defclass, &value, RTEST(inherit));
1136
+
1137
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1138
+
1139
+ return out;
1140
+ }
1141
+
1142
+ static VALUE clips_environment_defclass_static_superclasses(int argc, VALUE *argv, VALUE klass)
1143
+ {
1144
+ VALUE rbEnvironment, inherit, rbDefclass;
1145
+ Defclass *defclass;
1146
+ CLIPSValue value;
1147
+ VALUE out;
1148
+
1149
+ rb_scan_args(argc, argv, "11", &rbDefclass, &inherit);
1150
+
1151
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1152
+
1153
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1154
+
1155
+ ClassSuperclasses(defclass, &value, RTEST(inherit));
1156
+
1157
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1158
+
1159
+ return out;
1160
+ }
1161
+
1162
+ static VALUE clips_environment_defclass_subclasses(int argc, VALUE *argv, VALUE rbDefclass)
1163
+ {
1164
+ VALUE rbEnvironment, inherit;
1165
+ Defclass *defclass;
1166
+ CLIPSValue value;
1167
+ VALUE out;
1168
+
1169
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1170
+
1171
+ rb_scan_args(argc, argv, "01", &inherit);
1172
+
1173
+ if (NIL_P(inherit)) {
1174
+ inherit = Qfalse;
1175
+ }
1176
+
1177
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1178
+
1179
+ ClassSubclasses(defclass, &value, RTEST(inherit));
1180
+
1181
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1182
+
1183
+ return out;
1184
+ }
1185
+
1186
+ static VALUE clips_environment_defclass_static_subclasses(int argc, VALUE *argv, VALUE klass)
1187
+ {
1188
+ VALUE rbEnvironment, inherit, rbDefclass;
1189
+ Defclass *defclass;
1190
+ CLIPSValue value;
1191
+ VALUE out;
1192
+
1193
+ rb_scan_args(argc, argv, "11", &rbDefclass, &inherit);
1194
+
1195
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1196
+
1197
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1198
+
1199
+ ClassSubclasses(defclass, &value, RTEST(inherit));
1200
+
1201
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1202
+
1203
+ return out;
1204
+ }
1021
1205
 
1022
1206
  static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) {
1023
1207
  VALUE integer;
@@ -1925,6 +2109,223 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
1925
2109
  return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
1926
2110
  }
1927
2111
 
2112
+ static VALUE clips_environment_find_instance(int argc, VALUE *argv, VALUE rbEnvironment) {
2113
+ VALUE instanceName, search_imports, rbInstance, rbDefmodule;
2114
+ Defmodule *defmodule;
2115
+ Environment *env;
2116
+ Instance *instance;
2117
+
2118
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2119
+
2120
+ rb_scan_args(argc, argv, "12", &instanceName, &rbDefmodule, &search_imports);
2121
+
2122
+ const char *cinstanceName;
2123
+ switch(TYPE(instanceName))
2124
+ {
2125
+ case T_SYMBOL:
2126
+ cinstanceName = rb_id2name(SYM2ID(instanceName));
2127
+ break;
2128
+ case T_STRING:
2129
+ cinstanceName = StringValueCStr(instanceName);
2130
+ break;
2131
+ default:
2132
+ rb_warn("instance name must be a String or a Symbol");
2133
+ return Qnil;
2134
+ }
2135
+
2136
+ switch (TYPE(rbDefmodule)) {
2137
+ case T_NIL:
2138
+ defmodule = NULL;
2139
+ break;
2140
+ case T_STRING:
2141
+ case T_SYMBOL:
2142
+ rbDefmodule = clips_environment_find_defmodule(rbEnvironment, rbDefmodule);
2143
+ if (rbDefmodule == Qnil) {
2144
+ return Qnil;
2145
+ }
2146
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2147
+ break;
2148
+ case T_DATA:
2149
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2150
+ break;
2151
+ default:
2152
+ rb_warn("defmodule name must be a symbol or string");
2153
+ return Qnil;
2154
+ }
2155
+
2156
+ instance = FindInstance(
2157
+ env,
2158
+ defmodule,
2159
+ cinstanceName,
2160
+ RTEST(search_imports));
2161
+
2162
+ if (instance == NULL) {
2163
+ return Qnil;
2164
+ } else {
2165
+ rbInstance =
2166
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
2167
+
2168
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2169
+
2170
+ return rbInstance;
2171
+ }
2172
+ }
2173
+
2174
+ static VALUE clips_environment_static_find_instance(int argc, VALUE *argv, VALUE klass) {
2175
+ VALUE rbEnvironment, instanceName, rbInstance, rbDefmodule, search_imports;
2176
+ Defmodule *defmodule;
2177
+ Environment *env;
2178
+ Instance *instance;
2179
+
2180
+ rb_scan_args(argc, argv, "22", &rbEnvironment, &instanceName, &rbDefmodule, &search_imports);
2181
+
2182
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2183
+
2184
+ const char *cinstanceName;
2185
+ switch(TYPE(instanceName))
2186
+ {
2187
+ case T_SYMBOL:
2188
+ cinstanceName = rb_id2name(SYM2ID(instanceName));
2189
+ break;
2190
+ case T_STRING:
2191
+ cinstanceName = StringValueCStr(instanceName);
2192
+ break;
2193
+ default:
2194
+ rb_warn("instance name must be a String or a Symbol");
2195
+ return Qnil;
2196
+ }
2197
+
2198
+ switch (TYPE(rbDefmodule)) {
2199
+ case T_NIL:
2200
+ defmodule = NULL;
2201
+ break;
2202
+ case T_STRING:
2203
+ case T_SYMBOL:
2204
+ rbDefmodule = clips_environment_find_defmodule(rbEnvironment, rbDefmodule);
2205
+ if (rbDefmodule == Qnil) {
2206
+ return Qnil;
2207
+ }
2208
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2209
+ break;
2210
+ case T_DATA:
2211
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2212
+ break;
2213
+ default:
2214
+ rb_warn("defmodule name must be a symbol or string");
2215
+ return Qnil;
2216
+ }
2217
+
2218
+ instance = FindInstance(
2219
+ env,
2220
+ defmodule,
2221
+ cinstanceName,
2222
+ RTEST(search_imports));
2223
+
2224
+ if (instance == NULL) {
2225
+ return Qnil;
2226
+ } else {
2227
+ rbInstance =
2228
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
2229
+
2230
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2231
+
2232
+ return rbInstance;
2233
+ }
2234
+ }
2235
+
2236
+ static VALUE clips_environment_defmodule_find_instance(int argc, VALUE *argv, VALUE rbDefmodule) {
2237
+ VALUE instanceName, search_imports, rbInstance, rbEnvironment;
2238
+ Defmodule *defmodule;
2239
+ Environment *env;
2240
+ Instance *instance;
2241
+ const char *cinstanceName;
2242
+
2243
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2244
+
2245
+ rbEnvironment = rb_iv_get(rbDefmodule, "@environment");
2246
+
2247
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2248
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2249
+
2250
+ rb_scan_args(argc, argv, "11", &instanceName, &search_imports);
2251
+
2252
+ switch(TYPE(instanceName))
2253
+ {
2254
+ case T_SYMBOL:
2255
+ cinstanceName = rb_id2name(SYM2ID(instanceName));
2256
+ break;
2257
+ case T_STRING:
2258
+ cinstanceName = StringValueCStr(instanceName);
2259
+ break;
2260
+ default:
2261
+ rb_warn("instance name must be a String or a Symbol");
2262
+ return Qnil;
2263
+ }
2264
+
2265
+ instance = FindInstance(
2266
+ env,
2267
+ defmodule,
2268
+ cinstanceName,
2269
+ RTEST(search_imports));
2270
+
2271
+ if (instance == NULL) {
2272
+ return Qnil;
2273
+ } else {
2274
+ rbInstance =
2275
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
2276
+
2277
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2278
+
2279
+ return rbInstance;
2280
+ }
2281
+ }
2282
+
2283
+ static VALUE clips_environment_defmodule_static_find_instance(int argc, VALUE *argv, VALUE klass) {
2284
+ VALUE rbDefmodule, rbEnvironment, instanceName, search_imports, rbInstance;
2285
+ Defmodule *defmodule;
2286
+ Environment *env;
2287
+ Instance *instance;
2288
+ const char *cinstanceName;
2289
+
2290
+ rb_scan_args(argc, argv, "21", &rbDefmodule, &instanceName, &search_imports);
2291
+
2292
+ rbEnvironment = rb_iv_get(rbDefmodule, "@environment");
2293
+
2294
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2295
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
2296
+
2297
+ switch(TYPE(instanceName))
2298
+ {
2299
+ case T_SYMBOL:
2300
+ cinstanceName = rb_id2name(SYM2ID(instanceName));
2301
+ break;
2302
+ case T_STRING:
2303
+ cinstanceName = StringValueCStr(instanceName);
2304
+ break;
2305
+ default:
2306
+ rb_warn("instance name must be a String or a Symbol");
2307
+ return Qnil;
2308
+ }
2309
+
2310
+ instance = FindInstance(
2311
+ env,
2312
+ defmodule,
2313
+ cinstanceName,
2314
+ RTEST(search_imports));
2315
+
2316
+ if (instance == NULL) {
2317
+ return Qnil;
2318
+ } else {
2319
+ rbInstance =
2320
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
2321
+
2322
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2323
+
2324
+ return rbInstance;
2325
+ }
2326
+ }
2327
+
2328
+
1928
2329
  static VALUE clips_environment_find_deftemplate(VALUE self, VALUE deftemplate_name)
1929
2330
  {
1930
2331
  Environment *env;
@@ -2159,6 +2560,186 @@ static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE
2159
2560
  return out;
2160
2561
  }
2161
2562
 
2563
+ static VALUE clips_environment_get_instance_list(int argc, VALUE *argv, VALUE rbEnvironment) {
2564
+ VALUE rbDefclass_or_defclass_name, rbDefclass, include_subclasses, rbInstance, returnArray;
2565
+ Environment *env;
2566
+ Defclass *defclass;
2567
+ UDFValue iterator;
2568
+ Instance *theInstance;
2569
+
2570
+ returnArray = rb_ary_new2(0);
2571
+
2572
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2573
+
2574
+ rb_scan_args(argc, argv, "02", &rbDefclass_or_defclass_name, &include_subclasses);
2575
+ // defclass is undefined, ignore include_subclasses
2576
+ if (rbDefclass_or_defclass_name == Qnil) {
2577
+ for (
2578
+ theInstance = GetNextInstance(env,NULL);
2579
+ theInstance != NULL;
2580
+ theInstance = GetNextInstance(env,theInstance)
2581
+ ) {
2582
+ rbInstance =
2583
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
2584
+
2585
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2586
+ rb_ary_push(returnArray, rbInstance);
2587
+ }
2588
+ } else if (include_subclasses != Qtrue) {
2589
+ switch (TYPE(rbDefclass_or_defclass_name)) {
2590
+ case T_STRING:
2591
+ case T_SYMBOL:
2592
+ if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
2593
+ rb_warn("could not find defclass");
2594
+ return Qnil;
2595
+ }
2596
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
2597
+ break;
2598
+ case T_DATA:
2599
+ TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
2600
+ break;
2601
+ default:
2602
+ rb_warn("defclass name must be a symbol or string");
2603
+ return Qnil;
2604
+ }
2605
+ for (
2606
+ theInstance = GetNextInstanceInClass(defclass,NULL);
2607
+ theInstance != NULL;
2608
+ theInstance = GetNextInstanceInClass(defclass,theInstance)
2609
+ ) {
2610
+ rbInstance =
2611
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
2612
+
2613
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2614
+ rb_ary_push(returnArray, rbInstance);
2615
+ }
2616
+ } else if (include_subclasses == Qtrue) {
2617
+ switch (TYPE(rbDefclass_or_defclass_name)) {
2618
+ case T_STRING:
2619
+ case T_SYMBOL:
2620
+ if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
2621
+ rb_warn("could not find defclass");
2622
+ return Qnil;
2623
+ }
2624
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
2625
+ break;
2626
+ case T_DATA:
2627
+ TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
2628
+ break;
2629
+ default:
2630
+ rb_warn("defclass name must be a symbol or string");
2631
+ return Qnil;
2632
+ }
2633
+ for (
2634
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,NULL,&iterator);
2635
+ theInstance != NULL;
2636
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,theInstance,&iterator)
2637
+ ) {
2638
+ rbInstance =
2639
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
2640
+
2641
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2642
+ rb_ary_push(returnArray, rbInstance);
2643
+ }
2644
+ // unexpected input of some kind...
2645
+ } else {
2646
+ rb_warn("unexpected arguments sent to get_instance_list!");
2647
+ return Qnil;
2648
+ }
2649
+
2650
+ return returnArray;
2651
+ }
2652
+
2653
+ static VALUE clips_environment_static_get_instance_list(int argc, VALUE *argv, VALUE klass) {
2654
+ VALUE rbEnvironment, rbDefclass_or_defclass_name, rbDefclass, include_subclasses, rbInstance, returnArray;
2655
+ Environment *env;
2656
+ Defclass *defclass;
2657
+ UDFValue iterator;
2658
+ Instance *theInstance;
2659
+
2660
+ returnArray = rb_ary_new2(0);
2661
+
2662
+ rb_scan_args(argc, argv, "12", &rbEnvironment, &rbDefclass_or_defclass_name, &include_subclasses);
2663
+
2664
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2665
+ // defclass is undefined, ignore include_subclasses
2666
+ if (rbDefclass_or_defclass_name == Qnil) {
2667
+ for (
2668
+ theInstance = GetNextInstance(env,NULL);
2669
+ theInstance != NULL;
2670
+ theInstance = GetNextInstance(env,theInstance)
2671
+ ) {
2672
+ rbInstance =
2673
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
2674
+
2675
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2676
+ rb_ary_push(returnArray, rbInstance);
2677
+ }
2678
+ } else if (include_subclasses != Qtrue) {
2679
+ switch (TYPE(rbDefclass_or_defclass_name)) {
2680
+ case T_STRING:
2681
+ case T_SYMBOL:
2682
+ if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
2683
+ rb_warn("could not find defclass");
2684
+ return Qnil;
2685
+ }
2686
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
2687
+ break;
2688
+ case T_DATA:
2689
+ TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
2690
+ break;
2691
+ default:
2692
+ rb_warn("defclass name must be a symbol or string");
2693
+ return Qnil;
2694
+ }
2695
+ for (
2696
+ theInstance = GetNextInstanceInClass(defclass,NULL);
2697
+ theInstance != NULL;
2698
+ theInstance = GetNextInstanceInClass(defclass,theInstance)
2699
+ ) {
2700
+ rbInstance =
2701
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
2702
+
2703
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2704
+ rb_ary_push(returnArray, rbInstance);
2705
+ }
2706
+ } else if (include_subclasses == Qtrue) {
2707
+ switch (TYPE(rbDefclass_or_defclass_name)) {
2708
+ case T_STRING:
2709
+ case T_SYMBOL:
2710
+ if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
2711
+ rb_warn("could not find defclass");
2712
+ return Qnil;
2713
+ }
2714
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
2715
+ break;
2716
+ case T_DATA:
2717
+ TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
2718
+ break;
2719
+ default:
2720
+ rb_warn("defclass name must be a symbol or string");
2721
+ return Qnil;
2722
+ }
2723
+ for (
2724
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,NULL,&iterator);
2725
+ theInstance != NULL;
2726
+ theInstance = GetNextInstanceInClassAndSubclasses(&defclass,theInstance,&iterator)
2727
+ ) {
2728
+ rbInstance =
2729
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
2730
+
2731
+ rb_iv_set(rbInstance, "@environment", rbEnvironment);
2732
+ rb_ary_push(returnArray, rbInstance);
2733
+ }
2734
+ // unexpected input of some kind...
2735
+ } else {
2736
+ rb_warn("unexpected arguments sent to get_instance_list!");
2737
+ return Qnil;
2738
+ }
2739
+
2740
+ return returnArray;
2741
+ }
2742
+
2162
2743
  static VALUE clips_environment_get_deftemplate_list(int argc, VALUE *argv, VALUE rbEnvironment) {
2163
2744
  VALUE defmodule_or_defmodule_name;
2164
2745
  Environment *env;
@@ -3506,12 +4087,16 @@ void Init_clipsruby(void)
3506
4087
  rb_define_method(rbEnvironment, "find_deftemplate", clips_environment_find_deftemplate, 1);
3507
4088
  rb_define_singleton_method(rbEnvironment, "find_defclass", clips_environment_static_find_defclass, 2);
3508
4089
  rb_define_method(rbEnvironment, "find_defclass", clips_environment_find_defclass, 1);
4090
+ rb_define_singleton_method(rbEnvironment, "find_instance", clips_environment_static_find_instance, -1);
4091
+ rb_define_method(rbEnvironment, "find_instance", clips_environment_find_instance, -1);
3509
4092
  rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
3510
4093
  rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
3511
4094
  rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
3512
4095
  rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
3513
4096
  rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
3514
4097
  rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
4098
+ rb_define_singleton_method(rbEnvironment, "get_instance_list", clips_environment_static_get_instance_list, -1);
4099
+ rb_define_method(rbEnvironment, "get_instance_list", clips_environment_get_instance_list, -1);
3515
4100
  rb_define_singleton_method(rbEnvironment, "get_deftemplate_list", clips_environment_static_get_deftemplate_list, -1);
3516
4101
  rb_define_method(rbEnvironment, "get_deftemplate_list", clips_environment_get_deftemplate_list, -1);
3517
4102
  rb_define_singleton_method(rbEnvironment, "get_defclass_list", clips_environment_static_get_defclass_list, -1);
@@ -3649,6 +4234,8 @@ void Init_clipsruby(void)
3649
4234
  rb_define_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_get_deftemplate_list, 0);
3650
4235
  rb_define_singleton_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_static_get_defrule_list, 1);
3651
4236
  rb_define_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_get_defrule_list, 0);
4237
+ rb_define_singleton_method(rbDefmodule, "find_instance", clips_environment_defmodule_static_find_instance, -1);
4238
+ rb_define_method(rbDefmodule, "find_instance", clips_environment_defmodule_find_instance, -1);
3652
4239
 
3653
4240
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
3654
4241
  rb_define_alloc_func(rbFact, fact_alloc);
@@ -3700,6 +4287,12 @@ void Init_clipsruby(void)
3700
4287
  rb_define_method(rbDefclass, "defmodule_name", clips_environment_defclass_defmodule_name, 0);
3701
4288
  rb_define_singleton_method(rbDefclass, "pp_form", clips_environment_defclass_static_pp_form, 1);
3702
4289
  rb_define_method(rbDefclass, "pp_form", clips_environment_defclass_pp_form, 0);
4290
+ rb_define_singleton_method(rbDefclass, "get_instance_list", clips_environment_defclass_static_get_instance_list, -1);
4291
+ rb_define_method(rbDefclass, "get_instance_list", clips_environment_defclass_get_instance_list, -1);
4292
+ rb_define_singleton_method(rbDefclass, "superclasses", clips_environment_defclass_static_superclasses, -1);
4293
+ rb_define_method(rbDefclass, "superclasses", clips_environment_defclass_superclasses, -1);
4294
+ rb_define_singleton_method(rbDefclass, "subclasses", clips_environment_defclass_static_subclasses, -1);
4295
+ rb_define_method(rbDefclass, "subclasses", clips_environment_defclass_subclasses, -1);
3703
4296
 
3704
4297
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
3705
4298
  rb_define_alloc_func(rbInstance, instance_alloc);
@@ -3707,8 +4300,8 @@ void Init_clipsruby(void)
3707
4300
  rb_define_method(rbInstance, "unmake", clips_environment_instance_unmake, 0);
3708
4301
  rb_define_singleton_method(rbInstance, "delete", clips_environment_instance_static_delete, 1);
3709
4302
  rb_define_method(rbInstance, "delete", clips_environment_instance_delete, 0);
3710
- rb_define_singleton_method(rbInstance, "_class", clips_environment_instance_static_class, 1);
3711
- rb_define_method(rbInstance, "_class", clips_environment_instance_class, 0);
4303
+ rb_define_singleton_method(rbInstance, "defclass", clips_environment_instance_static_defclass, 1);
4304
+ rb_define_method(rbInstance, "defclass", clips_environment_instance_defclass, 0);
3712
4305
  rb_define_singleton_method(rbInstance, "name", clips_environment_instance_static_name, 1);
3713
4306
  rb_define_method(rbInstance, "name", clips_environment_instance_name, 0);
3714
4307
  rb_define_singleton_method(rbInstance, "pp_form", clips_environment_instance_static_pp_form, 1);
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.34
4
+ version: 0.0.36
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-25 00:00:00.000000000 Z
11
+ date: 2024-09-28 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