clipsruby 0.0.38 → 0.0.40

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 +116 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d5b2eff6dfde994a41ed4226415ed61cc22f4a60164ca7f0adb14f2913ed831
4
- data.tar.gz: 18f6b5748632239dac343f0b91b41620a2973699e27a9d52a2aef28bde921a0c
3
+ metadata.gz: f9f5ef0ebbc5224f3c9ee6ab3bc3a025e543ec210aea37062d6eb7a8389424e6
4
+ data.tar.gz: d850a5303be6baca4514d9ed7de5061efacad449666fa56e80a15c7c29dd6e67
5
5
  SHA512:
6
- metadata.gz: 634dd08bc164e971d4484e18a2fadc51a56e7b7976994b3cfb3bad903445157da9b6bc1ef4dc424faacef0a68217f774c6c3ec9f9fd717c3d579df04d0e6525e
7
- data.tar.gz: b31052a98c2238d3d97bf6938193202ca6b05333286e61500000da33dd4baaeddc915b5bd53c53cf989c366bcc51d5469428632766ad625e616249f9eb996655
6
+ metadata.gz: 282703a59de83937e2afafb3bf66b315cc5bf0175d87ffb7eba3f3e34e831fbc7ebd8f764f64b430062d1cec587c3e4ce12248d5e6417b24b139d126be9a90d0
7
+ data.tar.gz: afaaf02eca5132f0092cec3665e0a4820b4e9517f04bda680f8c15cef85f8cdbcc2fd80a3dc752a103f220c11d270a26299b4a6c8121356394dc284df81842cf
data/README.md CHANGED
@@ -464,6 +464,19 @@ CLIPS::Environment::Instance.defclass(instance)
464
464
  instance.defclass
465
465
  ```
466
466
 
467
+ ### `CLIPS::Environment::Instance.to_h`
468
+ ### `CLIPS::Environment::Instance#to_h`
469
+
470
+ Returns a hash representing the instance slot names and their values.
471
+ Pass a `true` as an argument to get inhereted slots as well.
472
+
473
+ ```ruby
474
+ CLIPS::Environment::Instance.to_h(instance)
475
+ instance.to_h
476
+ CLIPS::Environment::Instance.to_h(instance, true)
477
+ instance.to_h(true)
478
+ ```
479
+
467
480
  ### `CLIPS::Environment::Defclass.name`
468
481
  ### `CLIPS::Environment::Defclass#name`
469
482
 
@@ -484,6 +497,19 @@ CLIPS::Environment::Defclass.pp_form(defclass)
484
497
  defclass.pp_form
485
498
  ```
486
499
 
500
+ ### `CLIPS::Environment::Defclass.slots`
501
+ ### `CLIPS::Environment::Defclass#slots`
502
+
503
+ Returns an array representing the slot names of a Defclass.
504
+ Pass `true` as an argument to get inherited slots, as well.
505
+
506
+ ```ruby
507
+ CLIPS::Environment::Defclass.slots(defclass)
508
+ defclass.slots
509
+ CLIPS::Environment::Defclass.slots(defclass, true)
510
+ defclass.slots(true)
511
+ ```
512
+
487
513
  ### `CLIPS::Environment::Defclass.defmodule_name`
488
514
  ### `CLIPS::Environment::Defclass#defmodule_name`
489
515
 
@@ -1266,10 +1266,6 @@ static VALUE clips_environment_defclass_subclasses(int argc, VALUE *argv, VALUE
1266
1266
 
1267
1267
  rb_scan_args(argc, argv, "01", &inherit);
1268
1268
 
1269
- if (NIL_P(inherit)) {
1270
- inherit = Qfalse;
1271
- }
1272
-
1273
1269
  TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1274
1270
 
1275
1271
  ClassSubclasses(defclass, &value, RTEST(inherit));
@@ -1299,6 +1295,46 @@ static VALUE clips_environment_defclass_static_subclasses(int argc, VALUE *argv,
1299
1295
  return out;
1300
1296
  }
1301
1297
 
1298
+ static VALUE clips_environment_defclass_slots(int argc, VALUE *argv, VALUE rbDefclass)
1299
+ {
1300
+ VALUE rbEnvironment, inherit;
1301
+ Defclass *defclass;
1302
+ CLIPSValue value;
1303
+ VALUE out;
1304
+
1305
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1306
+
1307
+ rb_scan_args(argc, argv, "01", &inherit);
1308
+
1309
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1310
+
1311
+ ClassSlots(defclass, &value, RTEST(inherit));
1312
+
1313
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1314
+
1315
+ return out;
1316
+ }
1317
+
1318
+ static VALUE clips_environment_defclass_static_slots(int argc, VALUE *argv, VALUE klass)
1319
+ {
1320
+ VALUE rbEnvironment, inherit, rbDefclass;
1321
+ Defclass *defclass;
1322
+ CLIPSValue value;
1323
+ VALUE out;
1324
+
1325
+ rb_scan_args(argc, argv, "11", &rbDefclass, &inherit);
1326
+
1327
+ TypedData_Get_Struct(rbDefclass, Defclass, &Defclass_type, defclass);
1328
+
1329
+ rbEnvironment = rb_iv_get(rbDefclass, "@environment");
1330
+
1331
+ ClassSlots(defclass, &value, RTEST(inherit));
1332
+
1333
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1334
+
1335
+ return out;
1336
+ }
1337
+
1302
1338
  static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) {
1303
1339
  VALUE integer;
1304
1340
  Environment *env;
@@ -1436,6 +1472,57 @@ static VALUE clips_environment_fact_static_to_h(VALUE self, VALUE rbFact)
1436
1472
  return clips_environment_fact_to_h(rbFact);
1437
1473
  }
1438
1474
 
1475
+ static VALUE clips_environment_instance_to_h(int argc, VALUE *argv, VALUE rbInstance)
1476
+ {
1477
+ VALUE rbEnvironment, inherit;
1478
+ Instance *instance;
1479
+ CLIPSValue key, value;
1480
+ rbEnvironment = rb_iv_get(rbInstance, "@environment");
1481
+
1482
+ TypedData_Get_Struct(rbInstance, Instance, &Instance_type, instance);
1483
+
1484
+ rb_scan_args(argc, argv, "01", &inherit);
1485
+
1486
+ ClassSlots(InstanceClass(instance), &key, RTEST(inherit));
1487
+
1488
+ VALUE hash = rb_hash_new();
1489
+ for (size_t i = 0; i < key.multifieldValue->length; i++)
1490
+ {
1491
+ VALUE innerValue;
1492
+ DirectGetSlot(instance, key.multifieldValue->contents[i].lexemeValue->contents, &value);
1493
+ CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
1494
+ rb_hash_aset(hash, ID2SYM(rb_intern(key.multifieldValue->contents[i].lexemeValue->contents)), innerValue);
1495
+ }
1496
+
1497
+ return hash;
1498
+ }
1499
+
1500
+ static VALUE clips_environment_instance_static_to_h(int argc, VALUE *argv, VALUE klass)
1501
+ {
1502
+ VALUE rbInstance, rbEnvironment, inherit;
1503
+ Instance *instance;
1504
+ CLIPSValue key, value;
1505
+
1506
+ rb_scan_args(argc, argv, "11", &rbInstance, &inherit);
1507
+
1508
+ rbEnvironment = rb_iv_get(rbInstance, "@environment");
1509
+
1510
+ TypedData_Get_Struct(rbInstance, Instance, &Instance_type, instance);
1511
+
1512
+ ClassSlots(InstanceClass(instance), &key, RTEST(inherit));
1513
+
1514
+ VALUE hash = rb_hash_new();
1515
+ for (size_t i = 0; i < key.multifieldValue->length; i++)
1516
+ {
1517
+ VALUE innerValue;
1518
+ DirectGetSlot(instance, key.multifieldValue->contents[i].lexemeValue->contents, &value);
1519
+ CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
1520
+ rb_hash_aset(hash, ID2SYM(rb_intern(key.multifieldValue->contents[i].lexemeValue->contents)), innerValue);
1521
+ }
1522
+
1523
+ return hash;
1524
+ }
1525
+
1439
1526
  static VALUE clips_environment_batch_star(VALUE self, VALUE path)
1440
1527
  {
1441
1528
  Environment *env;
@@ -2122,10 +2209,16 @@ static VALUE clips_environment_deffacts_static_name(VALUE self, VALUE rbDeffacts
2122
2209
  static VALUE clips_environment_deffacts_pp_form(VALUE self)
2123
2210
  {
2124
2211
  Deffacts *deffacts;
2212
+ const char *pp_form;
2125
2213
 
2126
2214
  TypedData_Get_Struct(self, Deffacts, &Deffacts_type, deffacts);
2127
2215
 
2128
- return rb_str_new2(DeffactsPPForm(deffacts));
2216
+ pp_form = DeffactsPPForm(deffacts);
2217
+ if (pp_form == NULL) {
2218
+ return Qnil;
2219
+ } else {
2220
+ return rb_str_new2(pp_form);
2221
+ }
2129
2222
  }
2130
2223
 
2131
2224
  static VALUE clips_environment_deffacts_static_pp_form(VALUE self, VALUE rbDeffacts)
@@ -2510,10 +2603,16 @@ static VALUE clips_environment_deftemplate_static_name(VALUE self, VALUE rbDefte
2510
2603
  static VALUE clips_environment_deftemplate_pp_form(VALUE self)
2511
2604
  {
2512
2605
  Deftemplate *deftemplate;
2606
+ const char *pp_form;
2513
2607
 
2514
2608
  TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
2515
2609
 
2516
- return rb_str_new2(DeftemplatePPForm(deftemplate));
2610
+ pp_form = DeftemplatePPForm(deftemplate);
2611
+ if (pp_form == NULL) {
2612
+ return Qnil;
2613
+ } else {
2614
+ return rb_str_new2(pp_form);
2615
+ }
2517
2616
  }
2518
2617
 
2519
2618
  static VALUE clips_environment_deftemplate_static_pp_form(VALUE self, VALUE rbDeftemplate)
@@ -3060,10 +3159,16 @@ static VALUE clips_environment_defmodule_static_name(VALUE self, VALUE rbDefmodu
3060
3159
  static VALUE clips_environment_defmodule_pp_form(VALUE self)
3061
3160
  {
3062
3161
  Defmodule *defmodule;
3162
+ const char *pp_form;
3063
3163
 
3064
3164
  TypedData_Get_Struct(self, Defmodule, &Defmodule_type, defmodule);
3065
3165
 
3066
- return rb_str_new2(DefmodulePPForm(defmodule));
3166
+ pp_form = DefmodulePPForm(defmodule);
3167
+ if (pp_form == NULL) {
3168
+ return Qnil;
3169
+ } else {
3170
+ return rb_str_new2(pp_form);
3171
+ }
3067
3172
  }
3068
3173
 
3069
3174
  static VALUE clips_environment_defmodule_static_pp_form(VALUE self, VALUE rbDefmodule)
@@ -4398,6 +4503,8 @@ void Init_clipsruby(void)
4398
4503
  rb_define_method(rbDefclass, "superclasses", clips_environment_defclass_superclasses, -1);
4399
4504
  rb_define_singleton_method(rbDefclass, "subclasses", clips_environment_defclass_static_subclasses, -1);
4400
4505
  rb_define_method(rbDefclass, "subclasses", clips_environment_defclass_subclasses, -1);
4506
+ rb_define_singleton_method(rbDefclass, "slots", clips_environment_defclass_static_slots, -1);
4507
+ rb_define_method(rbDefclass, "slots", clips_environment_defclass_slots, -1);
4401
4508
 
4402
4509
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
4403
4510
  rb_define_alloc_func(rbInstance, instance_alloc);
@@ -4411,4 +4518,6 @@ void Init_clipsruby(void)
4411
4518
  rb_define_method(rbInstance, "name", clips_environment_instance_name, 0);
4412
4519
  rb_define_singleton_method(rbInstance, "pp_form", clips_environment_instance_static_pp_form, 1);
4413
4520
  rb_define_method(rbInstance, "pp_form", clips_environment_instance_pp_form, 0);
4521
+ rb_define_singleton_method(rbInstance, "to_h", clips_environment_instance_static_to_h, -1);
4522
+ rb_define_method(rbInstance, "to_h", clips_environment_instance_to_h, -1);
4414
4523
  }
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.38
4
+ version: 0.0.40
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-29 00:00:00.000000000 Z
11
+ date: 2024-09-30 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