clipsruby 0.0.19 → 0.0.20

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/ext/clipsruby/clipsruby.c +88 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c06b3f9f05fc87da93b208ba7f77de5097f964a689e2a9d1cdc8d8e0d992c826
4
- data.tar.gz: 151dd0c82d9213a7ce971935513cbd9c16ab76bc08b123c7321ecfe1fa5cf985
3
+ metadata.gz: ed56e2c48e4ab0971ac56242518c127aa04368c3e2d6d1102f734ce577d89a54
4
+ data.tar.gz: ca7df6a8e9eb6711ed51b14e3db1ee799e887fe0d5b90755705b14672c57bd57
5
5
  SHA512:
6
- metadata.gz: d545c65c3587d29c3b0a4fa12ffa6ecc030c242c472bcb5eb607014de3a03bd465defbe34fa4753e2594e55b2f5685f4111d8ab1c38b2467a9fa38256e31458c
7
- data.tar.gz: c49a1fa673d5f680ee9c6fc2a38ed4dd4708cc996b8624f620e97d5161a5f533077542d7b0a4e788c4a6a4b9be49ad1bbf4307e769fde4cc537dde92905b8b86
6
+ metadata.gz: 2017fc2246a1869a5971e3cd6c9471e8903c1435e71cb0735c729d2e3165be97a6bc6d48373a2b9e4b3d1343854a5ebd681a70934b81a78c7a8654c65db9bbfd
7
+ data.tar.gz: 59734c2c151c11125d8c114f9aaae1b62f869969e272f3b97de7d37ba1c908b577c091fffe000c161484d5536795f20eab66f19cf53842c90bb969c58aa266cb
@@ -1,6 +1,18 @@
1
1
  #include "clips.h"
2
2
  #include "ruby.h"
3
3
 
4
+ size_t deftemplate_size(const void *data)
5
+ {
6
+ return sizeof(Deftemplate);
7
+ }
8
+
9
+ static const rb_data_type_t Deftemplate_type = {
10
+ .function = {
11
+ .dsize = deftemplate_size
12
+ },
13
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
14
+ };
15
+
4
16
  size_t defmodule_size(const void *data)
5
17
  {
6
18
  return sizeof(Defmodule);
@@ -91,6 +103,11 @@ VALUE defmodule_alloc(VALUE self)
91
103
  return TypedData_Wrap_Struct(self, &Defmodule_type, NULL);
92
104
  }
93
105
 
106
+ VALUE deftemplate_alloc(VALUE self)
107
+ {
108
+ return TypedData_Wrap_Struct(self, &Deftemplate_type, NULL);
109
+ }
110
+
94
111
  VALUE defrule_alloc(VALUE self)
95
112
  {
96
113
  return TypedData_Wrap_Struct(self, &Defrule_type, NULL);
@@ -1313,6 +1330,68 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
1313
1330
  return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
1314
1331
  }
1315
1332
 
1333
+ static VALUE clips_environment_find_deftemplate(VALUE self, VALUE deftemplate_name)
1334
+ {
1335
+ Environment *env;
1336
+ Deftemplate *template;
1337
+
1338
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
1339
+
1340
+ switch (TYPE(deftemplate_name)) {
1341
+ case T_STRING:
1342
+ template = FindDeftemplate(env, StringValueCStr(deftemplate_name));
1343
+ break;
1344
+ case T_SYMBOL:
1345
+ template = FindDeftemplate(env, rb_id2name(SYM2ID(deftemplate_name)));
1346
+ break;
1347
+ default:
1348
+ rb_warn("deftemplate name must be a symbol or string");
1349
+ return Qnil;
1350
+ }
1351
+
1352
+ if (template == NULL) {
1353
+ return Qnil;
1354
+ } else {
1355
+ VALUE rbDeftemplate;
1356
+ rbDeftemplate = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deftemplate")), &Deftemplate_type, template);
1357
+ rb_iv_set(rbDeftemplate, "@environment", self);
1358
+ return rbDeftemplate;
1359
+ }
1360
+ }
1361
+
1362
+ static VALUE clips_environment_static_find_deftemplate(VALUE self, VALUE rbEnvironment, VALUE deftemplate_name)
1363
+ {
1364
+ return clips_environment_find_deftemplate(rbEnvironment, deftemplate_name);
1365
+ }
1366
+
1367
+ static VALUE clips_environment_deftemplate_name(VALUE self)
1368
+ {
1369
+ Deftemplate *deftemplate;
1370
+
1371
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
1372
+
1373
+ return ID2SYM(rb_intern(DeftemplateName(deftemplate)));
1374
+ }
1375
+
1376
+ static VALUE clips_environment_deftemplate_static_name(VALUE self, VALUE rbDeftemplate)
1377
+ {
1378
+ return clips_environment_deftemplate_name(rbDeftemplate);
1379
+ }
1380
+
1381
+ static VALUE clips_environment_deftemplate_pp_form(VALUE self)
1382
+ {
1383
+ Deftemplate *deftemplate;
1384
+
1385
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
1386
+
1387
+ return rb_str_new2(DeftemplatePPForm(deftemplate));
1388
+ }
1389
+
1390
+ static VALUE clips_environment_deftemplate_static_pp_form(VALUE self, VALUE rbDeftemplate)
1391
+ {
1392
+ return clips_environment_deftemplate_pp_form(rbDeftemplate);
1393
+ }
1394
+
1316
1395
  static VALUE clips_environment_get_fact_list(int argc, VALUE *argv, VALUE rbEnvironment) {
1317
1396
  VALUE defmodule_or_defmodule_name;
1318
1397
  Environment *env;
@@ -1603,6 +1682,8 @@ void Init_clipsruby(void)
1603
1682
  rb_define_method(rbEnvironment, "find_defrule", clips_environment_find_defrule, 1);
1604
1683
  rb_define_singleton_method(rbEnvironment, "find_defmodule", clips_environment_static_find_defmodule, 2);
1605
1684
  rb_define_method(rbEnvironment, "find_defmodule", clips_environment_find_defmodule, 1);
1685
+ rb_define_singleton_method(rbEnvironment, "find_deftemplate", clips_environment_static_find_deftemplate, 2);
1686
+ rb_define_method(rbEnvironment, "find_deftemplate", clips_environment_find_deftemplate, 1);
1606
1687
  rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
1607
1688
  rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
1608
1689
  rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
@@ -1610,6 +1691,13 @@ void Init_clipsruby(void)
1610
1691
  rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
1611
1692
  rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
1612
1693
 
1694
+ VALUE rbDeftemplate = rb_define_class_under(rbEnvironment, "Deftemplate", rb_cObject);
1695
+ rb_define_alloc_func(rbDeftemplate, deftemplate_alloc);
1696
+ rb_define_singleton_method(rbDeftemplate, "name", clips_environment_deftemplate_static_name, 1);
1697
+ rb_define_method(rbDeftemplate, "name", clips_environment_deftemplate_name, 0);
1698
+ rb_define_singleton_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_static_pp_form, 1);
1699
+ rb_define_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_pp_form, 0);
1700
+
1613
1701
  VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
1614
1702
  rb_define_alloc_func(rbDefmodule, defmodule_alloc);
1615
1703
  rb_define_singleton_method(rbDefmodule, "name", clips_environment_defmodule_static_name, 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.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston