clipsruby 0.0.21 → 0.0.22
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 +21 -0
- data/ext/clipsruby/clipsruby.c +82 -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: 4f7a174c8ca0889553334a3a6ad54580624d7d92695e3483aa44a130627b3fcb
|
4
|
+
data.tar.gz: a31141c4ce2490c74218316c89d08342dab315d5c35016c8dd488c2a344f8ae7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 863a626437f0c4583e0f35618b4fd29c461b579833970e08999202dc35c2ac306a61b5eb3d029551187c7791d7b7fb22cb3d400d4106dea3c30eb1f1eccd7e73
|
7
|
+
data.tar.gz: aa4858ed68e383ff113accafb0f4652d4453448e93e6ecfa5c55a5903263925ae4ed114401158cb8d08b291a85eaf82891df0020a0b8f74cd9fbabdb228f4cec
|
data/README.md
CHANGED
@@ -332,6 +332,16 @@ CLIPS::Environment::Fact.index(fact)
|
|
332
332
|
fact.index
|
333
333
|
```
|
334
334
|
|
335
|
+
### `CLIPS::Environment::Fact.deftemplate`
|
336
|
+
### `CLIPS::Environment::Fact#deftemplate`
|
337
|
+
|
338
|
+
Returns the Deftemplate object for a fact
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
CLIPS::Environment::Fact.deftemplate(fact)
|
342
|
+
fact.deftemplate
|
343
|
+
```
|
344
|
+
|
335
345
|
### `CLIPS::Environment::Fact.deftemplate_name`
|
336
346
|
### `CLIPS::Environment::Fact#deftemplate_name`
|
337
347
|
|
@@ -534,6 +544,17 @@ CLIPS::Environment::Deftemplate.pp_form(deftemplate)
|
|
534
544
|
deftemplate.pp_form
|
535
545
|
```
|
536
546
|
|
547
|
+
### `CLIPS::Environment::Deftemplate.assert_hash`
|
548
|
+
### `CLIPS::Environment::Deftemplate#assert_hash`
|
549
|
+
|
550
|
+
Asserts a hash in the clips environment that a Deftemplate is defined in.
|
551
|
+
Returns the Fact object that was just asserted
|
552
|
+
|
553
|
+
```ruby
|
554
|
+
CLIPS::Environment::Deftemplate.assert_hash(deftemplate, foo: :bar)
|
555
|
+
deftemplate.assert_hash(foo: :bar)
|
556
|
+
```
|
557
|
+
|
537
558
|
### `CLIPS::Environment.find_deffacts`
|
538
559
|
### `CLIPS::Environment#find_deffacts`
|
539
560
|
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -62,6 +62,26 @@ static const rb_data_type_t Fact_type = {
|
|
62
62
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
63
63
|
};
|
64
64
|
|
65
|
+
static VALUE clips_environment_fact_deftemplate(VALUE self)
|
66
|
+
{
|
67
|
+
VALUE rbDeftemplate, rbEnvironment;
|
68
|
+
Fact *fact;
|
69
|
+
Deftemplate *template;
|
70
|
+
|
71
|
+
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
72
|
+
|
73
|
+
template = FactDeftemplate(fact);
|
74
|
+
rbEnvironment = rb_iv_get(self, "@environment");
|
75
|
+
rbDeftemplate = TypedData_Wrap_Struct(rb_const_get(rb_obj_class(rbEnvironment), rb_intern("Deftemplate")), &Deftemplate_type, template);
|
76
|
+
rb_iv_set(rbDeftemplate, "@environment", rbEnvironment);
|
77
|
+
return rbDeftemplate;
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE clips_environment_fact_static_deftemplate(VALUE self, VALUE rbFact)
|
81
|
+
{
|
82
|
+
return clips_environment_fact_deftemplate(rbFact);
|
83
|
+
}
|
84
|
+
|
65
85
|
static VALUE clips_environment_fact_deftemplate_name(VALUE self)
|
66
86
|
{
|
67
87
|
Fact *fact;
|
@@ -408,6 +428,64 @@ static VALUE clips_environment_static_assert_hash(VALUE self, VALUE environment,
|
|
408
428
|
return clips_environment_assert_hash(environment, deftemplate_name, hash);
|
409
429
|
}
|
410
430
|
|
431
|
+
static VALUE clips_environment_deftemplate_assert_hash(VALUE self, VALUE hash)
|
432
|
+
{
|
433
|
+
const char *cdeftemplate_name;
|
434
|
+
|
435
|
+
Environment *env;
|
436
|
+
Deftemplate *template;
|
437
|
+
|
438
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
439
|
+
TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, template);
|
440
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
441
|
+
|
442
|
+
cdeftemplate_name = DeftemplateName(template);
|
443
|
+
|
444
|
+
FactBuilder *fb = CreateFactBuilder(env, cdeftemplate_name);
|
445
|
+
switch (FBError(env))
|
446
|
+
{
|
447
|
+
case FBE_NO_ERROR:
|
448
|
+
break;
|
449
|
+
case FBE_DEFTEMPLATE_NOT_FOUND_ERROR:
|
450
|
+
rb_warn("Could not assert fact; deftemplate not found!");
|
451
|
+
return Qnil;
|
452
|
+
case FBE_IMPLIED_DEFTEMPLATE_ERROR:
|
453
|
+
rb_warn("Could not assert fact; cannot use assert_hash to create non-deftemplated facts!");
|
454
|
+
return Qnil;
|
455
|
+
}
|
456
|
+
void *args[2] = { (void *)fb, (void *)env };
|
457
|
+
rb_hash_foreach(hash, _clips_environment_assert_hash, (VALUE)args);
|
458
|
+
Fact *fact = FBAssert(fb);
|
459
|
+
FBDispose(fb);
|
460
|
+
|
461
|
+
switch (FBError(env))
|
462
|
+
{
|
463
|
+
case FBE_NO_ERROR:
|
464
|
+
break;
|
465
|
+
case FBE_NULL_POINTER_ERROR:
|
466
|
+
rb_warn("Could not assert fact. This might be a bug in clipsruby!");
|
467
|
+
return Qnil;
|
468
|
+
case FBE_COULD_NOT_ASSERT_ERROR:
|
469
|
+
rb_warn("Could not assert fact. Pattern matching of a fact or instance is already occurring.");
|
470
|
+
return Qnil;
|
471
|
+
case FBE_RULE_NETWORK_ERROR:
|
472
|
+
rb_warn("Could not assert fact. An error occurs while the assertion was being processed in the rule network.");
|
473
|
+
return Qnil;
|
474
|
+
}
|
475
|
+
|
476
|
+
VALUE rb_fact =
|
477
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Fact")), &Fact_type, fact);
|
478
|
+
|
479
|
+
rb_iv_set(rb_fact, "@environment", rbEnvironment);
|
480
|
+
|
481
|
+
return rb_fact;
|
482
|
+
}
|
483
|
+
|
484
|
+
static VALUE clips_environment_deftemplate_static_assert_hash(VALUE self, VALUE deftemplate, VALUE hash)
|
485
|
+
{
|
486
|
+
return clips_environment_deftemplate_assert_hash(deftemplate, hash);
|
487
|
+
}
|
488
|
+
|
411
489
|
static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnvironment)
|
412
490
|
{
|
413
491
|
Environment *env;
|
@@ -1834,6 +1912,8 @@ void Init_clipsruby(void)
|
|
1834
1912
|
rb_define_method(rbDeftemplate, "name", clips_environment_deftemplate_name, 0);
|
1835
1913
|
rb_define_singleton_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_static_pp_form, 1);
|
1836
1914
|
rb_define_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_pp_form, 0);
|
1915
|
+
rb_define_singleton_method(rbDeftemplate, "assert_hash", clips_environment_deftemplate_static_assert_hash, 2);
|
1916
|
+
rb_define_method(rbDeftemplate, "assert_hash", clips_environment_deftemplate_assert_hash, 1);
|
1837
1917
|
|
1838
1918
|
VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
|
1839
1919
|
rb_define_alloc_func(rbDefmodule, defmodule_alloc);
|
@@ -1848,6 +1928,8 @@ void Init_clipsruby(void)
|
|
1848
1928
|
|
1849
1929
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
1850
1930
|
rb_define_alloc_func(rbFact, fact_alloc);
|
1931
|
+
rb_define_singleton_method(rbFact, "deftemplate", clips_environment_fact_static_deftemplate, 1);
|
1932
|
+
rb_define_method(rbFact, "deftemplate", clips_environment_fact_deftemplate, 0);
|
1851
1933
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
1852
1934
|
rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
|
1853
1935
|
rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
|
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.22
|
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-13 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
|