clipsruby 0.0.17 → 0.0.19
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 +66 -0
- data/ext/clipsruby/clipsruby.c +168 -1
- 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: c06b3f9f05fc87da93b208ba7f77de5097f964a689e2a9d1cdc8d8e0d992c826
|
4
|
+
data.tar.gz: 151dd0c82d9213a7ce971935513cbd9c16ab76bc08b123c7321ecfe1fa5cf985
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d545c65c3587d29c3b0a4fa12ffa6ecc030c242c472bcb5eb607014de3a03bd465defbe34fa4753e2594e55b2f5685f4111d8ab1c38b2467a9fa38256e31458c
|
7
|
+
data.tar.gz: c49a1fa673d5f680ee9c6fc2a38ed4dd4708cc996b8624f620e97d5161a5f533077542d7b0a4e788c4a6a4b9be49ad1bbf4307e769fde4cc537dde92905b8b86
|
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
|
|
@@ -266,6 +282,26 @@ CLIPS::Environment.facts(env)
|
|
266
282
|
env.facts
|
267
283
|
```
|
268
284
|
|
285
|
+
### `CLIPS::Environment.get_current_module`
|
286
|
+
### `CLIPS::Environment#get_current_module`
|
287
|
+
|
288
|
+
Get the current module in the CLIPS environment
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
CLIPS::Environment.get_current_module(env)
|
292
|
+
env.get_current_module
|
293
|
+
```
|
294
|
+
|
295
|
+
### `CLIPS::Environment.set_current_module`
|
296
|
+
### `CLIPS::Environment#set_current_module`
|
297
|
+
|
298
|
+
Set the current module in the CLIPS environment
|
299
|
+
|
300
|
+
```ruby
|
301
|
+
CLIPS::Environment.set_current_module(env, defmodule)
|
302
|
+
env.set_current_module(defmodule)
|
303
|
+
```
|
304
|
+
|
269
305
|
### `CLIPS::Environment::Fact.to_h`
|
270
306
|
### `CLIPS::Environment::Fact#to_h`
|
271
307
|
|
@@ -408,6 +444,16 @@ CLIPS::Environment::Defrule.remove_break(defrule)
|
|
408
444
|
defrule.remove_break
|
409
445
|
```
|
410
446
|
|
447
|
+
### `CLIPS::Environment.find_defmodule`
|
448
|
+
### `CLIPS::Environment#find_defmodule`
|
449
|
+
|
450
|
+
Finds a defmodule by name and returns a CLIPS::Environment::Defmodule object
|
451
|
+
|
452
|
+
```ruby
|
453
|
+
CLIPS::Environment.find_defmodule(:a)
|
454
|
+
env.find_defmodule("foo")
|
455
|
+
```
|
456
|
+
|
411
457
|
### `CLIPS::Environment::Defmodule.name`
|
412
458
|
### `CLIPS::Environment::Defmodule#name`
|
413
459
|
|
@@ -428,6 +474,26 @@ CLIPS::Environment::Defmodule.pp_form(defmodule)
|
|
428
474
|
defmodule.pp_form
|
429
475
|
```
|
430
476
|
|
477
|
+
### `CLIPS::Environment::Defmodule.set_current`
|
478
|
+
### `CLIPS::Environment::Defmodule#set_current`
|
479
|
+
|
480
|
+
Sets the Defmodule as the current module of the environment
|
481
|
+
|
482
|
+
```ruby
|
483
|
+
CLIPS::Environment::Defmodule.set_current(defmodule)
|
484
|
+
defmodule.set_current
|
485
|
+
```
|
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
|
+
|
431
497
|
## Running the tests
|
432
498
|
|
433
499
|
Simply do `rake compile` and then `rake test` in order to run the tests.
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -1238,6 +1238,47 @@ static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironme
|
|
1238
1238
|
return clips_environment_find_defrule(rbEnvironment, defrule_name);
|
1239
1239
|
}
|
1240
1240
|
|
1241
|
+
static VALUE clips_environment_get_current_module(VALUE self)
|
1242
|
+
{
|
1243
|
+
Environment *env;
|
1244
|
+
Defmodule *module;
|
1245
|
+
|
1246
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
1247
|
+
module = GetCurrentModule(env);
|
1248
|
+
|
1249
|
+
if (module == NULL) {
|
1250
|
+
return Qnil;
|
1251
|
+
} else {
|
1252
|
+
VALUE rbDefmodule;
|
1253
|
+
rbDefmodule = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Defmodule")), &Defmodule_type, module);
|
1254
|
+
rb_iv_set(rbDefmodule, "@environment", self);
|
1255
|
+
return rbDefmodule;
|
1256
|
+
}
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
static VALUE clips_environment_static_get_current_module(VALUE self, VALUE rbEnvironment)
|
1260
|
+
{
|
1261
|
+
return clips_environment_get_current_module(rbEnvironment);
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
static VALUE clips_environment_set_current_module(VALUE self, VALUE rbDefmodule)
|
1265
|
+
{
|
1266
|
+
Environment *env;
|
1267
|
+
Defmodule *module;
|
1268
|
+
|
1269
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
1270
|
+
TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, module);
|
1271
|
+
|
1272
|
+
SetCurrentModule(env, module);
|
1273
|
+
|
1274
|
+
return rbDefmodule;
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
static VALUE clips_environment_static_set_current_module(VALUE self, VALUE rbEnvironment, VALUE defmodule_name)
|
1278
|
+
{
|
1279
|
+
return clips_environment_set_current_module(rbEnvironment, defmodule_name);
|
1280
|
+
}
|
1281
|
+
|
1241
1282
|
static VALUE clips_environment_find_defmodule(VALUE self, VALUE defmodule_name)
|
1242
1283
|
{
|
1243
1284
|
Environment *env;
|
@@ -1260,7 +1301,10 @@ static VALUE clips_environment_find_defmodule(VALUE self, VALUE defmodule_name)
|
|
1260
1301
|
if (module == NULL) {
|
1261
1302
|
return Qnil;
|
1262
1303
|
} else {
|
1263
|
-
|
1304
|
+
VALUE rbDefmodule;
|
1305
|
+
rbDefmodule = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Defmodule")), &Defmodule_type, module);
|
1306
|
+
rb_iv_set(rbDefmodule, "@environment", self);
|
1307
|
+
return rbDefmodule;
|
1264
1308
|
}
|
1265
1309
|
}
|
1266
1310
|
|
@@ -1269,6 +1313,75 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
|
|
1269
1313
|
return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
|
1270
1314
|
}
|
1271
1315
|
|
1316
|
+
static VALUE clips_environment_get_fact_list(int argc, VALUE *argv, VALUE rbEnvironment) {
|
1317
|
+
VALUE defmodule_or_defmodule_name;
|
1318
|
+
Environment *env;
|
1319
|
+
Defmodule *module;
|
1320
|
+
CLIPSValue value;
|
1321
|
+
VALUE out;
|
1322
|
+
|
1323
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1324
|
+
|
1325
|
+
rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
|
1326
|
+
switch (TYPE(defmodule_or_defmodule_name)) {
|
1327
|
+
case T_NIL:
|
1328
|
+
module = NULL;
|
1329
|
+
break;
|
1330
|
+
case T_STRING:
|
1331
|
+
case T_SYMBOL:
|
1332
|
+
TypedData_Get_Struct(
|
1333
|
+
clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
|
1334
|
+
Defmodule, &Defmodule_type, module);
|
1335
|
+
break;
|
1336
|
+
case T_DATA:
|
1337
|
+
TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
|
1338
|
+
break;
|
1339
|
+
default:
|
1340
|
+
rb_warn("defmodule name must be a symbol or string");
|
1341
|
+
return Qnil;
|
1342
|
+
}
|
1343
|
+
GetFactList(env, &value, module);
|
1344
|
+
|
1345
|
+
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1346
|
+
|
1347
|
+
return out;
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE klass) {
|
1351
|
+
VALUE rbEnvironment, defmodule_or_defmodule_name;
|
1352
|
+
Environment *env;
|
1353
|
+
Defmodule *module;
|
1354
|
+
CLIPSValue value;
|
1355
|
+
VALUE out;
|
1356
|
+
|
1357
|
+
rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
|
1358
|
+
|
1359
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1360
|
+
switch (TYPE(defmodule_or_defmodule_name)) {
|
1361
|
+
case T_NIL:
|
1362
|
+
module = NULL;
|
1363
|
+
break;
|
1364
|
+
case T_STRING:
|
1365
|
+
case T_SYMBOL:
|
1366
|
+
TypedData_Get_Struct(
|
1367
|
+
clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
|
1368
|
+
Defmodule, &Defmodule_type, module);
|
1369
|
+
break;
|
1370
|
+
case T_DATA:
|
1371
|
+
TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
|
1372
|
+
break;
|
1373
|
+
default:
|
1374
|
+
rb_warn("defmodule name must be a symbol or string");
|
1375
|
+
return Qnil;
|
1376
|
+
}
|
1377
|
+
GetFactList(env, &value, module);
|
1378
|
+
|
1379
|
+
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1380
|
+
|
1381
|
+
return out;
|
1382
|
+
|
1383
|
+
}
|
1384
|
+
|
1272
1385
|
static VALUE clips_environment_defmodule_name(VALUE self)
|
1273
1386
|
{
|
1274
1387
|
Defmodule *defmodule;
|
@@ -1297,6 +1410,50 @@ static VALUE clips_environment_defmodule_static_pp_form(VALUE self, VALUE rbDefm
|
|
1297
1410
|
return clips_environment_defmodule_pp_form(rbDefmodule);
|
1298
1411
|
}
|
1299
1412
|
|
1413
|
+
static VALUE clips_environment_defmodule_set_current(VALUE self)
|
1414
|
+
{
|
1415
|
+
Defmodule *module;
|
1416
|
+
Environment *env;
|
1417
|
+
|
1418
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
1419
|
+
|
1420
|
+
TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
|
1421
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1422
|
+
|
1423
|
+
SetCurrentModule(env, module);
|
1424
|
+
|
1425
|
+
return self;
|
1426
|
+
}
|
1427
|
+
|
1428
|
+
static VALUE clips_environment_defmodule_static_set_current(VALUE self, VALUE rbDefmodule)
|
1429
|
+
{
|
1430
|
+
return clips_environment_defmodule_set_current(rbDefmodule);
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
static VALUE clips_environment_defmodule_get_fact_list(VALUE self)
|
1434
|
+
{
|
1435
|
+
Defmodule *module;
|
1436
|
+
Environment *env;
|
1437
|
+
CLIPSValue value;
|
1438
|
+
VALUE out;
|
1439
|
+
|
1440
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
1441
|
+
|
1442
|
+
TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
|
1443
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1444
|
+
|
1445
|
+
GetFactList(env, &value, module);
|
1446
|
+
|
1447
|
+
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1448
|
+
|
1449
|
+
return out;
|
1450
|
+
}
|
1451
|
+
|
1452
|
+
static VALUE clips_environment_defmodule_static_get_fact_list(VALUE self, VALUE rbDefmodule)
|
1453
|
+
{
|
1454
|
+
return clips_environment_defmodule_get_fact_list(rbDefmodule);
|
1455
|
+
}
|
1456
|
+
|
1300
1457
|
static VALUE clips_environment_defrule_name(VALUE self)
|
1301
1458
|
{
|
1302
1459
|
Defrule *defrule;
|
@@ -1446,6 +1603,12 @@ void Init_clipsruby(void)
|
|
1446
1603
|
rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
|
1447
1604
|
rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
|
1448
1605
|
rb_define_method(rbEnvironment, "find_defmodule", clips_environment_find_defmodule, 1);
|
1606
|
+
rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
|
1607
|
+
rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
|
1608
|
+
rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
|
1609
|
+
rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
|
1610
|
+
rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
|
1611
|
+
rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
|
1449
1612
|
|
1450
1613
|
VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
|
1451
1614
|
rb_define_alloc_func(rbDefmodule, defmodule_alloc);
|
@@ -1453,6 +1616,10 @@ void Init_clipsruby(void)
|
|
1453
1616
|
rb_define_method(rbDefmodule, "name", clips_environment_defmodule_name, 0);
|
1454
1617
|
rb_define_singleton_method(rbDefmodule, "pp_form", clips_environment_defmodule_static_pp_form, 1);
|
1455
1618
|
rb_define_method(rbDefmodule, "pp_form", clips_environment_defmodule_pp_form, 0);
|
1619
|
+
rb_define_singleton_method(rbDefmodule, "set_current", clips_environment_defmodule_static_set_current, 1);
|
1620
|
+
rb_define_method(rbDefmodule, "set_current", clips_environment_defmodule_set_current, 0);
|
1621
|
+
rb_define_singleton_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_static_get_fact_list, 1);
|
1622
|
+
rb_define_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_get_fact_list, 0);
|
1456
1623
|
|
1457
1624
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
1458
1625
|
rb_define_alloc_func(rbFact, fact_alloc);
|