clipsruby 0.0.14 → 0.0.16
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 +82 -12
- data/ext/clipsruby/clipsruby.c +156 -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: 4d5b7a59f7219254864351b91605797ae234e16e608d59233703143c7abf54dc
|
4
|
+
data.tar.gz: fcb8917ac24d4bb0168c95b4349377d264a13683aeba0ab7fab6f319267da7a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 443bbd98d165934e83653355a59441aec19aab844a3d381ce604d1701ea3229215459112aa91e4704d6c4bc7a16d1df181c7a21b5f6539d4ef5b7f3bf531d0e0
|
7
|
+
data.tar.gz: '090a1fa0c36b3e13070d5bab7fd0f572342dc737c13fcf6d877aff2730bddd5166ed88b8f2f1894680b93b6620f2bec684f43c2187065b6da020dc5717b2334e'
|
data/README.md
CHANGED
@@ -45,8 +45,8 @@ env.batch_star("./my-batch.bat")
|
|
45
45
|
Pass the path in which we'll save the environment constructs.
|
46
46
|
|
47
47
|
```ruby
|
48
|
-
CLIPS::Environment.save(env, "./my-save.
|
49
|
-
env.save("./my-save.
|
48
|
+
CLIPS::Environment.save(env, "./my-save.clp")
|
49
|
+
env.save("./my-save.clp")
|
50
50
|
```
|
51
51
|
|
52
52
|
### `CLIPS::Environment.load`
|
@@ -56,8 +56,8 @@ Pass the path to a file that will load the constructs stored in the file
|
|
56
56
|
into the environment. Remember to `reset` the environment if you need.
|
57
57
|
|
58
58
|
```ruby
|
59
|
-
CLIPS::Environment.load(env, "./my-load.
|
60
|
-
env.load("./my-load.
|
59
|
+
CLIPS::Environment.load(env, "./my-load.clp")
|
60
|
+
env.load("./my-load.clp")
|
61
61
|
```
|
62
62
|
|
63
63
|
### `CLIPS::Environment.save_facts`
|
@@ -68,12 +68,12 @@ The third argument is optional, and determines whether to store the visible or l
|
|
68
68
|
By default, it'll store local.
|
69
69
|
|
70
70
|
```ruby
|
71
|
-
CLIPS::Environment.save_facts(env, "./my-save-facts.
|
72
|
-
env.save_facts("./my-save-facts.
|
73
|
-
CLIPS::Environment.save_facts(env, "./my-save-facts.
|
74
|
-
env.save_facts("./my-save-facts.
|
75
|
-
CLIPS::Environment.save_facts(env, "./my-save-facts.
|
76
|
-
env.save_facts("./my-save-facts.
|
71
|
+
CLIPS::Environment.save_facts(env, "./my-save-facts.clp")
|
72
|
+
env.save_facts("./my-save-facts.clp")
|
73
|
+
CLIPS::Environment.save_facts(env, "./my-save-facts.clp", :local)
|
74
|
+
env.save_facts("./my-save-facts.clp", :local)
|
75
|
+
CLIPS::Environment.save_facts(env, "./my-save-facts.clp", :visible)
|
76
|
+
env.save_facts("./my-save-facts.clp", :visible)
|
77
77
|
```
|
78
78
|
|
79
79
|
### `CLIPS::Environment.load_facts`
|
@@ -83,8 +83,8 @@ Pass the path to a file that will load the facts stored in the file
|
|
83
83
|
into the environment.
|
84
84
|
|
85
85
|
```ruby
|
86
|
-
CLIPS::Environment.load_facts(env, "./my-load-facts.
|
87
|
-
env.load_facts("./my-load-facts.
|
86
|
+
CLIPS::Environment.load_facts(env, "./my-load-facts.clp")
|
87
|
+
env.load_facts("./my-load-facts.clp")
|
88
88
|
```
|
89
89
|
|
90
90
|
### `CLIPS::Environment.bsave`
|
@@ -338,6 +338,76 @@ CLIPS::Environment::Fact.modify(fact, bar: 123)
|
|
338
338
|
fact.modify(foo: "my new foo!")
|
339
339
|
```
|
340
340
|
|
341
|
+
### `CLIPS::Environment.find_defrule`
|
342
|
+
### `CLIPS::Environment#find_defrule`
|
343
|
+
|
344
|
+
Finds a defrule by name and returns a CLIPS::Environment::Defrule object
|
345
|
+
|
346
|
+
```ruby
|
347
|
+
CLIPS::Environment.find_defrule(:a)
|
348
|
+
env.find_defrule("foo")
|
349
|
+
```
|
350
|
+
|
351
|
+
### `CLIPS::Environment::Defrule.name`
|
352
|
+
### `CLIPS::Environment::Defrule#name`
|
353
|
+
|
354
|
+
Returns the name of a defrule as a symbol
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
CLIPS::Environment::Defrule.name(defrule)
|
358
|
+
defrule.name
|
359
|
+
```
|
360
|
+
|
361
|
+
### `CLIPS::Environment::Defrule.is_deletable`
|
362
|
+
### `CLIPS::Environment::Defrule#is_deletable`
|
363
|
+
|
364
|
+
Returns a boolean whether the Defrule is deletable or not
|
365
|
+
|
366
|
+
```ruby
|
367
|
+
CLIPS::Environment::Defrule.is_deletable(defrule)
|
368
|
+
defrule.is_deletable
|
369
|
+
```
|
370
|
+
|
371
|
+
### `CLIPS::Environment::Defrule.pp_form`
|
372
|
+
### `CLIPS::Environment::Defrule#pp_form`
|
373
|
+
|
374
|
+
Returns a pretty printed string representation of the Defrule
|
375
|
+
|
376
|
+
```ruby
|
377
|
+
CLIPS::Environment::Defrule.pp_form(defrule)
|
378
|
+
defrule.pp_form
|
379
|
+
```
|
380
|
+
|
381
|
+
### `CLIPS::Environment::Defrule.has_breakpoint`
|
382
|
+
### `CLIPS::Environment::Defrule#has_breakpoint`
|
383
|
+
|
384
|
+
Returns whether or not the rule has a breakpoint set
|
385
|
+
|
386
|
+
```ruby
|
387
|
+
CLIPS::Environment::Defrule.has_breakpoint(defrule)
|
388
|
+
defrule.has_breakpoint
|
389
|
+
```
|
390
|
+
|
391
|
+
### `CLIPS::Environment::Defrule.set_break`
|
392
|
+
### `CLIPS::Environment::Defrule#set_break`
|
393
|
+
|
394
|
+
Sets a breakpoint on a rule
|
395
|
+
|
396
|
+
```ruby
|
397
|
+
CLIPS::Environment::Defrule.set_break(defrule)
|
398
|
+
defrule.set_break
|
399
|
+
```
|
400
|
+
|
401
|
+
### `CLIPS::Environment::Defrule.remove_break`
|
402
|
+
### `CLIPS::Environment::Defrule#remove_break`
|
403
|
+
|
404
|
+
Returns whether or not it was able to remove a breakpoint from a rule
|
405
|
+
|
406
|
+
```ruby
|
407
|
+
CLIPS::Environment::Defrule.remove_break(defrule)
|
408
|
+
defrule.remove_break
|
409
|
+
```
|
410
|
+
|
341
411
|
## Running the tests
|
342
412
|
|
343
413
|
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 defrule_size(const void *data)
|
5
|
+
{
|
6
|
+
return sizeof(Defrule);
|
7
|
+
}
|
8
|
+
|
9
|
+
static const rb_data_type_t Defrule_type = {
|
10
|
+
.function = {
|
11
|
+
.dsize = defrule_size
|
12
|
+
},
|
13
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
14
|
+
};
|
15
|
+
|
4
16
|
size_t fact_size(const void *data)
|
5
17
|
{
|
6
18
|
return sizeof(Fact);
|
@@ -1167,6 +1179,134 @@ static VALUE clips_environment_fact_static_index(VALUE self, VALUE rbFact)
|
|
1167
1179
|
return clips_environment_fact_index(rbFact);
|
1168
1180
|
}
|
1169
1181
|
|
1182
|
+
static VALUE clips_environment_find_defrule(VALUE self, VALUE defrule_name)
|
1183
|
+
{
|
1184
|
+
Environment *env;
|
1185
|
+
Defrule *rule;
|
1186
|
+
|
1187
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
1188
|
+
|
1189
|
+
switch (TYPE(defrule_name)) {
|
1190
|
+
case T_STRING:
|
1191
|
+
rule = FindDefrule(env, StringValueCStr(defrule_name));
|
1192
|
+
break;
|
1193
|
+
case T_SYMBOL:
|
1194
|
+
rule = FindDefrule(env, rb_id2name(SYM2ID(defrule_name)));
|
1195
|
+
break;
|
1196
|
+
default:
|
1197
|
+
rb_warn("defrule name must be a symbol or string");
|
1198
|
+
return Qnil;
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
if (rule == NULL) {
|
1202
|
+
return Qnil;
|
1203
|
+
} else {
|
1204
|
+
return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Defrule")), &Defrule_type, rule);
|
1205
|
+
}
|
1206
|
+
}
|
1207
|
+
|
1208
|
+
static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironment, VALUE defrule_name)
|
1209
|
+
{
|
1210
|
+
return clips_environment_find_defrule(rbEnvironment, defrule_name);
|
1211
|
+
}
|
1212
|
+
|
1213
|
+
static VALUE clips_environment_defrule_name(VALUE self)
|
1214
|
+
{
|
1215
|
+
Defrule *defrule;
|
1216
|
+
|
1217
|
+
TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
|
1218
|
+
|
1219
|
+
return ID2SYM(rb_intern(DefruleName(defrule)));
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
static VALUE clips_environment_defrule_static_name(VALUE self, VALUE rbDefrule)
|
1223
|
+
{
|
1224
|
+
return clips_environment_defrule_name(rbDefrule);
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
static VALUE clips_environment_defrule_pp_form(VALUE self)
|
1228
|
+
{
|
1229
|
+
Defrule *defrule;
|
1230
|
+
|
1231
|
+
TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
|
1232
|
+
|
1233
|
+
return rb_str_new2(DefrulePPForm(defrule));
|
1234
|
+
}
|
1235
|
+
|
1236
|
+
static VALUE clips_environment_defrule_static_pp_form(VALUE self, VALUE rbDefrule)
|
1237
|
+
{
|
1238
|
+
return clips_environment_defrule_pp_form(rbDefrule);
|
1239
|
+
}
|
1240
|
+
|
1241
|
+
static VALUE clips_environment_defrule_is_deletable(VALUE self)
|
1242
|
+
{
|
1243
|
+
Defrule *defrule;
|
1244
|
+
|
1245
|
+
TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
|
1246
|
+
|
1247
|
+
if (DefruleIsDeletable(defrule)) {
|
1248
|
+
return Qtrue;
|
1249
|
+
} else {
|
1250
|
+
return Qfalse;
|
1251
|
+
}
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
static VALUE clips_environment_defrule_static_is_deletable(VALUE self, VALUE rbDefrule)
|
1255
|
+
{
|
1256
|
+
return clips_environment_defrule_is_deletable(rbDefrule);
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
static VALUE clips_environment_defrule_has_breakpoint(VALUE self)
|
1260
|
+
{
|
1261
|
+
Defrule *defrule;
|
1262
|
+
|
1263
|
+
TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
|
1264
|
+
|
1265
|
+
if (DefruleHasBreakpoint(defrule)) {
|
1266
|
+
return Qtrue;
|
1267
|
+
} else {
|
1268
|
+
return Qfalse;
|
1269
|
+
}
|
1270
|
+
}
|
1271
|
+
|
1272
|
+
static VALUE clips_environment_defrule_static_has_breakpoint(VALUE self, VALUE rbDefrule)
|
1273
|
+
{
|
1274
|
+
return clips_environment_defrule_has_breakpoint(rbDefrule);
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
static VALUE clips_environment_defrule_set_break(VALUE self)
|
1278
|
+
{
|
1279
|
+
Defrule *defrule;
|
1280
|
+
|
1281
|
+
TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
|
1282
|
+
|
1283
|
+
SetBreak(defrule);
|
1284
|
+
|
1285
|
+
return Qnil;
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
static VALUE clips_environment_defrule_static_set_break(VALUE self, VALUE rbDefrule)
|
1289
|
+
{
|
1290
|
+
return clips_environment_defrule_set_break(rbDefrule);
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
static VALUE clips_environment_defrule_remove_break(VALUE self)
|
1294
|
+
{
|
1295
|
+
Defrule *defrule;
|
1296
|
+
|
1297
|
+
TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
|
1298
|
+
|
1299
|
+
if (RemoveBreak(defrule)) {
|
1300
|
+
return Qtrue;
|
1301
|
+
} else {
|
1302
|
+
return Qfalse;
|
1303
|
+
}
|
1304
|
+
}
|
1305
|
+
|
1306
|
+
static VALUE clips_environment_defrule_static_remove_break(VALUE self, VALUE rbDefrule)
|
1307
|
+
{
|
1308
|
+
return clips_environment_defrule_remove_break(rbDefrule);
|
1309
|
+
}
|
1170
1310
|
|
1171
1311
|
void Init_clipsruby(void)
|
1172
1312
|
{
|
@@ -1215,6 +1355,8 @@ void Init_clipsruby(void)
|
|
1215
1355
|
rb_define_method(rbEnvironment, "bsave_facts", clips_environment_bsave_facts, -1);
|
1216
1356
|
rb_define_singleton_method(rbEnvironment, "bload_facts", clips_environment_static_bload_facts, 2);
|
1217
1357
|
rb_define_method(rbEnvironment, "bload_facts", clips_environment_bload_facts, 1);
|
1358
|
+
rb_define_singleton_method(rbEnvironment, "find_defrule", clips_environment_static_find_defrule, 2);
|
1359
|
+
rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
|
1218
1360
|
|
1219
1361
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
1220
1362
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
@@ -1232,5 +1374,19 @@ void Init_clipsruby(void)
|
|
1232
1374
|
rb_define_singleton_method(rbFact, "index", clips_environment_fact_static_index, 1);
|
1233
1375
|
rb_define_method(rbFact, "index", clips_environment_fact_index, 0);
|
1234
1376
|
|
1377
|
+
VALUE rbDefrule = rb_define_class_under(rbEnvironment, "Defrule", rb_cObject);
|
1378
|
+
rb_define_singleton_method(rbDefrule, "name", clips_environment_defrule_static_name, 1);
|
1379
|
+
rb_define_method(rbDefrule, "name", clips_environment_defrule_name, 0);
|
1380
|
+
rb_define_singleton_method(rbDefrule, "pp_form", clips_environment_defrule_static_pp_form, 1);
|
1381
|
+
rb_define_method(rbDefrule, "pp_form", clips_environment_defrule_pp_form, 0);
|
1382
|
+
rb_define_singleton_method(rbDefrule, "is_deletable", clips_environment_defrule_static_is_deletable, 1);
|
1383
|
+
rb_define_method(rbDefrule, "is_deletable", clips_environment_defrule_is_deletable, 0);
|
1384
|
+
rb_define_singleton_method(rbDefrule, "has_breakpoint", clips_environment_defrule_static_has_breakpoint, 1);
|
1385
|
+
rb_define_method(rbDefrule, "has_breakpoint", clips_environment_defrule_has_breakpoint, 0);
|
1386
|
+
rb_define_singleton_method(rbDefrule, "set_break", clips_environment_defrule_static_set_break, 1);
|
1387
|
+
rb_define_method(rbDefrule, "set_break", clips_environment_defrule_set_break, 0);
|
1388
|
+
rb_define_singleton_method(rbDefrule, "remove_break", clips_environment_defrule_static_remove_break, 1);
|
1389
|
+
rb_define_method(rbDefrule, "remove_break", clips_environment_defrule_remove_break, 0);
|
1390
|
+
|
1235
1391
|
VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
|
1236
1392
|
}
|
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.16
|
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-10 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
|