clipsruby 0.0.19 → 0.0.21
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 +71 -1
- data/ext/clipsruby/clipsruby.c +227 -0
- 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: 7e26c6a3eb9602ca2ab8d3aa497b95b19d404640fa281aac5544310a01040b62
|
4
|
+
data.tar.gz: 56000c5e564e43d907daf53fd0476113448e0a27377b36ad41cd1a04202f1c03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a7ec9525ec36621cba6fb7c75bb89f2406dcdb13237b478e2a98b2d9b7af202b79fae1e65779fc48b1ab89ef490a66cb68343c48144cb8d857fab3c4a1eaaf4
|
7
|
+
data.tar.gz: 5d45dcb799e1c829f76d5f20a41b05817f9d0a57ab7d72827b45b871a38755f9f695fd5fb9d62a1c899fe83b993a29cd42870b194a651b92461ac846d67bde04
|
data/README.md
CHANGED
@@ -162,7 +162,7 @@ A light wrapper around the CLIPS find-fact function. Accepts a fact set template
|
|
162
162
|
returns the first Facts in the environment that match as Ruby objects.
|
163
163
|
|
164
164
|
```ruby
|
165
|
-
CLIPS::Environment.
|
165
|
+
CLIPS::Environment.find_fact(env, "(?f my_deftemplate)")
|
166
166
|
env.find_fact("(?f my_deftemplate)")
|
167
167
|
CLIPS::Environment.find_fact(env, "(?f my_deftemplate)", "(eq ?f:b \"asdf\")")
|
168
168
|
env.find_fact("(?f my_deftemplate)", "(= ?f:a 1)")
|
@@ -302,6 +302,16 @@ CLIPS::Environment.set_current_module(env, defmodule)
|
|
302
302
|
env.set_current_module(defmodule)
|
303
303
|
```
|
304
304
|
|
305
|
+
### `CLIPS::Environment::Fact.pp_form`
|
306
|
+
### `CLIPS::Environment::Fact#pp_form`
|
307
|
+
|
308
|
+
Returns a pretty printed string representation of the Fact
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
CLIPS::Environment::Fact.pp_form(fact)
|
312
|
+
fact.pp_form
|
313
|
+
```
|
314
|
+
|
305
315
|
### `CLIPS::Environment::Fact.to_h`
|
306
316
|
### `CLIPS::Environment::Fact#to_h`
|
307
317
|
|
@@ -494,6 +504,66 @@ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
|
|
494
504
|
defmodule.get_fact_list
|
495
505
|
```
|
496
506
|
|
507
|
+
### `CLIPS::Environment.find_deftemplate`
|
508
|
+
### `CLIPS::Environment#find_deftemplate`
|
509
|
+
|
510
|
+
Finds a deftemplate by name and returns a CLIPS::Environment::Deftemplate object
|
511
|
+
|
512
|
+
```ruby
|
513
|
+
CLIPS::Environment.find_deftemplate(:a)
|
514
|
+
env.find_deftemplate("foo")
|
515
|
+
```
|
516
|
+
|
517
|
+
### `CLIPS::Environment::Deftemplate.name`
|
518
|
+
### `CLIPS::Environment::Deftemplate#name`
|
519
|
+
|
520
|
+
Returns the name of a deftemplate as a symbol
|
521
|
+
|
522
|
+
```ruby
|
523
|
+
CLIPS::Environment::Deftemplate.name(deftemplate)
|
524
|
+
deftemplate.name
|
525
|
+
```
|
526
|
+
|
527
|
+
### `CLIPS::Environment::Deftemplate.pp_form`
|
528
|
+
### `CLIPS::Environment::Deftemplate#pp_form`
|
529
|
+
|
530
|
+
Returns a pretty printed string representation of the Deftemplate
|
531
|
+
|
532
|
+
```ruby
|
533
|
+
CLIPS::Environment::Deftemplate.pp_form(deftemplate)
|
534
|
+
deftemplate.pp_form
|
535
|
+
```
|
536
|
+
|
537
|
+
### `CLIPS::Environment.find_deffacts`
|
538
|
+
### `CLIPS::Environment#find_deffacts`
|
539
|
+
|
540
|
+
Finds a deffacts by name and returns a CLIPS::Environment::Deffacts object
|
541
|
+
|
542
|
+
```ruby
|
543
|
+
CLIPS::Environment.find_deffacts(:a)
|
544
|
+
env.find_deffacts("foo")
|
545
|
+
```
|
546
|
+
|
547
|
+
### `CLIPS::Environment::Deffacts.name`
|
548
|
+
### `CLIPS::Environment::Deffacts#name`
|
549
|
+
|
550
|
+
Returns the name of a deffacts as a symbol
|
551
|
+
|
552
|
+
```ruby
|
553
|
+
CLIPS::Environment::Deffacts.name(deffacts)
|
554
|
+
deffacts.name
|
555
|
+
```
|
556
|
+
|
557
|
+
### `CLIPS::Environment::Deffacts.pp_form`
|
558
|
+
### `CLIPS::Environment::Deffacts#pp_form`
|
559
|
+
|
560
|
+
Returns a pretty printed string representation of the Deffacts
|
561
|
+
|
562
|
+
```ruby
|
563
|
+
CLIPS::Environment::Deffacts.pp_form(deffacts)
|
564
|
+
deffacts.pp_form
|
565
|
+
```
|
566
|
+
|
497
567
|
## Running the tests
|
498
568
|
|
499
569
|
Simply do `rake compile` and then `rake test` in order to run the tests.
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
#include "clips.h"
|
2
2
|
#include "ruby.h"
|
3
3
|
|
4
|
+
size_t deffacts_size(const void *data)
|
5
|
+
{
|
6
|
+
return sizeof(Deffacts);
|
7
|
+
}
|
8
|
+
|
9
|
+
static const rb_data_type_t Deffacts_type = {
|
10
|
+
.function = {
|
11
|
+
.dsize = deffacts_size
|
12
|
+
},
|
13
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
14
|
+
};
|
15
|
+
|
16
|
+
size_t deftemplate_size(const void *data)
|
17
|
+
{
|
18
|
+
return sizeof(Deftemplate);
|
19
|
+
}
|
20
|
+
|
21
|
+
static const rb_data_type_t Deftemplate_type = {
|
22
|
+
.function = {
|
23
|
+
.dsize = deftemplate_size
|
24
|
+
},
|
25
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
26
|
+
};
|
27
|
+
|
4
28
|
size_t defmodule_size(const void *data)
|
5
29
|
{
|
6
30
|
return sizeof(Defmodule);
|
@@ -91,6 +115,16 @@ VALUE defmodule_alloc(VALUE self)
|
|
91
115
|
return TypedData_Wrap_Struct(self, &Defmodule_type, NULL);
|
92
116
|
}
|
93
117
|
|
118
|
+
VALUE deffacts_alloc(VALUE self)
|
119
|
+
{
|
120
|
+
return TypedData_Wrap_Struct(self, &Deffacts_type, NULL);
|
121
|
+
}
|
122
|
+
|
123
|
+
VALUE deftemplate_alloc(VALUE self)
|
124
|
+
{
|
125
|
+
return TypedData_Wrap_Struct(self, &Deftemplate_type, NULL);
|
126
|
+
}
|
127
|
+
|
94
128
|
VALUE defrule_alloc(VALUE self)
|
95
129
|
{
|
96
130
|
return TypedData_Wrap_Struct(self, &Defrule_type, NULL);
|
@@ -1238,6 +1272,65 @@ static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironme
|
|
1238
1272
|
return clips_environment_find_defrule(rbEnvironment, defrule_name);
|
1239
1273
|
}
|
1240
1274
|
|
1275
|
+
static VALUE clips_environment_find_deffacts(VALUE self, VALUE deffacts_name)
|
1276
|
+
{
|
1277
|
+
Environment *env;
|
1278
|
+
Deffacts *deffacts;
|
1279
|
+
|
1280
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
1281
|
+
|
1282
|
+
switch (TYPE(deffacts_name)) {
|
1283
|
+
case T_STRING:
|
1284
|
+
deffacts = FindDeffacts(env, StringValueCStr(deffacts_name));
|
1285
|
+
break;
|
1286
|
+
case T_SYMBOL:
|
1287
|
+
deffacts = FindDeffacts(env, rb_id2name(SYM2ID(deffacts_name)));
|
1288
|
+
break;
|
1289
|
+
default:
|
1290
|
+
rb_warn("deffacts name must be a symbol or string");
|
1291
|
+
return Qnil;
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
if (deffacts == NULL) {
|
1295
|
+
return Qnil;
|
1296
|
+
} else {
|
1297
|
+
return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deffacts")), &Deffacts_type, deffacts);
|
1298
|
+
}
|
1299
|
+
}
|
1300
|
+
|
1301
|
+
static VALUE clips_environment_static_find_deffacts(VALUE self, VALUE rbEnvironment, VALUE deffacts_name)
|
1302
|
+
{
|
1303
|
+
return clips_environment_find_deffacts(rbEnvironment, deffacts_name);
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
static VALUE clips_environment_deffacts_name(VALUE self)
|
1307
|
+
{
|
1308
|
+
Deffacts *deffacts;
|
1309
|
+
|
1310
|
+
TypedData_Get_Struct(self, Deffacts, &Deffacts_type, deffacts);
|
1311
|
+
|
1312
|
+
return ID2SYM(rb_intern(DeffactsName(deffacts)));
|
1313
|
+
}
|
1314
|
+
|
1315
|
+
static VALUE clips_environment_deffacts_static_name(VALUE self, VALUE rbDeffacts)
|
1316
|
+
{
|
1317
|
+
return clips_environment_deffacts_name(rbDeffacts);
|
1318
|
+
}
|
1319
|
+
|
1320
|
+
static VALUE clips_environment_deffacts_pp_form(VALUE self)
|
1321
|
+
{
|
1322
|
+
Deffacts *deffacts;
|
1323
|
+
|
1324
|
+
TypedData_Get_Struct(self, Deffacts, &Deffacts_type, deffacts);
|
1325
|
+
|
1326
|
+
return rb_str_new2(DeffactsPPForm(deffacts));
|
1327
|
+
}
|
1328
|
+
|
1329
|
+
static VALUE clips_environment_deffacts_static_pp_form(VALUE self, VALUE rbDeffacts)
|
1330
|
+
{
|
1331
|
+
return clips_environment_deffacts_pp_form(rbDeffacts);
|
1332
|
+
}
|
1333
|
+
|
1241
1334
|
static VALUE clips_environment_get_current_module(VALUE self)
|
1242
1335
|
{
|
1243
1336
|
Environment *env;
|
@@ -1313,6 +1406,120 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
|
|
1313
1406
|
return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
|
1314
1407
|
}
|
1315
1408
|
|
1409
|
+
static VALUE clips_environment_find_deftemplate(VALUE self, VALUE deftemplate_name)
|
1410
|
+
{
|
1411
|
+
Environment *env;
|
1412
|
+
Deftemplate *template;
|
1413
|
+
|
1414
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
1415
|
+
|
1416
|
+
switch (TYPE(deftemplate_name)) {
|
1417
|
+
case T_STRING:
|
1418
|
+
template = FindDeftemplate(env, StringValueCStr(deftemplate_name));
|
1419
|
+
break;
|
1420
|
+
case T_SYMBOL:
|
1421
|
+
template = FindDeftemplate(env, rb_id2name(SYM2ID(deftemplate_name)));
|
1422
|
+
break;
|
1423
|
+
default:
|
1424
|
+
rb_warn("deftemplate name must be a symbol or string");
|
1425
|
+
return Qnil;
|
1426
|
+
}
|
1427
|
+
|
1428
|
+
if (template == NULL) {
|
1429
|
+
return Qnil;
|
1430
|
+
} else {
|
1431
|
+
VALUE rbDeftemplate;
|
1432
|
+
rbDeftemplate = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deftemplate")), &Deftemplate_type, template);
|
1433
|
+
rb_iv_set(rbDeftemplate, "@environment", self);
|
1434
|
+
return rbDeftemplate;
|
1435
|
+
}
|
1436
|
+
}
|
1437
|
+
|
1438
|
+
static VALUE clips_environment_static_find_deftemplate(VALUE self, VALUE rbEnvironment, VALUE deftemplate_name)
|
1439
|
+
{
|
1440
|
+
return clips_environment_find_deftemplate(rbEnvironment, deftemplate_name);
|
1441
|
+
}
|
1442
|
+
|
1443
|
+
static VALUE clips_environment_deftemplate_name(VALUE self)
|
1444
|
+
{
|
1445
|
+
Deftemplate *deftemplate;
|
1446
|
+
|
1447
|
+
TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
|
1448
|
+
|
1449
|
+
return ID2SYM(rb_intern(DeftemplateName(deftemplate)));
|
1450
|
+
}
|
1451
|
+
|
1452
|
+
static VALUE clips_environment_deftemplate_static_name(VALUE self, VALUE rbDeftemplate)
|
1453
|
+
{
|
1454
|
+
return clips_environment_deftemplate_name(rbDeftemplate);
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
static VALUE clips_environment_deftemplate_pp_form(VALUE self)
|
1458
|
+
{
|
1459
|
+
Deftemplate *deftemplate;
|
1460
|
+
|
1461
|
+
TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
|
1462
|
+
|
1463
|
+
return rb_str_new2(DeftemplatePPForm(deftemplate));
|
1464
|
+
}
|
1465
|
+
|
1466
|
+
static VALUE clips_environment_deftemplate_static_pp_form(VALUE self, VALUE rbDeftemplate)
|
1467
|
+
{
|
1468
|
+
return clips_environment_deftemplate_pp_form(rbDeftemplate);
|
1469
|
+
}
|
1470
|
+
|
1471
|
+
static VALUE clips_environment_fact_pp_form(int argc, VALUE *argv, VALUE self)
|
1472
|
+
{
|
1473
|
+
Fact *fact;
|
1474
|
+
VALUE ignore_defaults, toReturn;
|
1475
|
+
Environment *env;
|
1476
|
+
|
1477
|
+
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
1478
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
1479
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1480
|
+
StringBuilder *sb = CreateStringBuilder(env, 0);
|
1481
|
+
|
1482
|
+
rb_scan_args(argc, argv, "01", &ignore_defaults);
|
1483
|
+
|
1484
|
+
if (ignore_defaults == Qtrue) {
|
1485
|
+
FactPPForm(fact, sb, true);
|
1486
|
+
} else {
|
1487
|
+
FactPPForm(fact, sb, false);
|
1488
|
+
}
|
1489
|
+
|
1490
|
+
toReturn = rb_str_new2(sb->contents);
|
1491
|
+
|
1492
|
+
SBDispose(sb);
|
1493
|
+
|
1494
|
+
return toReturn;
|
1495
|
+
}
|
1496
|
+
|
1497
|
+
static VALUE clips_environment_fact_static_pp_form(int argc, VALUE *argv, VALUE klass)
|
1498
|
+
{
|
1499
|
+
Fact *fact;
|
1500
|
+
VALUE self, ignore_defaults, toReturn;
|
1501
|
+
Environment *env;
|
1502
|
+
|
1503
|
+
rb_scan_args(argc, argv, "11", &self, &ignore_defaults);
|
1504
|
+
|
1505
|
+
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
1506
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
1507
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1508
|
+
StringBuilder *sb = CreateStringBuilder(env, 0);
|
1509
|
+
|
1510
|
+
if (ignore_defaults == Qtrue) {
|
1511
|
+
FactPPForm(fact, sb, true);
|
1512
|
+
} else {
|
1513
|
+
FactPPForm(fact, sb, false);
|
1514
|
+
}
|
1515
|
+
|
1516
|
+
toReturn = rb_str_new2(sb->contents);
|
1517
|
+
|
1518
|
+
SBDispose(sb);
|
1519
|
+
|
1520
|
+
return toReturn;
|
1521
|
+
}
|
1522
|
+
|
1316
1523
|
static VALUE clips_environment_get_fact_list(int argc, VALUE *argv, VALUE rbEnvironment) {
|
1317
1524
|
VALUE defmodule_or_defmodule_name;
|
1318
1525
|
Environment *env;
|
@@ -1603,12 +1810,30 @@ void Init_clipsruby(void)
|
|
1603
1810
|
rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
|
1604
1811
|
rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
|
1605
1812
|
rb_define_method(rbEnvironment, "find_defmodule", clips_environment_find_defmodule, 1);
|
1813
|
+
rb_define_singleton_method(rbEnvironment, "find_deftemplate", clips_environment_static_find_deftemplate, 2);
|
1814
|
+
rb_define_method(rbEnvironment, "find_deftemplate", clips_environment_find_deftemplate, 1);
|
1606
1815
|
rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
|
1607
1816
|
rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
|
1608
1817
|
rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
|
1609
1818
|
rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
|
1610
1819
|
rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
|
1611
1820
|
rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
|
1821
|
+
rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
|
1822
|
+
rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
|
1823
|
+
|
1824
|
+
VALUE rbDeffacts = rb_define_class_under(rbEnvironment, "Deffacts", rb_cObject);
|
1825
|
+
rb_define_alloc_func(rbDeffacts, deffacts_alloc);
|
1826
|
+
rb_define_singleton_method(rbDeffacts, "name", clips_environment_deffacts_static_name, 1);
|
1827
|
+
rb_define_method(rbDeffacts, "name", clips_environment_deffacts_name, 0);
|
1828
|
+
rb_define_singleton_method(rbDeffacts, "pp_form", clips_environment_deffacts_static_pp_form, 1);
|
1829
|
+
rb_define_method(rbDeffacts, "pp_form", clips_environment_deffacts_pp_form, 0);
|
1830
|
+
|
1831
|
+
VALUE rbDeftemplate = rb_define_class_under(rbEnvironment, "Deftemplate", rb_cObject);
|
1832
|
+
rb_define_alloc_func(rbDeftemplate, deftemplate_alloc);
|
1833
|
+
rb_define_singleton_method(rbDeftemplate, "name", clips_environment_deftemplate_static_name, 1);
|
1834
|
+
rb_define_method(rbDeftemplate, "name", clips_environment_deftemplate_name, 0);
|
1835
|
+
rb_define_singleton_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_static_pp_form, 1);
|
1836
|
+
rb_define_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_pp_form, 0);
|
1612
1837
|
|
1613
1838
|
VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
|
1614
1839
|
rb_define_alloc_func(rbDefmodule, defmodule_alloc);
|
@@ -1637,6 +1862,8 @@ void Init_clipsruby(void)
|
|
1637
1862
|
rb_define_method(rbFact, "modify", clips_environment_fact_modify, 1);
|
1638
1863
|
rb_define_singleton_method(rbFact, "index", clips_environment_fact_static_index, 1);
|
1639
1864
|
rb_define_method(rbFact, "index", clips_environment_fact_index, 0);
|
1865
|
+
rb_define_singleton_method(rbFact, "pp_form", clips_environment_fact_static_pp_form, -1);
|
1866
|
+
rb_define_method(rbFact, "pp_form", clips_environment_fact_pp_form, -1);
|
1640
1867
|
|
1641
1868
|
VALUE rbDefrule = rb_define_class_under(rbEnvironment, "Defrule", rb_cObject);
|
1642
1869
|
rb_define_alloc_func(rbDefrule, defrule_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.21
|
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-11 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
|