clipsruby 0.0.16 → 0.0.17
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 +20 -0
- data/ext/clipsruby/clipsruby.c +98 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de97045f9a1a8a525b3749c820e21addf2bdbf4edbfefc3fd6d02e4d611560bc
|
4
|
+
data.tar.gz: d364bf452cf66ca60d9acc12d794fdc25ed613ef2db5c5af194a982b9beff1e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ed356daccf5a65e12ee6ac3c516efcf6035852eb70a4aab2a2b619ffc7a78c7dfba99c7c5d49bc7127b76ff5c6432e2709bbcc7b196160d55329411abbd892e
|
7
|
+
data.tar.gz: 99712624df319cf372755ada70bf503d5bd99a8a4bb336d3da8968fae9669b4482065259ebf337dc43b8820b9207e3afb08e80c88f43cb62b6bc90077b64113c
|
data/README.md
CHANGED
@@ -408,6 +408,26 @@ CLIPS::Environment::Defrule.remove_break(defrule)
|
|
408
408
|
defrule.remove_break
|
409
409
|
```
|
410
410
|
|
411
|
+
### `CLIPS::Environment::Defmodule.name`
|
412
|
+
### `CLIPS::Environment::Defmodule#name`
|
413
|
+
|
414
|
+
Returns the name of a defmodule as a symbol
|
415
|
+
|
416
|
+
```ruby
|
417
|
+
CLIPS::Environment::Defmodule.name(defmodule)
|
418
|
+
defmodule.name
|
419
|
+
```
|
420
|
+
|
421
|
+
### `CLIPS::Environment::Defmodule.pp_form`
|
422
|
+
### `CLIPS::Environment::Defmodule#pp_form`
|
423
|
+
|
424
|
+
Returns a pretty printed string representation of the Defmodule
|
425
|
+
|
426
|
+
```ruby
|
427
|
+
CLIPS::Environment::Defmodule.pp_form(defmodule)
|
428
|
+
defmodule.pp_form
|
429
|
+
```
|
430
|
+
|
411
431
|
## Running the tests
|
412
432
|
|
413
433
|
Simply do `rake compile` and then `rake test` in order to run the tests.
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
#include "clips.h"
|
2
2
|
#include "ruby.h"
|
3
3
|
|
4
|
+
size_t defmodule_size(const void *data)
|
5
|
+
{
|
6
|
+
return sizeof(Defmodule);
|
7
|
+
}
|
8
|
+
|
9
|
+
static const rb_data_type_t Defmodule_type = {
|
10
|
+
.function = {
|
11
|
+
.dsize = defmodule_size
|
12
|
+
},
|
13
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
14
|
+
};
|
15
|
+
|
16
|
+
|
4
17
|
size_t defrule_size(const void *data)
|
5
18
|
{
|
6
19
|
return sizeof(Defrule);
|
@@ -73,6 +86,21 @@ static VALUE clips_environment_static_facts(VALUE self, VALUE rbEnvironment)
|
|
73
86
|
return clips_environment_facts(rbEnvironment);
|
74
87
|
}
|
75
88
|
|
89
|
+
VALUE defmodule_alloc(VALUE self)
|
90
|
+
{
|
91
|
+
return TypedData_Wrap_Struct(self, &Defmodule_type, NULL);
|
92
|
+
}
|
93
|
+
|
94
|
+
VALUE defrule_alloc(VALUE self)
|
95
|
+
{
|
96
|
+
return TypedData_Wrap_Struct(self, &Defrule_type, NULL);
|
97
|
+
}
|
98
|
+
|
99
|
+
VALUE fact_alloc(VALUE self)
|
100
|
+
{
|
101
|
+
return TypedData_Wrap_Struct(self, &Fact_type, NULL);
|
102
|
+
}
|
103
|
+
|
76
104
|
VALUE environment_alloc(VALUE self)
|
77
105
|
{
|
78
106
|
return TypedData_Wrap_Struct(self, &Environment_type, CreateEnvironment());
|
@@ -1210,6 +1238,65 @@ static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironme
|
|
1210
1238
|
return clips_environment_find_defrule(rbEnvironment, defrule_name);
|
1211
1239
|
}
|
1212
1240
|
|
1241
|
+
static VALUE clips_environment_find_defmodule(VALUE self, VALUE defmodule_name)
|
1242
|
+
{
|
1243
|
+
Environment *env;
|
1244
|
+
Defmodule *module;
|
1245
|
+
|
1246
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
1247
|
+
|
1248
|
+
switch (TYPE(defmodule_name)) {
|
1249
|
+
case T_STRING:
|
1250
|
+
module = FindDefmodule(env, StringValueCStr(defmodule_name));
|
1251
|
+
break;
|
1252
|
+
case T_SYMBOL:
|
1253
|
+
module = FindDefmodule(env, rb_id2name(SYM2ID(defmodule_name)));
|
1254
|
+
break;
|
1255
|
+
default:
|
1256
|
+
rb_warn("defmodule name must be a symbol or string");
|
1257
|
+
return Qnil;
|
1258
|
+
}
|
1259
|
+
|
1260
|
+
if (module == NULL) {
|
1261
|
+
return Qnil;
|
1262
|
+
} else {
|
1263
|
+
return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Defmodule")), &Defmodule_type, module);
|
1264
|
+
}
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnvironment, VALUE defmodule_name)
|
1268
|
+
{
|
1269
|
+
return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
|
1270
|
+
}
|
1271
|
+
|
1272
|
+
static VALUE clips_environment_defmodule_name(VALUE self)
|
1273
|
+
{
|
1274
|
+
Defmodule *defmodule;
|
1275
|
+
|
1276
|
+
TypedData_Get_Struct(self, Defmodule, &Defmodule_type, defmodule);
|
1277
|
+
|
1278
|
+
return ID2SYM(rb_intern(DefmoduleName(defmodule)));
|
1279
|
+
}
|
1280
|
+
|
1281
|
+
static VALUE clips_environment_defmodule_static_name(VALUE self, VALUE rbDefmodule)
|
1282
|
+
{
|
1283
|
+
return clips_environment_defmodule_name(rbDefmodule);
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
static VALUE clips_environment_defmodule_pp_form(VALUE self)
|
1287
|
+
{
|
1288
|
+
Defmodule *defmodule;
|
1289
|
+
|
1290
|
+
TypedData_Get_Struct(self, Defmodule, &Defmodule_type, defmodule);
|
1291
|
+
|
1292
|
+
return rb_str_new2(DefmodulePPForm(defmodule));
|
1293
|
+
}
|
1294
|
+
|
1295
|
+
static VALUE clips_environment_defmodule_static_pp_form(VALUE self, VALUE rbDefmodule)
|
1296
|
+
{
|
1297
|
+
return clips_environment_defmodule_pp_form(rbDefmodule);
|
1298
|
+
}
|
1299
|
+
|
1213
1300
|
static VALUE clips_environment_defrule_name(VALUE self)
|
1214
1301
|
{
|
1215
1302
|
Defrule *defrule;
|
@@ -1357,8 +1444,18 @@ void Init_clipsruby(void)
|
|
1357
1444
|
rb_define_method(rbEnvironment, "bload_facts", clips_environment_bload_facts, 1);
|
1358
1445
|
rb_define_singleton_method(rbEnvironment, "find_defrule", clips_environment_static_find_defrule, 2);
|
1359
1446
|
rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
|
1447
|
+
rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
|
1448
|
+
rb_define_method(rbEnvironment, "find_defmodule", clips_environment_find_defmodule, 1);
|
1449
|
+
|
1450
|
+
VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
|
1451
|
+
rb_define_alloc_func(rbDefmodule, defmodule_alloc);
|
1452
|
+
rb_define_singleton_method(rbDefmodule, "name", clips_environment_defmodule_static_name, 1);
|
1453
|
+
rb_define_method(rbDefmodule, "name", clips_environment_defmodule_name, 0);
|
1454
|
+
rb_define_singleton_method(rbDefmodule, "pp_form", clips_environment_defmodule_static_pp_form, 1);
|
1455
|
+
rb_define_method(rbDefmodule, "pp_form", clips_environment_defmodule_pp_form, 0);
|
1360
1456
|
|
1361
1457
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
1458
|
+
rb_define_alloc_func(rbFact, fact_alloc);
|
1362
1459
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
1363
1460
|
rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
|
1364
1461
|
rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
|
@@ -1375,6 +1472,7 @@ void Init_clipsruby(void)
|
|
1375
1472
|
rb_define_method(rbFact, "index", clips_environment_fact_index, 0);
|
1376
1473
|
|
1377
1474
|
VALUE rbDefrule = rb_define_class_under(rbEnvironment, "Defrule", rb_cObject);
|
1475
|
+
rb_define_alloc_func(rbDefrule, defrule_alloc);
|
1378
1476
|
rb_define_singleton_method(rbDefrule, "name", clips_environment_defrule_static_name, 1);
|
1379
1477
|
rb_define_method(rbDefrule, "name", clips_environment_defrule_name, 0);
|
1380
1478
|
rb_define_singleton_method(rbDefrule, "pp_form", clips_environment_defrule_static_pp_form, 1);
|