clipsruby 0.0.16 → 0.0.18

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -0
  3. data/ext/clipsruby/clipsruby.c +168 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d5b7a59f7219254864351b91605797ae234e16e608d59233703143c7abf54dc
4
- data.tar.gz: fcb8917ac24d4bb0168c95b4349377d264a13683aeba0ab7fab6f319267da7a4
3
+ metadata.gz: 33891d80ffdc546c56d9cfa73c522f9b53ebbe666f21da00239aebb184d1f424
4
+ data.tar.gz: 10fae8b4acc60835743bbb301e936c21ed96a989fdc90d8119313494d406d3f1
5
5
  SHA512:
6
- metadata.gz: 443bbd98d165934e83653355a59441aec19aab844a3d381ce604d1701ea3229215459112aa91e4704d6c4bc7a16d1df181c7a21b5f6539d4ef5b7f3bf531d0e0
7
- data.tar.gz: '090a1fa0c36b3e13070d5bab7fd0f572342dc737c13fcf6d877aff2730bddd5166ed88b8f2f1894680b93b6620f2bec684f43c2187065b6da020dc5717b2334e'
6
+ metadata.gz: b212ee718009840bd627f666ec1cb16ea1732386dc3a3dc8bd12f39aac2ae24c9ccf207a0247e37298ba1411518c44bfb450cec70568c4db141bc0da6ddb8e28
7
+ data.tar.gz: ebc27064ab0edd3113683de4d6b75889b12ed4b2522b3d1e2de7598223526caf67dba7199c3520d22c712bb5e821981d99904b0ba228e9ded9b5cdfd5417d678
data/README.md CHANGED
@@ -266,6 +266,26 @@ CLIPS::Environment.facts(env)
266
266
  env.facts
267
267
  ```
268
268
 
269
+ ### `CLIPS::Environment.get_current_module`
270
+ ### `CLIPS::Environment#get_current_module`
271
+
272
+ Get the current module in the CLIPS environment
273
+
274
+ ```ruby
275
+ CLIPS::Environment.get_current_module(env)
276
+ env.get_current_module
277
+ ```
278
+
279
+ ### `CLIPS::Environment.set_current_module`
280
+ ### `CLIPS::Environment#set_current_module`
281
+
282
+ Set the current module in the CLIPS environment
283
+
284
+ ```ruby
285
+ CLIPS::Environment.set_current_module(env, defmodule)
286
+ env.set_current_module(defmodule)
287
+ ```
288
+
269
289
  ### `CLIPS::Environment::Fact.to_h`
270
290
  ### `CLIPS::Environment::Fact#to_h`
271
291
 
@@ -408,6 +428,46 @@ CLIPS::Environment::Defrule.remove_break(defrule)
408
428
  defrule.remove_break
409
429
  ```
410
430
 
431
+ ### `CLIPS::Environment.find_defmodule`
432
+ ### `CLIPS::Environment#find_defmodule`
433
+
434
+ Finds a defmodule by name and returns a CLIPS::Environment::Defmodule object
435
+
436
+ ```ruby
437
+ CLIPS::Environment.find_defmodule(:a)
438
+ env.find_defmodule("foo")
439
+ ```
440
+
441
+ ### `CLIPS::Environment::Defmodule.name`
442
+ ### `CLIPS::Environment::Defmodule#name`
443
+
444
+ Returns the name of a defmodule as a symbol
445
+
446
+ ```ruby
447
+ CLIPS::Environment::Defmodule.name(defmodule)
448
+ defmodule.name
449
+ ```
450
+
451
+ ### `CLIPS::Environment::Defmodule.pp_form`
452
+ ### `CLIPS::Environment::Defmodule#pp_form`
453
+
454
+ Returns a pretty printed string representation of the Defmodule
455
+
456
+ ```ruby
457
+ CLIPS::Environment::Defmodule.pp_form(defmodule)
458
+ defmodule.pp_form
459
+ ```
460
+
461
+ ### `CLIPS::Environment::Defmodule.set_current`
462
+ ### `CLIPS::Environment::Defmodule#set_current`
463
+
464
+ Sets the Defmodule as the current module of the environment
465
+
466
+ ```ruby
467
+ CLIPS::Environment::Defmodule.set_current(defmodule)
468
+ defmodule.set_current
469
+ ```
470
+
411
471
  ## Running the tests
412
472
 
413
473
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -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,129 @@ 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_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
+
1282
+ static VALUE clips_environment_find_defmodule(VALUE self, VALUE defmodule_name)
1283
+ {
1284
+ Environment *env;
1285
+ Defmodule *module;
1286
+
1287
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
1288
+
1289
+ switch (TYPE(defmodule_name)) {
1290
+ case T_STRING:
1291
+ module = FindDefmodule(env, StringValueCStr(defmodule_name));
1292
+ break;
1293
+ case T_SYMBOL:
1294
+ module = FindDefmodule(env, rb_id2name(SYM2ID(defmodule_name)));
1295
+ break;
1296
+ default:
1297
+ rb_warn("defmodule name must be a symbol or string");
1298
+ return Qnil;
1299
+ }
1300
+
1301
+ if (module == NULL) {
1302
+ return Qnil;
1303
+ } else {
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;
1308
+ }
1309
+ }
1310
+
1311
+ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnvironment, VALUE defmodule_name)
1312
+ {
1313
+ return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
1314
+ }
1315
+
1316
+ static VALUE clips_environment_defmodule_name(VALUE self)
1317
+ {
1318
+ Defmodule *defmodule;
1319
+
1320
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, defmodule);
1321
+
1322
+ return ID2SYM(rb_intern(DefmoduleName(defmodule)));
1323
+ }
1324
+
1325
+ static VALUE clips_environment_defmodule_static_name(VALUE self, VALUE rbDefmodule)
1326
+ {
1327
+ return clips_environment_defmodule_name(rbDefmodule);
1328
+ }
1329
+
1330
+ static VALUE clips_environment_defmodule_pp_form(VALUE self)
1331
+ {
1332
+ Defmodule *defmodule;
1333
+
1334
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, defmodule);
1335
+
1336
+ return rb_str_new2(DefmodulePPForm(defmodule));
1337
+ }
1338
+
1339
+ static VALUE clips_environment_defmodule_static_pp_form(VALUE self, VALUE rbDefmodule)
1340
+ {
1341
+ return clips_environment_defmodule_pp_form(rbDefmodule);
1342
+ }
1343
+
1344
+ static VALUE clips_environment_defmodule_set_current(VALUE self)
1345
+ {
1346
+ Defmodule *module;
1347
+ Environment *env;
1348
+
1349
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
1350
+
1351
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
1352
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1353
+
1354
+ SetCurrentModule(env, module);
1355
+
1356
+ return self;
1357
+ }
1358
+
1359
+ static VALUE clips_environment_defmodule_static_set_current(VALUE self, VALUE rbDefmodule)
1360
+ {
1361
+ return clips_environment_defmodule_set_current(rbDefmodule);
1362
+ }
1363
+
1213
1364
  static VALUE clips_environment_defrule_name(VALUE self)
1214
1365
  {
1215
1366
  Defrule *defrule;
@@ -1357,8 +1508,24 @@ void Init_clipsruby(void)
1357
1508
  rb_define_method(rbEnvironment, "bload_facts", clips_environment_bload_facts, 1);
1358
1509
  rb_define_singleton_method(rbEnvironment, "find_defrule", clips_environment_static_find_defrule, 2);
1359
1510
  rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
1511
+ rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
1512
+ rb_define_method(rbEnvironment, "find_defmodule", clips_environment_find_defmodule, 1);
1513
+ rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
1514
+ rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
1515
+ rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
1516
+ rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
1517
+
1518
+ VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
1519
+ rb_define_alloc_func(rbDefmodule, defmodule_alloc);
1520
+ rb_define_singleton_method(rbDefmodule, "name", clips_environment_defmodule_static_name, 1);
1521
+ rb_define_method(rbDefmodule, "name", clips_environment_defmodule_name, 0);
1522
+ rb_define_singleton_method(rbDefmodule, "pp_form", clips_environment_defmodule_static_pp_form, 1);
1523
+ rb_define_method(rbDefmodule, "pp_form", clips_environment_defmodule_pp_form, 0);
1524
+ rb_define_singleton_method(rbDefmodule, "set_current", clips_environment_defmodule_static_set_current, 1);
1525
+ rb_define_method(rbDefmodule, "set_current", clips_environment_defmodule_set_current, 0);
1360
1526
 
1361
1527
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
1528
+ rb_define_alloc_func(rbFact, fact_alloc);
1362
1529
  rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
1363
1530
  rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
1364
1531
  rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
@@ -1375,6 +1542,7 @@ void Init_clipsruby(void)
1375
1542
  rb_define_method(rbFact, "index", clips_environment_fact_index, 0);
1376
1543
 
1377
1544
  VALUE rbDefrule = rb_define_class_under(rbEnvironment, "Defrule", rb_cObject);
1545
+ rb_define_alloc_func(rbDefrule, defrule_alloc);
1378
1546
  rb_define_singleton_method(rbDefrule, "name", clips_environment_defrule_static_name, 1);
1379
1547
  rb_define_method(rbDefrule, "name", clips_environment_defrule_name, 0);
1380
1548
  rb_define_singleton_method(rbDefrule, "pp_form", clips_environment_defrule_static_pp_form, 1);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston