clipsruby 0.0.5 → 0.0.6
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/ext/clipsruby/clipsruby.c +76 -9
- 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: 4e3ac17e072a0fec194ad7a163acefb487ed0b2d822c04ba71f28e517278fe7a
|
4
|
+
data.tar.gz: 76b21dc4e2c25ae2017d94c064ac33f9bd2e3ff9d6a9b9505e5bd2f298b1d837
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a665cd9fd033552cad6807dea0616cf5ebb9f41e1d07f37357c57d85e3e3db50c4845792626e47d01c8c0a6a1a1454983b8f32979624bfadc0d08388d96cefc1
|
7
|
+
data.tar.gz: 2ac05ff02cbb504aba1eab34cfcd5f7ff4c800cd4021de5bf956edec010725af34a5dcaa531b91b633761f9198b5835316b1b3ca20d639c0860297da5b40e46e
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -323,8 +323,10 @@ static VALUE clips_environment_static_assert_hash(VALUE self, VALUE environment,
|
|
323
323
|
return clips_environment_assert_hash(environment, deftemplate_name, hash);
|
324
324
|
}
|
325
325
|
|
326
|
-
static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value,
|
326
|
+
static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnvironment)
|
327
327
|
{
|
328
|
+
Environment *env;
|
329
|
+
TypedData_Get_Struct(*rbEnvironment, Environment, &Environment_type, env);
|
328
330
|
switch (from->header->type)
|
329
331
|
{
|
330
332
|
case VOID_TYPE:
|
@@ -338,7 +340,7 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, Environment *env
|
|
338
340
|
for (size_t i = 0; i < from->multifieldValue->length; i++)
|
339
341
|
{
|
340
342
|
VALUE innerValue;
|
341
|
-
CLIPSValue_to_VALUE(&from->multifieldValue->contents[i], &innerValue,
|
343
|
+
CLIPSValue_to_VALUE(&from->multifieldValue->contents[i], &innerValue, rbEnvironment);
|
342
344
|
rb_ary_push(*value, innerValue);
|
343
345
|
}
|
344
346
|
break;
|
@@ -358,8 +360,13 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, Environment *env
|
|
358
360
|
case INSTANCE_NAME_TYPE:
|
359
361
|
*value = rb_str_new2(from->lexemeValue->contents);
|
360
362
|
break;
|
361
|
-
case EXTERNAL_ADDRESS_TYPE:
|
362
363
|
case FACT_ADDRESS_TYPE:
|
364
|
+
*value =
|
365
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(*rbEnvironment), rb_intern("Fact")), &Fact_type, from->factValue);
|
366
|
+
|
367
|
+
rb_iv_set(*value, "@environment", *rbEnvironment);
|
368
|
+
break;
|
369
|
+
case EXTERNAL_ADDRESS_TYPE:
|
363
370
|
case INSTANCE_ADDRESS_TYPE:
|
364
371
|
default:
|
365
372
|
WriteString(env,STDERR,"Unsupported data type returned from function\n");
|
@@ -368,8 +375,10 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, Environment *env
|
|
368
375
|
}
|
369
376
|
}
|
370
377
|
|
371
|
-
static void UDFValue_to_VALUE(UDFValue *from, VALUE *value,
|
378
|
+
static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, VALUE *rbEnvironment)
|
372
379
|
{
|
380
|
+
Environment *env;
|
381
|
+
TypedData_Get_Struct(*rbEnvironment, Environment, &Environment_type, env);
|
373
382
|
switch (from->header->type)
|
374
383
|
{
|
375
384
|
case VOID_TYPE:
|
@@ -383,7 +392,7 @@ static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, Environment *env)
|
|
383
392
|
VALUE innerValue;
|
384
393
|
for (size_t i = 0; i < from->multifieldValue->length; i++)
|
385
394
|
{
|
386
|
-
CLIPSValue_to_VALUE(&from->multifieldValue->contents[i], &innerValue,
|
395
|
+
CLIPSValue_to_VALUE(&from->multifieldValue->contents[i], &innerValue, rbEnvironment);
|
387
396
|
rb_ary_push(*value, innerValue);
|
388
397
|
}
|
389
398
|
break;
|
@@ -403,8 +412,13 @@ static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, Environment *env)
|
|
403
412
|
case INSTANCE_NAME_TYPE:
|
404
413
|
*value = rb_str_new2(from->lexemeValue->contents);
|
405
414
|
break;
|
406
|
-
case EXTERNAL_ADDRESS_TYPE:
|
407
415
|
case FACT_ADDRESS_TYPE:
|
416
|
+
*value =
|
417
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(*rbEnvironment), rb_intern("Fact")), &Fact_type, from->factValue);
|
418
|
+
|
419
|
+
rb_iv_set(*value, "@environment", *rbEnvironment);
|
420
|
+
break;
|
421
|
+
case EXTERNAL_ADDRESS_TYPE:
|
408
422
|
case INSTANCE_ADDRESS_TYPE:
|
409
423
|
default:
|
410
424
|
WriteString(env,STDERR,"Unsupported data type returned from function\n");
|
@@ -424,10 +438,11 @@ void UDFGenericFunction(
|
|
424
438
|
UDFValue theArg;
|
425
439
|
VALUE method = (VALUE)(context->context);
|
426
440
|
VALUE theValue;
|
441
|
+
VALUE rbEnvironment = rb_funcall(method, rb_intern("receiver"), 0);
|
427
442
|
while (UDFHasNextArgument(context))
|
428
443
|
{
|
429
444
|
UDFNextArgument(context, ANY_TYPE_BITS, &theArg);
|
430
|
-
UDFValue_to_VALUE(&theArg, current_argv,
|
445
|
+
UDFValue_to_VALUE(&theArg, current_argv, &rbEnvironment);
|
431
446
|
current_argv++;
|
432
447
|
}
|
433
448
|
// Call the method on the object with the provided arguments
|
@@ -570,7 +585,7 @@ static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) {
|
|
570
585
|
|
571
586
|
TypedData_Get_Struct(environment, Environment, &Environment_type, env);
|
572
587
|
|
573
|
-
return
|
588
|
+
return INT2NUM(Run(env, NUM2INT(integer)));
|
574
589
|
}
|
575
590
|
|
576
591
|
static VALUE clips_environment_static_run(int argc, VALUE *argv, VALUE klass) {
|
@@ -584,7 +599,53 @@ static VALUE clips_environment_static_run(int argc, VALUE *argv, VALUE klass) {
|
|
584
599
|
|
585
600
|
TypedData_Get_Struct(environment, Environment, &Environment_type, env);
|
586
601
|
|
587
|
-
return
|
602
|
+
return INT2NUM(Run(env, NUM2INT(integer)));
|
603
|
+
}
|
604
|
+
|
605
|
+
/*
|
606
|
+
static VALUE clips_environment_find_all_facts(VALUE self)
|
607
|
+
{
|
608
|
+
Fact *fact;
|
609
|
+
|
610
|
+
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
611
|
+
|
612
|
+
return ID2SYM(rb_intern(DeftemplateName(FactDeftemplate(fact))));
|
613
|
+
}
|
614
|
+
|
615
|
+
static VALUE clips_environment_static_find_all_facts(VALUE self, VALUE rbFact)
|
616
|
+
{
|
617
|
+
return clips_environment_fact_deftemplate_name(rbFact);
|
618
|
+
}
|
619
|
+
*/
|
620
|
+
|
621
|
+
static VALUE clips_environment_eval(VALUE self, VALUE string)
|
622
|
+
{
|
623
|
+
Environment *env;
|
624
|
+
CLIPSValue output;
|
625
|
+
VALUE toReturn;
|
626
|
+
|
627
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
628
|
+
|
629
|
+
switch(Eval(env, StringValueCStr(string), &output))
|
630
|
+
{
|
631
|
+
case EE_NO_ERROR:
|
632
|
+
break;
|
633
|
+
case EE_PROCESSING_ERROR:
|
634
|
+
rb_warn("`eval` failed!");
|
635
|
+
break;
|
636
|
+
case EE_PARSING_ERROR:
|
637
|
+
rb_warn("`eval` failed! Could not parse string correctly.");
|
638
|
+
break;
|
639
|
+
}
|
640
|
+
|
641
|
+
CLIPSValue_to_VALUE(&output, &toReturn, &self);
|
642
|
+
|
643
|
+
return toReturn;
|
644
|
+
}
|
645
|
+
|
646
|
+
static VALUE clips_environment_static_eval(VALUE self, VALUE rbEnvironment, VALUE string)
|
647
|
+
{
|
648
|
+
return clips_environment_eval(rbEnvironment, string);
|
588
649
|
}
|
589
650
|
|
590
651
|
void Init_clipsruby(void)
|
@@ -606,6 +667,12 @@ void Init_clipsruby(void)
|
|
606
667
|
rb_define_method(rbEnvironment, "add_udf", clips_environment_add_udf, -1);
|
607
668
|
rb_define_singleton_method(rbEnvironment, "run", clips_environment_static_run, -1);
|
608
669
|
rb_define_method(rbEnvironment, "run", clips_environment_run, -1);
|
670
|
+
/*
|
671
|
+
rb_define_singleton_method(rbEnvironment, "find_all_facts", clips_environment_static_find_all_facts, 2);
|
672
|
+
rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, 1);
|
673
|
+
*/
|
674
|
+
rb_define_singleton_method(rbEnvironment, "_eval", clips_environment_static_eval, 2);
|
675
|
+
rb_define_method(rbEnvironment, "_eval", clips_environment_eval, 1);
|
609
676
|
|
610
677
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
611
678
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 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.6
|
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-04 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
|