Class: CLIPS::Environment
- Inherits:
-
Object
- Object
- CLIPS::Environment
- Defined in:
- ext/clipsruby/clipsruby.c
Defined Under Namespace
Class Method Summary collapse
- .add_udf(*args) ⇒ Object
- .assert_hash(environment, deftemplate_name, hash) ⇒ Object
- .assert_string(rbEnvironment, string) ⇒ Object
- .build(rbEnvironment, string) ⇒ Object
- .facts(rbEnvironment) ⇒ Object
- .run(*args) ⇒ Object
Instance Method Summary collapse
- #add_udf(*args) ⇒ Object
- #assert_hash(deftemplate_name, hash) ⇒ Object
- #assert_string(string) ⇒ Object
- #build(string) ⇒ Object
- #facts ⇒ Object
- #run(*args) ⇒ Object
Class Method Details
.add_udf(*args) ⇒ Object
550 551 552 553 554 555 556 557 558 559 560 |
# File 'ext/clipsruby/clipsruby.c', line 550 static VALUE clips_environment_static_add_udf(int argc, VALUE *argv, VALUE klass) { VALUE environment, method_name, clips_function_name; rb_scan_args(argc, argv, "21", &environment, &method_name, &clips_function_name); if (NIL_P(clips_function_name)) { clips_function_name = method_name; } return _clips_environment_add_udf(environment, method_name, clips_function_name); } |
.assert_hash(environment, deftemplate_name, hash) ⇒ Object
321 322 323 324 |
# File 'ext/clipsruby/clipsruby.c', line 321 static VALUE clips_environment_static_assert_hash(VALUE self, VALUE environment, VALUE deftemplate_name, VALUE hash) { return clips_environment_assert_hash(environment, deftemplate_name, hash); } |
.assert_string(rbEnvironment, string) ⇒ Object
90 91 92 93 |
# File 'ext/clipsruby/clipsruby.c', line 90 static VALUE clips_environment_static_assert_string(VALUE self, VALUE rbEnvironment, VALUE string) { return clips_environment_assert_string(rbEnvironment, string); } |
.build(rbEnvironment, string) ⇒ Object
119 120 121 122 |
# File 'ext/clipsruby/clipsruby.c', line 119 static VALUE clips_environment_static_build(VALUE self, VALUE rbEnvironment, VALUE string) { return clips_environment_build(rbEnvironment, string); } |
.facts(rbEnvironment) ⇒ Object
59 60 61 62 |
# File 'ext/clipsruby/clipsruby.c', line 59 static VALUE clips_environment_static_facts(VALUE self, VALUE rbEnvironment) { return clips_environment_facts(rbEnvironment); } |
.run(*args) ⇒ Object
576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'ext/clipsruby/clipsruby.c', line 576 static VALUE clips_environment_static_run(int argc, VALUE *argv, VALUE klass) { VALUE environment, integer; Environment *env; rb_scan_args(argc, argv, "11", &environment, &integer); if (NIL_P(integer)) { integer = INT2NUM(-1); } TypedData_Get_Struct(environment, Environment, &Environment_type, env); return NUM2INT(Run(env, NUM2INT(integer))); } |
Instance Method Details
#add_udf(*args) ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 |
# File 'ext/clipsruby/clipsruby.c', line 538 static VALUE clips_environment_add_udf(int argc, VALUE *argv, VALUE environment) { VALUE method_name, clips_function_name; rb_scan_args(argc, argv, "11", &method_name, &clips_function_name); if (NIL_P(clips_function_name)) { clips_function_name = method_name; } return _clips_environment_add_udf(environment, method_name, clips_function_name); } |
#assert_hash(deftemplate_name, hash) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'ext/clipsruby/clipsruby.c', line 273 static VALUE clips_environment_assert_hash(VALUE self, VALUE deftemplate_name, VALUE hash) { const char *cdeftemplate_name; switch(TYPE(deftemplate_name)) { case T_SYMBOL: cdeftemplate_name = rb_id2name(SYM2ID(deftemplate_name)); break; case T_STRING: cdeftemplate_name = StringValueCStr(deftemplate_name); break; default: rb_raise(rb_eTypeError, "First argument must be a String or a Symbol"); break; } Environment *env; TypedData_Get_Struct(self, Environment, &Environment_type, env); FactBuilder *fb = CreateFactBuilder(env, cdeftemplate_name); void *args[2] = { (void *)fb, (void *)env }; rb_hash_foreach(hash, _clips_environment_assert_hash, (VALUE)args); Fact *fact = FBAssert(fb); FBDispose(fb); switch (FBError(env)) { case FBE_NO_ERROR: break; case FBE_NULL_POINTER_ERROR: rb_warn("Could not assert fact. This might be a bug in clipsruby!"); return Qnil; case FBE_COULD_NOT_ASSERT_ERROR: rb_warn("Could not assert fact. Pattern matching of a fact or instance is already occurring."); return Qnil; case FBE_RULE_NETWORK_ERROR: rb_warn("Could not assert fact. An error occurs while the assertion was being processed in the rule network."); return Qnil; } VALUE rb_fact = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Fact")), &Fact_type, fact); rb_iv_set(rb_fact, "@environment", self); return rb_fact; } |
#assert_string(string) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'ext/clipsruby/clipsruby.c', line 74 static VALUE clips_environment_assert_string(VALUE self, VALUE string) { Environment *env; TypedData_Get_Struct(self, Environment, &Environment_type, env); Fact *fact = AssertString(env, StringValueCStr(string)); VALUE rb_fact = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Fact")), &Fact_type, fact); rb_iv_set(rb_fact, "@environment", self); return rb_fact; } |
#build(string) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'ext/clipsruby/clipsruby.c', line 95 static VALUE clips_environment_build(VALUE self, VALUE string) { Environment *env; TypedData_Get_Struct(self, Environment, &Environment_type, env); switch(Build(env, StringValueCStr(string))) { case BE_NO_ERROR: break; case BE_COULD_NOT_BUILD_ERROR: rb_warn("`build` failed!"); break; case BE_CONSTRUCT_NOT_FOUND_ERROR: rb_warn("`build` failed! Construct not found."); break; case BE_PARSING_ERROR: rb_warn("`build` failed! Could not parse string correctly."); break; } return Qnil; } |
#facts ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'ext/clipsruby/clipsruby.c', line 48 static VALUE clips_environment_facts(VALUE self) { Environment *env; TypedData_Get_Struct(self, Environment, &Environment_type, env); Facts(env, "stdout", NULL, -1, -1, -1); return self; } |
#run(*args) ⇒ Object
562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'ext/clipsruby/clipsruby.c', line 562 static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) { VALUE integer; Environment *env; rb_scan_args(argc, argv, "01", &integer); if (NIL_P(integer)) { integer = INT2NUM(-1); } TypedData_Get_Struct(environment, Environment, &Environment_type, env); return NUM2INT(Run(env, NUM2INT(integer))); } |