clipsruby 0.0.18 → 0.0.20

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 +26 -0
  3. data/ext/clipsruby/clipsruby.c +185 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33891d80ffdc546c56d9cfa73c522f9b53ebbe666f21da00239aebb184d1f424
4
- data.tar.gz: 10fae8b4acc60835743bbb301e936c21ed96a989fdc90d8119313494d406d3f1
3
+ metadata.gz: ed56e2c48e4ab0971ac56242518c127aa04368c3e2d6d1102f734ce577d89a54
4
+ data.tar.gz: ca7df6a8e9eb6711ed51b14e3db1ee799e887fe0d5b90755705b14672c57bd57
5
5
  SHA512:
6
- metadata.gz: b212ee718009840bd627f666ec1cb16ea1732386dc3a3dc8bd12f39aac2ae24c9ccf207a0247e37298ba1411518c44bfb450cec70568c4db141bc0da6ddb8e28
7
- data.tar.gz: ebc27064ab0edd3113683de4d6b75889b12ed4b2522b3d1e2de7598223526caf67dba7199c3520d22c712bb5e821981d99904b0ba228e9ded9b5cdfd5417d678
6
+ metadata.gz: 2017fc2246a1869a5971e3cd6c9471e8903c1435e71cb0735c729d2e3165be97a6bc6d48373a2b9e4b3d1343854a5ebd681a70934b81a78c7a8654c65db9bbfd
7
+ data.tar.gz: 59734c2c151c11125d8c114f9aaae1b62f869969e272f3b97de7d37ba1c908b577c091fffe000c161484d5536795f20eab66f19cf53842c90bb969c58aa266cb
data/README.md CHANGED
@@ -168,6 +168,22 @@ CLIPS::Environment.find_fact(env, "(?f my_deftemplate)", "(eq ?f:b \"asdf\")")
168
168
  env.find_fact("(?f my_deftemplate)", "(= ?f:a 1)")
169
169
  ```
170
170
 
171
+ ### `CLIPS::Environment.get_fact_list`
172
+ ### `CLIPS::Environment#get_fact_list`
173
+
174
+ Return an array of Facts in the environment. Pass an argument of a
175
+ symbol, string, or Defmodule object in order to only get Facts with deftemplates
176
+ in that Defmodule. If you do not, it will return all Facts in all modules.
177
+
178
+ ```ruby
179
+ CLIPS::Environment.get_fact_list
180
+ env.get_fact_list
181
+ CLIPS::Environment.get_fact_list(:MAIN)
182
+ env.get_fact_list(:MAIN)
183
+ CLIPS::Environment.get_fact_list(defmodule)
184
+ env.get_fact_list(defmodule)
185
+ ```
186
+
171
187
  ### `CLIPS::Environment.find_all_facts`
172
188
  ### `CLIPS::Environment#find_all_facts`
173
189
 
@@ -468,6 +484,16 @@ CLIPS::Environment::Defmodule.set_current(defmodule)
468
484
  defmodule.set_current
469
485
  ```
470
486
 
487
+ ### `CLIPS::Environment::Defmodule.get_fact_list`
488
+ ### `CLIPS::Environment::Defmodule#get_fact_list`
489
+
490
+ Return an array of Facts with deftemplates in the Defmodule
491
+
492
+ ```ruby
493
+ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
494
+ defmodule.get_fact_list
495
+ ```
496
+
471
497
  ## Running the tests
472
498
 
473
499
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -1,6 +1,18 @@
1
1
  #include "clips.h"
2
2
  #include "ruby.h"
3
3
 
4
+ size_t deftemplate_size(const void *data)
5
+ {
6
+ return sizeof(Deftemplate);
7
+ }
8
+
9
+ static const rb_data_type_t Deftemplate_type = {
10
+ .function = {
11
+ .dsize = deftemplate_size
12
+ },
13
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
14
+ };
15
+
4
16
  size_t defmodule_size(const void *data)
5
17
  {
6
18
  return sizeof(Defmodule);
@@ -91,6 +103,11 @@ VALUE defmodule_alloc(VALUE self)
91
103
  return TypedData_Wrap_Struct(self, &Defmodule_type, NULL);
92
104
  }
93
105
 
106
+ VALUE deftemplate_alloc(VALUE self)
107
+ {
108
+ return TypedData_Wrap_Struct(self, &Deftemplate_type, NULL);
109
+ }
110
+
94
111
  VALUE defrule_alloc(VALUE self)
95
112
  {
96
113
  return TypedData_Wrap_Struct(self, &Defrule_type, NULL);
@@ -1313,6 +1330,137 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
1313
1330
  return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
1314
1331
  }
1315
1332
 
1333
+ static VALUE clips_environment_find_deftemplate(VALUE self, VALUE deftemplate_name)
1334
+ {
1335
+ Environment *env;
1336
+ Deftemplate *template;
1337
+
1338
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
1339
+
1340
+ switch (TYPE(deftemplate_name)) {
1341
+ case T_STRING:
1342
+ template = FindDeftemplate(env, StringValueCStr(deftemplate_name));
1343
+ break;
1344
+ case T_SYMBOL:
1345
+ template = FindDeftemplate(env, rb_id2name(SYM2ID(deftemplate_name)));
1346
+ break;
1347
+ default:
1348
+ rb_warn("deftemplate name must be a symbol or string");
1349
+ return Qnil;
1350
+ }
1351
+
1352
+ if (template == NULL) {
1353
+ return Qnil;
1354
+ } else {
1355
+ VALUE rbDeftemplate;
1356
+ rbDeftemplate = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deftemplate")), &Deftemplate_type, template);
1357
+ rb_iv_set(rbDeftemplate, "@environment", self);
1358
+ return rbDeftemplate;
1359
+ }
1360
+ }
1361
+
1362
+ static VALUE clips_environment_static_find_deftemplate(VALUE self, VALUE rbEnvironment, VALUE deftemplate_name)
1363
+ {
1364
+ return clips_environment_find_deftemplate(rbEnvironment, deftemplate_name);
1365
+ }
1366
+
1367
+ static VALUE clips_environment_deftemplate_name(VALUE self)
1368
+ {
1369
+ Deftemplate *deftemplate;
1370
+
1371
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
1372
+
1373
+ return ID2SYM(rb_intern(DeftemplateName(deftemplate)));
1374
+ }
1375
+
1376
+ static VALUE clips_environment_deftemplate_static_name(VALUE self, VALUE rbDeftemplate)
1377
+ {
1378
+ return clips_environment_deftemplate_name(rbDeftemplate);
1379
+ }
1380
+
1381
+ static VALUE clips_environment_deftemplate_pp_form(VALUE self)
1382
+ {
1383
+ Deftemplate *deftemplate;
1384
+
1385
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
1386
+
1387
+ return rb_str_new2(DeftemplatePPForm(deftemplate));
1388
+ }
1389
+
1390
+ static VALUE clips_environment_deftemplate_static_pp_form(VALUE self, VALUE rbDeftemplate)
1391
+ {
1392
+ return clips_environment_deftemplate_pp_form(rbDeftemplate);
1393
+ }
1394
+
1395
+ static VALUE clips_environment_get_fact_list(int argc, VALUE *argv, VALUE rbEnvironment) {
1396
+ VALUE defmodule_or_defmodule_name;
1397
+ Environment *env;
1398
+ Defmodule *module;
1399
+ CLIPSValue value;
1400
+ VALUE out;
1401
+
1402
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1403
+
1404
+ rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
1405
+ switch (TYPE(defmodule_or_defmodule_name)) {
1406
+ case T_NIL:
1407
+ module = NULL;
1408
+ break;
1409
+ case T_STRING:
1410
+ case T_SYMBOL:
1411
+ TypedData_Get_Struct(
1412
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1413
+ Defmodule, &Defmodule_type, module);
1414
+ break;
1415
+ case T_DATA:
1416
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1417
+ break;
1418
+ default:
1419
+ rb_warn("defmodule name must be a symbol or string");
1420
+ return Qnil;
1421
+ }
1422
+ GetFactList(env, &value, module);
1423
+
1424
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1425
+
1426
+ return out;
1427
+ }
1428
+
1429
+ static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE klass) {
1430
+ VALUE rbEnvironment, defmodule_or_defmodule_name;
1431
+ Environment *env;
1432
+ Defmodule *module;
1433
+ CLIPSValue value;
1434
+ VALUE out;
1435
+
1436
+ rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
1437
+
1438
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1439
+ switch (TYPE(defmodule_or_defmodule_name)) {
1440
+ case T_NIL:
1441
+ module = NULL;
1442
+ break;
1443
+ case T_STRING:
1444
+ case T_SYMBOL:
1445
+ TypedData_Get_Struct(
1446
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1447
+ Defmodule, &Defmodule_type, module);
1448
+ break;
1449
+ case T_DATA:
1450
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1451
+ break;
1452
+ default:
1453
+ rb_warn("defmodule name must be a symbol or string");
1454
+ return Qnil;
1455
+ }
1456
+ GetFactList(env, &value, module);
1457
+
1458
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1459
+
1460
+ return out;
1461
+
1462
+ }
1463
+
1316
1464
  static VALUE clips_environment_defmodule_name(VALUE self)
1317
1465
  {
1318
1466
  Defmodule *defmodule;
@@ -1361,6 +1509,30 @@ static VALUE clips_environment_defmodule_static_set_current(VALUE self, VALUE rb
1361
1509
  return clips_environment_defmodule_set_current(rbDefmodule);
1362
1510
  }
1363
1511
 
1512
+ static VALUE clips_environment_defmodule_get_fact_list(VALUE self)
1513
+ {
1514
+ Defmodule *module;
1515
+ Environment *env;
1516
+ CLIPSValue value;
1517
+ VALUE out;
1518
+
1519
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
1520
+
1521
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
1522
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1523
+
1524
+ GetFactList(env, &value, module);
1525
+
1526
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1527
+
1528
+ return out;
1529
+ }
1530
+
1531
+ static VALUE clips_environment_defmodule_static_get_fact_list(VALUE self, VALUE rbDefmodule)
1532
+ {
1533
+ return clips_environment_defmodule_get_fact_list(rbDefmodule);
1534
+ }
1535
+
1364
1536
  static VALUE clips_environment_defrule_name(VALUE self)
1365
1537
  {
1366
1538
  Defrule *defrule;
@@ -1510,10 +1682,21 @@ void Init_clipsruby(void)
1510
1682
  rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
1511
1683
  rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
1512
1684
  rb_define_method(rbEnvironment, "find_defmodule", clips_environment_find_defmodule, 1);
1685
+ rb_define_singleton_method(rbEnvironment, "find_deftemplate", clips_environment_static_find_deftemplate, 2);
1686
+ rb_define_method(rbEnvironment, "find_deftemplate", clips_environment_find_deftemplate, 1);
1513
1687
  rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
1514
1688
  rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
1515
1689
  rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
1516
1690
  rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
1691
+ rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
1692
+ rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
1693
+
1694
+ VALUE rbDeftemplate = rb_define_class_under(rbEnvironment, "Deftemplate", rb_cObject);
1695
+ rb_define_alloc_func(rbDeftemplate, deftemplate_alloc);
1696
+ rb_define_singleton_method(rbDeftemplate, "name", clips_environment_deftemplate_static_name, 1);
1697
+ rb_define_method(rbDeftemplate, "name", clips_environment_deftemplate_name, 0);
1698
+ rb_define_singleton_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_static_pp_form, 1);
1699
+ rb_define_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_pp_form, 0);
1517
1700
 
1518
1701
  VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
1519
1702
  rb_define_alloc_func(rbDefmodule, defmodule_alloc);
@@ -1523,6 +1706,8 @@ void Init_clipsruby(void)
1523
1706
  rb_define_method(rbDefmodule, "pp_form", clips_environment_defmodule_pp_form, 0);
1524
1707
  rb_define_singleton_method(rbDefmodule, "set_current", clips_environment_defmodule_static_set_current, 1);
1525
1708
  rb_define_method(rbDefmodule, "set_current", clips_environment_defmodule_set_current, 0);
1709
+ rb_define_singleton_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_static_get_fact_list, 1);
1710
+ rb_define_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_get_fact_list, 0);
1526
1711
 
1527
1712
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
1528
1713
  rb_define_alloc_func(rbFact, fact_alloc);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston