clipsruby 0.0.20 → 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 +139 -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,18 @@
|
|
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
|
+
|
4
16
|
size_t deftemplate_size(const void *data)
|
5
17
|
{
|
6
18
|
return sizeof(Deftemplate);
|
@@ -103,6 +115,11 @@ VALUE defmodule_alloc(VALUE self)
|
|
103
115
|
return TypedData_Wrap_Struct(self, &Defmodule_type, NULL);
|
104
116
|
}
|
105
117
|
|
118
|
+
VALUE deffacts_alloc(VALUE self)
|
119
|
+
{
|
120
|
+
return TypedData_Wrap_Struct(self, &Deffacts_type, NULL);
|
121
|
+
}
|
122
|
+
|
106
123
|
VALUE deftemplate_alloc(VALUE self)
|
107
124
|
{
|
108
125
|
return TypedData_Wrap_Struct(self, &Deftemplate_type, NULL);
|
@@ -1255,6 +1272,65 @@ static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironme
|
|
1255
1272
|
return clips_environment_find_defrule(rbEnvironment, defrule_name);
|
1256
1273
|
}
|
1257
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
|
+
|
1258
1334
|
static VALUE clips_environment_get_current_module(VALUE self)
|
1259
1335
|
{
|
1260
1336
|
Environment *env;
|
@@ -1392,6 +1468,58 @@ static VALUE clips_environment_deftemplate_static_pp_form(VALUE self, VALUE rbDe
|
|
1392
1468
|
return clips_environment_deftemplate_pp_form(rbDeftemplate);
|
1393
1469
|
}
|
1394
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
|
+
|
1395
1523
|
static VALUE clips_environment_get_fact_list(int argc, VALUE *argv, VALUE rbEnvironment) {
|
1396
1524
|
VALUE defmodule_or_defmodule_name;
|
1397
1525
|
Environment *env;
|
@@ -1690,6 +1818,15 @@ void Init_clipsruby(void)
|
|
1690
1818
|
rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
|
1691
1819
|
rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
|
1692
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);
|
1693
1830
|
|
1694
1831
|
VALUE rbDeftemplate = rb_define_class_under(rbEnvironment, "Deftemplate", rb_cObject);
|
1695
1832
|
rb_define_alloc_func(rbDeftemplate, deftemplate_alloc);
|
@@ -1725,6 +1862,8 @@ void Init_clipsruby(void)
|
|
1725
1862
|
rb_define_method(rbFact, "modify", clips_environment_fact_modify, 1);
|
1726
1863
|
rb_define_singleton_method(rbFact, "index", clips_environment_fact_static_index, 1);
|
1727
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);
|
1728
1867
|
|
1729
1868
|
VALUE rbDefrule = rb_define_class_under(rbEnvironment, "Defrule", rb_cObject);
|
1730
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
|