clipsruby 0.0.34 → 0.0.35
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.
- checksums.yaml +4 -4
- data/README.md +67 -0
- data/ext/clipsruby/clipsruby.c +503 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9bdca59f142899fe858cb253d57ce0d1b2d3eae763a57cb91d7278196e77f88
|
4
|
+
data.tar.gz: 5c958baae6e99acde4729fb3755bbfa9d8ec613e1dfd53b18b970c3824767872
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c57ac8a0cbc763881cfa3275d6f2e3550222e8d575865ce79c9aa0cfebf9eb5d6b66ccc5cae98555d6ba16fe6dca92de1560540cd6252bf5c42353ebdcaf774
|
7
|
+
data.tar.gz: 7c8914796e684ce973ba1058122ed1b4390d1b6043b3086abf70160b5aca79a1ce4e83286daed19a84ea77ff9a7b095f5bd707773763b33bc12e4c205d16635e
|
data/README.md
CHANGED
@@ -494,6 +494,20 @@ 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 and 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
|
+
|
497
511
|
### `CLIPS::Environment.find_defrule`
|
498
512
|
### `CLIPS::Environment#find_defrule`
|
499
513
|
|
@@ -504,6 +518,24 @@ CLIPS::Environment.find_defrule(:a)
|
|
504
518
|
env.find_defrule("foo")
|
505
519
|
```
|
506
520
|
|
521
|
+
### `CLIPS::Environment.find_instance`
|
522
|
+
### `CLIPS::Environment#find_instance`
|
523
|
+
|
524
|
+
Finds an instance by name and returns a CLIPS::Environment::Instance object.
|
525
|
+
Can take an optional second and third argument for Defmodule or Demodule name
|
526
|
+
and a boolean that represents whether or not the instance should be searched for
|
527
|
+
in imported modules.
|
528
|
+
If the second argument is `nil`, `find_instance` will search the current module only.
|
529
|
+
|
530
|
+
```ruby
|
531
|
+
CLIPS::Environment.find_definstance(:a)
|
532
|
+
env.find_definstance("foo")
|
533
|
+
CLIPS::Environment.find_definstance(:a, :my_module)
|
534
|
+
env.find_definstance("foo", "my_module")
|
535
|
+
CLIPS::Environment.find_definstance(:a, :my_module, true)
|
536
|
+
env.find_definstance("foo", nil, true)
|
537
|
+
```
|
538
|
+
|
507
539
|
### `CLIPS::Environment::Defrule.name`
|
508
540
|
### `CLIPS::Environment::Defrule#name`
|
509
541
|
|
@@ -634,6 +666,21 @@ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
|
|
634
666
|
defmodule.get_fact_list
|
635
667
|
```
|
636
668
|
|
669
|
+
### `CLIPS::Environment::Defmodule.find_instance`
|
670
|
+
### `CLIPS::Environment::Defmodule#find_instance`
|
671
|
+
|
672
|
+
Finds an instance by name and returns a CLIPS::Environment::Instance object.
|
673
|
+
Can take an optional second argument
|
674
|
+
of a boolean that represents whether or not the instance should be searched for
|
675
|
+
in imported modules.
|
676
|
+
|
677
|
+
```ruby
|
678
|
+
CLIPS::Environment::Defmodule.find_instance(:a)
|
679
|
+
defmodule.find_instance("foo")
|
680
|
+
CLIPS::Environment::Defmodule.find_instance(:a, true)
|
681
|
+
defmodule.find_instance("foo", true)
|
682
|
+
```
|
683
|
+
|
637
684
|
### `CLIPS::Environment.get_defclass_list`
|
638
685
|
### `CLIPS::Environment#get_defclass_list`
|
639
686
|
|
@@ -650,6 +697,26 @@ CLIPS::Environment.get_defclass_list(env, defmodule)
|
|
650
697
|
env.get_defclass_list(defmodule)
|
651
698
|
```
|
652
699
|
|
700
|
+
### `CLIPS::Environment.get_instance_list`
|
701
|
+
### `CLIPS::Environment#get_instance_list`
|
702
|
+
|
703
|
+
Return an array of Instances in the environment. Pass an argument of a
|
704
|
+
symbol, string, or Defclass object in order to only get Instances
|
705
|
+
in that Defclass. If you do not, it will return all Instances of all Defclasses.
|
706
|
+
If you do, you may also pass `true` as the second argument
|
707
|
+
to include instances of subclasses of this Defclass.
|
708
|
+
|
709
|
+
```ruby
|
710
|
+
CLIPS::Environment.get_instance_list(env)
|
711
|
+
env.get_instance_list
|
712
|
+
CLIPS::Environment.get_instance_list(env, :foo_class)
|
713
|
+
env.get_instance_list(:"my-class")
|
714
|
+
CLIPS::Environment.get_instance_list(env, defclass)
|
715
|
+
env.get_instance_list(defclass)
|
716
|
+
CLIPS::Environment.get_instance_list(env, defclass, true)
|
717
|
+
env.get_instance_list(defclass, true)
|
718
|
+
```
|
719
|
+
|
653
720
|
### `CLIPS::Environment.get_deftemplate_list`
|
654
721
|
### `CLIPS::Environment#get_deftemplate_list`
|
655
722
|
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -293,6 +293,92 @@ 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
|
+
|
296
382
|
static VALUE clips_environment_make_instance(VALUE self, VALUE string)
|
297
383
|
{
|
298
384
|
Environment *env;
|
@@ -787,8 +873,13 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnviron
|
|
787
873
|
|
788
874
|
rb_iv_set(*value, "@environment", *rbEnvironment);
|
789
875
|
break;
|
790
|
-
case EXTERNAL_ADDRESS_TYPE:
|
791
876
|
case INSTANCE_ADDRESS_TYPE:
|
877
|
+
*value =
|
878
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(*rbEnvironment), rb_intern("Instance")), &Instance_type, from->instanceValue);
|
879
|
+
|
880
|
+
rb_iv_set(*value, "@environment", *rbEnvironment);
|
881
|
+
break;
|
882
|
+
case EXTERNAL_ADDRESS_TYPE:
|
792
883
|
default:
|
793
884
|
WriteString(env,STDERR,"Unsupported data type returned from function\n");
|
794
885
|
*value = Qnil;
|
@@ -839,8 +930,13 @@ static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, VALUE *rbEnvironment
|
|
839
930
|
|
840
931
|
rb_iv_set(*value, "@environment", *rbEnvironment);
|
841
932
|
break;
|
842
|
-
case EXTERNAL_ADDRESS_TYPE:
|
843
933
|
case INSTANCE_ADDRESS_TYPE:
|
934
|
+
*value =
|
935
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(*rbEnvironment), rb_intern("Instance")), &Instance_type, from->instanceValue);
|
936
|
+
|
937
|
+
rb_iv_set(*value, "@environment", *rbEnvironment);
|
938
|
+
break;
|
939
|
+
case EXTERNAL_ADDRESS_TYPE:
|
844
940
|
default:
|
845
941
|
WriteString(env,STDERR,"Unsupported data type returned from function\n");
|
846
942
|
*value = Qnil;
|
@@ -1925,6 +2021,223 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
|
|
1925
2021
|
return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
|
1926
2022
|
}
|
1927
2023
|
|
2024
|
+
static VALUE clips_environment_find_instance(int argc, VALUE *argv, VALUE rbEnvironment) {
|
2025
|
+
VALUE instanceName, search_imports, rbInstance, rbDefmodule;
|
2026
|
+
Defmodule *defmodule;
|
2027
|
+
Environment *env;
|
2028
|
+
Instance *instance;
|
2029
|
+
|
2030
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
2031
|
+
|
2032
|
+
rb_scan_args(argc, argv, "12", &instanceName, &rbDefmodule, &search_imports);
|
2033
|
+
|
2034
|
+
const char *cinstanceName;
|
2035
|
+
switch(TYPE(instanceName))
|
2036
|
+
{
|
2037
|
+
case T_SYMBOL:
|
2038
|
+
cinstanceName = rb_id2name(SYM2ID(instanceName));
|
2039
|
+
break;
|
2040
|
+
case T_STRING:
|
2041
|
+
cinstanceName = StringValueCStr(instanceName);
|
2042
|
+
break;
|
2043
|
+
default:
|
2044
|
+
rb_warn("instance name must be a String or a Symbol");
|
2045
|
+
return Qnil;
|
2046
|
+
}
|
2047
|
+
|
2048
|
+
switch (TYPE(rbDefmodule)) {
|
2049
|
+
case T_NIL:
|
2050
|
+
defmodule = NULL;
|
2051
|
+
break;
|
2052
|
+
case T_STRING:
|
2053
|
+
case T_SYMBOL:
|
2054
|
+
rbDefmodule = clips_environment_find_defmodule(rbEnvironment, rbDefmodule);
|
2055
|
+
if (rbDefmodule == Qnil) {
|
2056
|
+
return Qnil;
|
2057
|
+
}
|
2058
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2059
|
+
break;
|
2060
|
+
case T_DATA:
|
2061
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2062
|
+
break;
|
2063
|
+
default:
|
2064
|
+
rb_warn("defmodule name must be a symbol or string");
|
2065
|
+
return Qnil;
|
2066
|
+
}
|
2067
|
+
|
2068
|
+
instance = FindInstance(
|
2069
|
+
env,
|
2070
|
+
defmodule,
|
2071
|
+
cinstanceName,
|
2072
|
+
RTEST(search_imports));
|
2073
|
+
|
2074
|
+
if (instance == NULL) {
|
2075
|
+
return Qnil;
|
2076
|
+
} else {
|
2077
|
+
rbInstance =
|
2078
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
|
2079
|
+
|
2080
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2081
|
+
|
2082
|
+
return rbInstance;
|
2083
|
+
}
|
2084
|
+
}
|
2085
|
+
|
2086
|
+
static VALUE clips_environment_static_find_instance(int argc, VALUE *argv, VALUE klass) {
|
2087
|
+
VALUE rbEnvironment, instanceName, rbInstance, rbDefmodule, search_imports;
|
2088
|
+
Defmodule *defmodule;
|
2089
|
+
Environment *env;
|
2090
|
+
Instance *instance;
|
2091
|
+
|
2092
|
+
rb_scan_args(argc, argv, "22", &rbEnvironment, &instanceName, &rbDefmodule, &search_imports);
|
2093
|
+
|
2094
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
2095
|
+
|
2096
|
+
const char *cinstanceName;
|
2097
|
+
switch(TYPE(instanceName))
|
2098
|
+
{
|
2099
|
+
case T_SYMBOL:
|
2100
|
+
cinstanceName = rb_id2name(SYM2ID(instanceName));
|
2101
|
+
break;
|
2102
|
+
case T_STRING:
|
2103
|
+
cinstanceName = StringValueCStr(instanceName);
|
2104
|
+
break;
|
2105
|
+
default:
|
2106
|
+
rb_warn("instance name must be a String or a Symbol");
|
2107
|
+
return Qnil;
|
2108
|
+
}
|
2109
|
+
|
2110
|
+
switch (TYPE(rbDefmodule)) {
|
2111
|
+
case T_NIL:
|
2112
|
+
defmodule = NULL;
|
2113
|
+
break;
|
2114
|
+
case T_STRING:
|
2115
|
+
case T_SYMBOL:
|
2116
|
+
rbDefmodule = clips_environment_find_defmodule(rbEnvironment, rbDefmodule);
|
2117
|
+
if (rbDefmodule == Qnil) {
|
2118
|
+
return Qnil;
|
2119
|
+
}
|
2120
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2121
|
+
break;
|
2122
|
+
case T_DATA:
|
2123
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2124
|
+
break;
|
2125
|
+
default:
|
2126
|
+
rb_warn("defmodule name must be a symbol or string");
|
2127
|
+
return Qnil;
|
2128
|
+
}
|
2129
|
+
|
2130
|
+
instance = FindInstance(
|
2131
|
+
env,
|
2132
|
+
defmodule,
|
2133
|
+
cinstanceName,
|
2134
|
+
RTEST(search_imports));
|
2135
|
+
|
2136
|
+
if (instance == NULL) {
|
2137
|
+
return Qnil;
|
2138
|
+
} else {
|
2139
|
+
rbInstance =
|
2140
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
|
2141
|
+
|
2142
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2143
|
+
|
2144
|
+
return rbInstance;
|
2145
|
+
}
|
2146
|
+
}
|
2147
|
+
|
2148
|
+
static VALUE clips_environment_defmodule_find_instance(int argc, VALUE *argv, VALUE rbDefmodule) {
|
2149
|
+
VALUE instanceName, search_imports, rbInstance, rbEnvironment;
|
2150
|
+
Defmodule *defmodule;
|
2151
|
+
Environment *env;
|
2152
|
+
Instance *instance;
|
2153
|
+
const char *cinstanceName;
|
2154
|
+
|
2155
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2156
|
+
|
2157
|
+
rbEnvironment = rb_iv_get(rbDefmodule, "@environment");
|
2158
|
+
|
2159
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
2160
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2161
|
+
|
2162
|
+
rb_scan_args(argc, argv, "11", &instanceName, &search_imports);
|
2163
|
+
|
2164
|
+
switch(TYPE(instanceName))
|
2165
|
+
{
|
2166
|
+
case T_SYMBOL:
|
2167
|
+
cinstanceName = rb_id2name(SYM2ID(instanceName));
|
2168
|
+
break;
|
2169
|
+
case T_STRING:
|
2170
|
+
cinstanceName = StringValueCStr(instanceName);
|
2171
|
+
break;
|
2172
|
+
default:
|
2173
|
+
rb_warn("instance name must be a String or a Symbol");
|
2174
|
+
return Qnil;
|
2175
|
+
}
|
2176
|
+
|
2177
|
+
instance = FindInstance(
|
2178
|
+
env,
|
2179
|
+
defmodule,
|
2180
|
+
cinstanceName,
|
2181
|
+
RTEST(search_imports));
|
2182
|
+
|
2183
|
+
if (instance == NULL) {
|
2184
|
+
return Qnil;
|
2185
|
+
} else {
|
2186
|
+
rbInstance =
|
2187
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
|
2188
|
+
|
2189
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2190
|
+
|
2191
|
+
return rbInstance;
|
2192
|
+
}
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
static VALUE clips_environment_defmodule_static_find_instance(int argc, VALUE *argv, VALUE klass) {
|
2196
|
+
VALUE rbDefmodule, rbEnvironment, instanceName, search_imports, rbInstance;
|
2197
|
+
Defmodule *defmodule;
|
2198
|
+
Environment *env;
|
2199
|
+
Instance *instance;
|
2200
|
+
const char *cinstanceName;
|
2201
|
+
|
2202
|
+
rb_scan_args(argc, argv, "21", &rbDefmodule, &instanceName, &search_imports);
|
2203
|
+
|
2204
|
+
rbEnvironment = rb_iv_get(rbDefmodule, "@environment");
|
2205
|
+
|
2206
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
2207
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, defmodule);
|
2208
|
+
|
2209
|
+
switch(TYPE(instanceName))
|
2210
|
+
{
|
2211
|
+
case T_SYMBOL:
|
2212
|
+
cinstanceName = rb_id2name(SYM2ID(instanceName));
|
2213
|
+
break;
|
2214
|
+
case T_STRING:
|
2215
|
+
cinstanceName = StringValueCStr(instanceName);
|
2216
|
+
break;
|
2217
|
+
default:
|
2218
|
+
rb_warn("instance name must be a String or a Symbol");
|
2219
|
+
return Qnil;
|
2220
|
+
}
|
2221
|
+
|
2222
|
+
instance = FindInstance(
|
2223
|
+
env,
|
2224
|
+
defmodule,
|
2225
|
+
cinstanceName,
|
2226
|
+
RTEST(search_imports));
|
2227
|
+
|
2228
|
+
if (instance == NULL) {
|
2229
|
+
return Qnil;
|
2230
|
+
} else {
|
2231
|
+
rbInstance =
|
2232
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, instance);
|
2233
|
+
|
2234
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2235
|
+
|
2236
|
+
return rbInstance;
|
2237
|
+
}
|
2238
|
+
}
|
2239
|
+
|
2240
|
+
|
1928
2241
|
static VALUE clips_environment_find_deftemplate(VALUE self, VALUE deftemplate_name)
|
1929
2242
|
{
|
1930
2243
|
Environment *env;
|
@@ -2159,6 +2472,186 @@ static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE
|
|
2159
2472
|
return out;
|
2160
2473
|
}
|
2161
2474
|
|
2475
|
+
static VALUE clips_environment_get_instance_list(int argc, VALUE *argv, VALUE rbEnvironment) {
|
2476
|
+
VALUE rbDefclass_or_defclass_name, rbDefclass, include_subclasses, rbInstance, returnArray;
|
2477
|
+
Environment *env;
|
2478
|
+
Defclass *defclass;
|
2479
|
+
UDFValue iterator;
|
2480
|
+
Instance *theInstance;
|
2481
|
+
|
2482
|
+
returnArray = rb_ary_new2(0);
|
2483
|
+
|
2484
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
2485
|
+
|
2486
|
+
rb_scan_args(argc, argv, "02", &rbDefclass_or_defclass_name, &include_subclasses);
|
2487
|
+
// defclass is undefined, ignore include_subclasses
|
2488
|
+
if (rbDefclass_or_defclass_name == Qnil) {
|
2489
|
+
for (
|
2490
|
+
theInstance = GetNextInstance(env,NULL);
|
2491
|
+
theInstance != NULL;
|
2492
|
+
theInstance = GetNextInstance(env,theInstance)
|
2493
|
+
) {
|
2494
|
+
rbInstance =
|
2495
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
|
2496
|
+
|
2497
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2498
|
+
rb_ary_push(returnArray, rbInstance);
|
2499
|
+
}
|
2500
|
+
} else if (include_subclasses != Qtrue) {
|
2501
|
+
switch (TYPE(rbDefclass_or_defclass_name)) {
|
2502
|
+
case T_STRING:
|
2503
|
+
case T_SYMBOL:
|
2504
|
+
if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
|
2505
|
+
rb_warn("could not find defclass");
|
2506
|
+
return Qnil;
|
2507
|
+
}
|
2508
|
+
TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
|
2509
|
+
break;
|
2510
|
+
case T_DATA:
|
2511
|
+
TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
|
2512
|
+
break;
|
2513
|
+
default:
|
2514
|
+
rb_warn("defclass name must be a symbol or string");
|
2515
|
+
return Qnil;
|
2516
|
+
}
|
2517
|
+
for (
|
2518
|
+
theInstance = GetNextInstanceInClass(defclass,NULL);
|
2519
|
+
theInstance != NULL;
|
2520
|
+
theInstance = GetNextInstanceInClass(defclass,theInstance)
|
2521
|
+
) {
|
2522
|
+
rbInstance =
|
2523
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
|
2524
|
+
|
2525
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2526
|
+
rb_ary_push(returnArray, rbInstance);
|
2527
|
+
}
|
2528
|
+
} else if (include_subclasses == Qtrue) {
|
2529
|
+
switch (TYPE(rbDefclass_or_defclass_name)) {
|
2530
|
+
case T_STRING:
|
2531
|
+
case T_SYMBOL:
|
2532
|
+
if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
|
2533
|
+
rb_warn("could not find defclass");
|
2534
|
+
return Qnil;
|
2535
|
+
}
|
2536
|
+
TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
|
2537
|
+
break;
|
2538
|
+
case T_DATA:
|
2539
|
+
TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
|
2540
|
+
break;
|
2541
|
+
default:
|
2542
|
+
rb_warn("defclass name must be a symbol or string");
|
2543
|
+
return Qnil;
|
2544
|
+
}
|
2545
|
+
for (
|
2546
|
+
theInstance = GetNextInstanceInClassAndSubclasses(&defclass,NULL,&iterator);
|
2547
|
+
theInstance != NULL;
|
2548
|
+
theInstance = GetNextInstanceInClassAndSubclasses(&defclass,theInstance,&iterator)
|
2549
|
+
) {
|
2550
|
+
rbInstance =
|
2551
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
|
2552
|
+
|
2553
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2554
|
+
rb_ary_push(returnArray, rbInstance);
|
2555
|
+
}
|
2556
|
+
// unexpected input of some kind...
|
2557
|
+
} else {
|
2558
|
+
rb_warn("unexpected arguments sent to get_instance_list!");
|
2559
|
+
return Qnil;
|
2560
|
+
}
|
2561
|
+
|
2562
|
+
return returnArray;
|
2563
|
+
}
|
2564
|
+
|
2565
|
+
static VALUE clips_environment_static_get_instance_list(int argc, VALUE *argv, VALUE klass) {
|
2566
|
+
VALUE rbEnvironment, rbDefclass_or_defclass_name, rbDefclass, include_subclasses, rbInstance, returnArray;
|
2567
|
+
Environment *env;
|
2568
|
+
Defclass *defclass;
|
2569
|
+
UDFValue iterator;
|
2570
|
+
Instance *theInstance;
|
2571
|
+
|
2572
|
+
returnArray = rb_ary_new2(0);
|
2573
|
+
|
2574
|
+
rb_scan_args(argc, argv, "12", &rbEnvironment, &rbDefclass_or_defclass_name, &include_subclasses);
|
2575
|
+
|
2576
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
2577
|
+
// defclass is undefined, ignore include_subclasses
|
2578
|
+
if (rbDefclass_or_defclass_name == Qnil) {
|
2579
|
+
for (
|
2580
|
+
theInstance = GetNextInstance(env,NULL);
|
2581
|
+
theInstance != NULL;
|
2582
|
+
theInstance = GetNextInstance(env,theInstance)
|
2583
|
+
) {
|
2584
|
+
rbInstance =
|
2585
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
|
2586
|
+
|
2587
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2588
|
+
rb_ary_push(returnArray, rbInstance);
|
2589
|
+
}
|
2590
|
+
} else if (include_subclasses != Qtrue) {
|
2591
|
+
switch (TYPE(rbDefclass_or_defclass_name)) {
|
2592
|
+
case T_STRING:
|
2593
|
+
case T_SYMBOL:
|
2594
|
+
if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
|
2595
|
+
rb_warn("could not find defclass");
|
2596
|
+
return Qnil;
|
2597
|
+
}
|
2598
|
+
TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
|
2599
|
+
break;
|
2600
|
+
case T_DATA:
|
2601
|
+
TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
|
2602
|
+
break;
|
2603
|
+
default:
|
2604
|
+
rb_warn("defclass name must be a symbol or string");
|
2605
|
+
return Qnil;
|
2606
|
+
}
|
2607
|
+
for (
|
2608
|
+
theInstance = GetNextInstanceInClass(defclass,NULL);
|
2609
|
+
theInstance != NULL;
|
2610
|
+
theInstance = GetNextInstanceInClass(defclass,theInstance)
|
2611
|
+
) {
|
2612
|
+
rbInstance =
|
2613
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
|
2614
|
+
|
2615
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2616
|
+
rb_ary_push(returnArray, rbInstance);
|
2617
|
+
}
|
2618
|
+
} else if (include_subclasses == Qtrue) {
|
2619
|
+
switch (TYPE(rbDefclass_or_defclass_name)) {
|
2620
|
+
case T_STRING:
|
2621
|
+
case T_SYMBOL:
|
2622
|
+
if (Qnil == (rbDefclass = clips_environment_find_defclass(rbEnvironment, rbDefclass_or_defclass_name))) {
|
2623
|
+
rb_warn("could not find defclass");
|
2624
|
+
return Qnil;
|
2625
|
+
}
|
2626
|
+
TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
|
2627
|
+
break;
|
2628
|
+
case T_DATA:
|
2629
|
+
TypedData_Get_Struct(rbDefclass_or_defclass_name, Defclass, &Defclass_type, defclass);
|
2630
|
+
break;
|
2631
|
+
default:
|
2632
|
+
rb_warn("defclass name must be a symbol or string");
|
2633
|
+
return Qnil;
|
2634
|
+
}
|
2635
|
+
for (
|
2636
|
+
theInstance = GetNextInstanceInClassAndSubclasses(&defclass,NULL,&iterator);
|
2637
|
+
theInstance != NULL;
|
2638
|
+
theInstance = GetNextInstanceInClassAndSubclasses(&defclass,theInstance,&iterator)
|
2639
|
+
) {
|
2640
|
+
rbInstance =
|
2641
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Instance")), &Instance_type, theInstance);
|
2642
|
+
|
2643
|
+
rb_iv_set(rbInstance, "@environment", rbEnvironment);
|
2644
|
+
rb_ary_push(returnArray, rbInstance);
|
2645
|
+
}
|
2646
|
+
// unexpected input of some kind...
|
2647
|
+
} else {
|
2648
|
+
rb_warn("unexpected arguments sent to get_instance_list!");
|
2649
|
+
return Qnil;
|
2650
|
+
}
|
2651
|
+
|
2652
|
+
return returnArray;
|
2653
|
+
}
|
2654
|
+
|
2162
2655
|
static VALUE clips_environment_get_deftemplate_list(int argc, VALUE *argv, VALUE rbEnvironment) {
|
2163
2656
|
VALUE defmodule_or_defmodule_name;
|
2164
2657
|
Environment *env;
|
@@ -3506,12 +3999,16 @@ void Init_clipsruby(void)
|
|
3506
3999
|
rb_define_method(rbEnvironment, "find_deftemplate", clips_environment_find_deftemplate, 1);
|
3507
4000
|
rb_define_singleton_method(rbEnvironment, "find_defclass", clips_environment_static_find_defclass, 2);
|
3508
4001
|
rb_define_method(rbEnvironment, "find_defclass", clips_environment_find_defclass, 1);
|
4002
|
+
rb_define_singleton_method(rbEnvironment, "find_instance", clips_environment_static_find_instance, -1);
|
4003
|
+
rb_define_method(rbEnvironment, "find_instance", clips_environment_find_instance, -1);
|
3509
4004
|
rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
|
3510
4005
|
rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
|
3511
4006
|
rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
|
3512
4007
|
rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
|
3513
4008
|
rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
|
3514
4009
|
rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
|
4010
|
+
rb_define_singleton_method(rbEnvironment, "get_instance_list", clips_environment_static_get_instance_list, -1);
|
4011
|
+
rb_define_method(rbEnvironment, "get_instance_list", clips_environment_get_instance_list, -1);
|
3515
4012
|
rb_define_singleton_method(rbEnvironment, "get_deftemplate_list", clips_environment_static_get_deftemplate_list, -1);
|
3516
4013
|
rb_define_method(rbEnvironment, "get_deftemplate_list", clips_environment_get_deftemplate_list, -1);
|
3517
4014
|
rb_define_singleton_method(rbEnvironment, "get_defclass_list", clips_environment_static_get_defclass_list, -1);
|
@@ -3649,6 +4146,8 @@ void Init_clipsruby(void)
|
|
3649
4146
|
rb_define_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_get_deftemplate_list, 0);
|
3650
4147
|
rb_define_singleton_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_static_get_defrule_list, 1);
|
3651
4148
|
rb_define_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_get_defrule_list, 0);
|
4149
|
+
rb_define_singleton_method(rbDefmodule, "find_instance", clips_environment_defmodule_static_find_instance, -1);
|
4150
|
+
rb_define_method(rbDefmodule, "find_instance", clips_environment_defmodule_find_instance, -1);
|
3652
4151
|
|
3653
4152
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
3654
4153
|
rb_define_alloc_func(rbFact, fact_alloc);
|
@@ -3700,6 +4199,8 @@ void Init_clipsruby(void)
|
|
3700
4199
|
rb_define_method(rbDefclass, "defmodule_name", clips_environment_defclass_defmodule_name, 0);
|
3701
4200
|
rb_define_singleton_method(rbDefclass, "pp_form", clips_environment_defclass_static_pp_form, 1);
|
3702
4201
|
rb_define_method(rbDefclass, "pp_form", clips_environment_defclass_pp_form, 0);
|
4202
|
+
rb_define_singleton_method(rbDefclass, "get_instance_list", clips_environment_defclass_static_get_instance_list, -1);
|
4203
|
+
rb_define_method(rbDefclass, "get_instance_list", clips_environment_defclass_get_instance_list, -1);
|
3703
4204
|
|
3704
4205
|
VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
|
3705
4206
|
rb_define_alloc_func(rbInstance, instance_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.
|
4
|
+
version: 0.0.35
|
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-
|
11
|
+
date: 2024-09-27 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
|