clipsruby 0.0.45 → 0.0.47

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 +86 -0
  3. data/ext/clipsruby/clipsruby.c +389 -51
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c9cd2640f2fe1fe923a67eedc51756a103b1d7efe16ba242cb511f4457c48b1
4
- data.tar.gz: 66468126873d355fbba614bbc0ce86dd33e6064b1c32a6d54012a0a7007b3b29
3
+ metadata.gz: f3c227f46986382a156b8507a7db8ba41d68fb2f34ff9f5f6de771328f92149f
4
+ data.tar.gz: 138c3a0af3fa85967eb8fc9257f0c486a5a2c1daa165a32a60fe205d53608ddd
5
5
  SHA512:
6
- metadata.gz: efefcb6fe9b23f5d3c9711066d7113ae8413f581ba14160cef069a5843fca5c2c52de7677f364d78ff87c2b706b7aeaea65ce92194babc9d9f411fe9de4b2989
7
- data.tar.gz: 7fc6d37228814375d88e21f09737383ba69c450f5a989cc8f8c2a1dbb22d792e6970627cc0eda249d38b0250afb2a7648347edc9ea2b184195e1280643278fd1
6
+ metadata.gz: a58d5f08757fd89c5e41fdca66897b64de30c1e239c876595a76b3991dc9dc45400de4061cd39f949c9be9db2345938bfaf5e493ef60ee59988dc71c04e4c12b
7
+ data.tar.gz: ccefb2aa21db768a717cb872121400fe919b7c4355e42b6d3a2a62fba720e303002e426a9bad7d08f4f6a799c26bdb7e6814bab7a146a6284ee51099838e399d
data/README.md CHANGED
@@ -483,6 +483,18 @@ CLIPS::Environment.get_defmodule_list(env)
483
483
  env.get_defmodule_list
484
484
  ```
485
485
 
486
+ #### `CLIPS::Environment.get_deffunction_list` / `CLIPS::Environment#get_deffunction_list`
487
+
488
+ Return an array of Deffunction names as symbols in the environment.
489
+ Optionally pass a `Defmodule`.
490
+
491
+ ```ruby
492
+ CLIPS::Environment.get_deffunction_list(env)
493
+ env.get_deffunction_list
494
+ CLIPS::Environment.get_deffunction_list(env, :MAIN)
495
+ env.get_deffunction_list(defmodule)
496
+ ```
497
+
486
498
  #### `CLIPS::Environment.find_deftemplate` / `CLIPS::Environment#find_deftemplate`
487
499
 
488
500
  Finds a deftemplate by name and returns a CLIPS::Environment::Deftemplate object
@@ -1055,6 +1067,15 @@ CLIPS::Environment::Defmodule.get_defrule_list(defmodule)
1055
1067
  defmodule.get_defrule_list
1056
1068
  ```
1057
1069
 
1070
+ #### `CLIPS::Environment::Defmodule.get_deffunction_list` / `CLIPS::Environment::Defmodule#get_deffunction_list`
1071
+
1072
+ Return an array of Deffunction names as symbols in the Defmodule
1073
+
1074
+ ```ruby
1075
+ CLIPS::Environment::Defmodule.get_deffunction_list(defmodule)
1076
+ defmodule.get_deffunction_list
1077
+ ```
1078
+
1058
1079
  #### `CLIPS::Environment::Defmodule.refresh_agenda` / `CLIPS::Environment::Defmodule#refresh_agenda`
1059
1080
 
1060
1081
  Refreshes the agenda in a given Defmodule.
@@ -1282,6 +1303,15 @@ CLIPS::Environment.find_deffacts(:a)
1282
1303
  env.find_deffacts("foo")
1283
1304
  ```
1284
1305
 
1306
+ #### `CLIPS::Environment.find_deffunction` / `CLIPS::Environment#find_deffunction`
1307
+
1308
+ Finds a `Deffunction` by name and returns a CLIPS::Environment::Deffunction object
1309
+
1310
+ ```ruby
1311
+ CLIPS::Environment.find_deffunction(:"MAIN::my_deffunction")
1312
+ env.find_deffunction("MAIN::other_deffunction")
1313
+ ```
1314
+
1285
1315
  ### Deffacts Methods
1286
1316
 
1287
1317
  #### `CLIPS::Environment::Deffacts.name` / `CLIPS::Environment::Deffacts#name`
@@ -1349,6 +1379,62 @@ CLIPS::Environment::Activation.pp_form(activation)
1349
1379
  activation.pp_form
1350
1380
  ```
1351
1381
 
1382
+ ### Deffunction Methods
1383
+
1384
+ #### `CLIPS::Environment::Deffunction.call` / `CLIPS::Environment::Deffunction#call`
1385
+
1386
+ Calls the `Deffunction`, passing it the arguments, returning the return value
1387
+
1388
+ ```ruby
1389
+ CLIPS::Environment::Deffunction.call(deffunction, :FOO, :BAR)
1390
+ deffunction.call(:FOO, :BAR)
1391
+ ```
1392
+
1393
+ #### `CLIPS::Environment::Deffunction.name` / `CLIPS::Environment::Deffunction#name`
1394
+
1395
+ Returns the name of the `Deffunction` as a symbol
1396
+
1397
+ ```ruby
1398
+ CLIPS::Environment::Deffunction.name(deffunction)
1399
+ deffunction.name
1400
+ ```
1401
+
1402
+ #### `CLIPS::Environment::Deffunction.pp_form` / `CLIPS::Environment::Deffunction#pp_form`
1403
+
1404
+ Returns the pretty printed version of the `Deffunction`
1405
+
1406
+ ```ruby
1407
+ CLIPS::Environment::Deffunction.pp_form(deffunction)
1408
+ deffunction.pp_form
1409
+ ```
1410
+
1411
+ #### `CLIPS::Environment::Deffunction.is_deletable` / `CLIPS::Environment::Deffunction#is_deletable`
1412
+
1413
+ Returns whether the `Deffunction` is deletable or not
1414
+
1415
+ ```ruby
1416
+ CLIPS::Environment::Deffunction.is_deletable(deffunction)
1417
+ deffunction.is_deletable
1418
+ ```
1419
+
1420
+ #### `CLIPS::Environment::Deffunction.defmodule` / `CLIPS::Environment::Deffunction#defmodule`
1421
+
1422
+ Returns the `Defmodule` that the `Deffunction` is defined in
1423
+
1424
+ ```ruby
1425
+ CLIPS::Environment::Deffunction.defmodule(deffunction)
1426
+ deffunction.defmodule
1427
+ ```
1428
+
1429
+ #### `CLIPS::Environment::Deffunction.defmodule_name` / `CLIPS::Environment::Deffunction#defmodule_name`
1430
+
1431
+ Returns the name of the `Defmodule` that the `Deffunction` is defined in
1432
+
1433
+ ```ruby
1434
+ CLIPS::Environment::Deffunction.defmodule_name(deffunction)
1435
+ deffunction.defmodule_name
1436
+ ```
1437
+
1352
1438
  ## Running the tests
1353
1439
 
1354
1440
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -115,6 +115,18 @@ static const rb_data_type_t Activation_type = {
115
115
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
116
116
  };
117
117
 
118
+ size_t deffunction_size(const void *data)
119
+ {
120
+ return sizeof(Deffunction);
121
+ }
122
+
123
+ static const rb_data_type_t Deffunction_type = {
124
+ .function = {
125
+ .dsize = deffunction_size
126
+ },
127
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
128
+ };
129
+
118
130
  static VALUE clips_environment_fact_deftemplate(VALUE self)
119
131
  {
120
132
  VALUE rbDeftemplate, rbEnvironment;
@@ -293,6 +305,11 @@ VALUE activation_alloc(VALUE self)
293
305
  return TypedData_Wrap_Struct(self, &Activation_type, NULL);
294
306
  }
295
307
 
308
+ VALUE deffunction_alloc(VALUE self)
309
+ {
310
+ return TypedData_Wrap_Struct(self, &Deffunction_type, NULL);
311
+ }
312
+
296
313
  VALUE environment_alloc(VALUE self)
297
314
  {
298
315
  return TypedData_Wrap_Struct(self, &Environment_type, CreateEnvironment());
@@ -2671,37 +2688,6 @@ static VALUE clips_environment_static_find_defrule(VALUE self, VALUE rbEnvironme
2671
2688
  return clips_environment_find_defrule(rbEnvironment, defrule_name);
2672
2689
  }
2673
2690
 
2674
- static VALUE clips_environment_find_deffacts(VALUE self, VALUE deffacts_name)
2675
- {
2676
- Environment *env;
2677
- Deffacts *deffacts;
2678
-
2679
- TypedData_Get_Struct(self, Environment, &Environment_type, env);
2680
-
2681
- switch (TYPE(deffacts_name)) {
2682
- case T_STRING:
2683
- deffacts = FindDeffacts(env, StringValueCStr(deffacts_name));
2684
- break;
2685
- case T_SYMBOL:
2686
- deffacts = FindDeffacts(env, rb_id2name(SYM2ID(deffacts_name)));
2687
- break;
2688
- default:
2689
- rb_warn("deffacts name must be a symbol or string");
2690
- return Qnil;
2691
- }
2692
-
2693
- if (deffacts == NULL) {
2694
- return Qnil;
2695
- } else {
2696
- return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deffacts")), &Deffacts_type, deffacts);
2697
- }
2698
- }
2699
-
2700
- static VALUE clips_environment_static_find_deffacts(VALUE self, VALUE rbEnvironment, VALUE deffacts_name)
2701
- {
2702
- return clips_environment_find_deffacts(rbEnvironment, deffacts_name);
2703
- }
2704
-
2705
2691
  static VALUE clips_environment_deffacts_name(VALUE self)
2706
2692
  {
2707
2693
  Deffacts *deffacts;
@@ -2759,24 +2745,6 @@ static VALUE clips_environment_static_get_current_module(VALUE self, VALUE rbEnv
2759
2745
  return clips_environment_get_current_module(rbEnvironment);
2760
2746
  }
2761
2747
 
2762
- static VALUE clips_environment_set_current_module(VALUE self, VALUE rbDefmodule)
2763
- {
2764
- Environment *env;
2765
- Defmodule *module;
2766
-
2767
- TypedData_Get_Struct(self, Environment, &Environment_type, env);
2768
- TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, module);
2769
-
2770
- SetCurrentModule(env, module);
2771
-
2772
- return rbDefmodule;
2773
- }
2774
-
2775
- static VALUE clips_environment_static_set_current_module(VALUE self, VALUE rbEnvironment, VALUE defmodule_name)
2776
- {
2777
- return clips_environment_set_current_module(rbEnvironment, defmodule_name);
2778
- }
2779
-
2780
2748
  static VALUE clips_environment_find_defmodule(VALUE self, VALUE defmodule_name)
2781
2749
  {
2782
2750
  Environment *env;
@@ -2811,6 +2779,38 @@ static VALUE clips_environment_static_find_defmodule(VALUE self, VALUE rbEnviron
2811
2779
  return clips_environment_find_defmodule(rbEnvironment, defmodule_name);
2812
2780
  }
2813
2781
 
2782
+ static VALUE clips_environment_set_current_module(VALUE self, VALUE defmodule_or_defmodule_name)
2783
+ {
2784
+ VALUE rbDefmodule;
2785
+ Environment *env;
2786
+ Defmodule *module;
2787
+
2788
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
2789
+ switch (TYPE(defmodule_or_defmodule_name)) {
2790
+ case T_STRING:
2791
+ case T_SYMBOL:
2792
+ rbDefmodule = clips_environment_find_defmodule(self, defmodule_or_defmodule_name);
2793
+ break;
2794
+ case T_DATA:
2795
+ rbDefmodule = defmodule_or_defmodule_name;
2796
+ break;
2797
+ default:
2798
+ rb_raise(rb_eTypeError, "Defmodule must be an instance of CLIPS::Environment::Defmodule, symbol, or string");
2799
+ return Qnil;
2800
+ }
2801
+ TypedData_Get_Struct(rbDefmodule, Defmodule, &Defmodule_type, module);
2802
+
2803
+ SetCurrentModule(env, module);
2804
+
2805
+ return rbDefmodule;
2806
+ }
2807
+
2808
+ static VALUE clips_environment_static_set_current_module(VALUE self, VALUE rbEnvironment, VALUE defmodule_name)
2809
+ {
2810
+ return clips_environment_set_current_module(rbEnvironment, defmodule_name);
2811
+ }
2812
+
2813
+
2814
2814
  static VALUE clips_environment_find_instance(int argc, VALUE *argv, VALUE rbEnvironment) {
2815
2815
  VALUE instanceName, search_imports, rbInstance, rbDefmodule;
2816
2816
  Defmodule *defmodule;
@@ -2935,6 +2935,37 @@ static VALUE clips_environment_static_find_instance(int argc, VALUE *argv, VALUE
2935
2935
  }
2936
2936
  }
2937
2937
 
2938
+ static VALUE clips_environment_find_deffacts(VALUE self, VALUE deffacts_name)
2939
+ {
2940
+ Environment *env;
2941
+ Deffacts *deffacts;
2942
+
2943
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
2944
+
2945
+ switch (TYPE(deffacts_name)) {
2946
+ case T_STRING:
2947
+ deffacts = FindDeffacts(env, StringValueCStr(deffacts_name));
2948
+ break;
2949
+ case T_SYMBOL:
2950
+ deffacts = FindDeffacts(env, rb_id2name(SYM2ID(deffacts_name)));
2951
+ break;
2952
+ default:
2953
+ rb_warn("deffacts name must be a symbol or string");
2954
+ return Qnil;
2955
+ }
2956
+
2957
+ if (deffacts == NULL) {
2958
+ return Qnil;
2959
+ } else {
2960
+ return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deffacts")), &Deffacts_type, deffacts);
2961
+ }
2962
+ }
2963
+
2964
+ static VALUE clips_environment_static_find_deffacts(VALUE self, VALUE rbEnvironment, VALUE deffacts_name)
2965
+ {
2966
+ return clips_environment_find_deffacts(rbEnvironment, deffacts_name);
2967
+ }
2968
+
2938
2969
  static VALUE clips_environment_defmodule_find_instance(int argc, VALUE *argv, VALUE rbDefmodule) {
2939
2970
  VALUE instanceName, search_imports, rbInstance, rbEnvironment;
2940
2971
  Defmodule *defmodule;
@@ -3027,6 +3058,40 @@ static VALUE clips_environment_defmodule_static_find_instance(int argc, VALUE *a
3027
3058
  }
3028
3059
  }
3029
3060
 
3061
+ static VALUE clips_environment_find_deffunction(VALUE self, VALUE deffunction_name)
3062
+ {
3063
+ Environment *env;
3064
+ Deffunction *deffunction;
3065
+
3066
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
3067
+
3068
+ switch (TYPE(deffunction_name)) {
3069
+ case T_STRING:
3070
+ deffunction = FindDeffunction(env, StringValueCStr(deffunction_name));
3071
+ break;
3072
+ case T_SYMBOL:
3073
+ deffunction = FindDeffunction(env, rb_id2name(SYM2ID(deffunction_name)));
3074
+ break;
3075
+ default:
3076
+ rb_warn("deffunction name must be a symbol or string");
3077
+ return Qnil;
3078
+ }
3079
+
3080
+ if (deffunction == NULL) {
3081
+ return Qnil;
3082
+ } else {
3083
+ VALUE rbDeffunction;
3084
+ rbDeffunction = TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Deffunction")), &Deffunction_type, deffunction);
3085
+ rb_iv_set(rbDeffunction, "@environment", self);
3086
+ return rbDeffunction;
3087
+ }
3088
+ }
3089
+
3090
+ static VALUE clips_environment_static_find_deffunction(VALUE self, VALUE rbEnvironment, VALUE deffunction_name)
3091
+ {
3092
+ return clips_environment_find_deffunction(rbEnvironment, deffunction_name);
3093
+ }
3094
+
3030
3095
  static VALUE clips_environment_defmodule_refresh_agenda(VALUE self)
3031
3096
  {
3032
3097
  Defmodule *module;
@@ -3849,6 +3914,30 @@ static VALUE clips_environment_defmodule_static_get_defrule_list(VALUE self, VAL
3849
3914
  return clips_environment_defmodule_get_defrule_list(rbDefmodule);
3850
3915
  }
3851
3916
 
3917
+ static VALUE clips_environment_defmodule_get_deffunction_list(VALUE self)
3918
+ {
3919
+ Defmodule *module;
3920
+ Environment *env;
3921
+ CLIPSValue value;
3922
+ VALUE out;
3923
+
3924
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
3925
+
3926
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
3927
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
3928
+
3929
+ GetDeffunctionList(env, &value, module);
3930
+
3931
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
3932
+
3933
+ return out;
3934
+ }
3935
+
3936
+ static VALUE clips_environment_defmodule_static_get_deffunction_list(VALUE self, VALUE rbDefmodule)
3937
+ {
3938
+ return clips_environment_defmodule_get_deffunction_list(rbDefmodule);
3939
+ }
3940
+
3852
3941
  static VALUE clips_environment_get_defmodule_list(VALUE self)
3853
3942
  {
3854
3943
  Environment *env;
@@ -5054,6 +5143,73 @@ static VALUE clips_environment_static_set_strategy(VALUE self, VALUE rbEnvironme
5054
5143
  return clips_environment_set_strategy(rbEnvironment, changed);
5055
5144
  }
5056
5145
 
5146
+ static VALUE clips_environment_get_deffunction_list(int argc, VALUE *argv, VALUE rbEnvironment) {
5147
+ VALUE defmodule_or_defmodule_name;
5148
+ Environment *env;
5149
+ Defmodule *module;
5150
+ CLIPSValue value;
5151
+ VALUE out;
5152
+
5153
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
5154
+
5155
+ rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
5156
+ switch (TYPE(defmodule_or_defmodule_name)) {
5157
+ case T_NIL:
5158
+ module = NULL;
5159
+ break;
5160
+ case T_STRING:
5161
+ case T_SYMBOL:
5162
+ TypedData_Get_Struct(
5163
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
5164
+ Defmodule, &Defmodule_type, module);
5165
+ break;
5166
+ case T_DATA:
5167
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
5168
+ break;
5169
+ default:
5170
+ rb_warn("defmodule name must be a symbol or string");
5171
+ return Qnil;
5172
+ }
5173
+ GetDeffunctionList(env, &value, module);
5174
+
5175
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
5176
+
5177
+ return out;
5178
+ }
5179
+
5180
+ static VALUE clips_environment_static_get_deffunction_list(int argc, VALUE *argv, VALUE klass) {
5181
+ VALUE rbEnvironment, defmodule_or_defmodule_name;
5182
+ Environment *env;
5183
+ Defmodule *module;
5184
+ CLIPSValue value;
5185
+ VALUE out;
5186
+
5187
+ rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
5188
+
5189
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
5190
+ switch (TYPE(defmodule_or_defmodule_name)) {
5191
+ case T_NIL:
5192
+ module = NULL;
5193
+ break;
5194
+ case T_STRING:
5195
+ case T_SYMBOL:
5196
+ TypedData_Get_Struct(
5197
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
5198
+ Defmodule, &Defmodule_type, module);
5199
+ break;
5200
+ case T_DATA:
5201
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
5202
+ break;
5203
+ default:
5204
+ rb_warn("defmodule name must be a symbol or string");
5205
+ return Qnil;
5206
+ }
5207
+ GetDeffunctionList(env, &value, module);
5208
+
5209
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
5210
+
5211
+ return out;
5212
+ }
5057
5213
 
5058
5214
  static VALUE clips_environment_activation_defrule_name(VALUE self)
5059
5215
  {
@@ -5138,6 +5294,167 @@ static VALUE clips_environment_activation_static_delete(VALUE self, VALUE rbActi
5138
5294
  return clips_environment_activation_delete(rbActivation);
5139
5295
  }
5140
5296
 
5297
+ static VALUE clips_environment_deffunction_name(VALUE self)
5298
+ {
5299
+ Deffunction *deffunction;
5300
+
5301
+ TypedData_Get_Struct(self, Deffunction, &Deffunction_type, deffunction);
5302
+
5303
+ return ID2SYM(rb_intern(DeffunctionName(deffunction)));
5304
+ }
5305
+
5306
+ static VALUE clips_environment_deffunction_static_name(VALUE self, VALUE rbDeffunction)
5307
+ {
5308
+ return clips_environment_deffunction_name(rbDeffunction);
5309
+ }
5310
+
5311
+ static VALUE clips_environment_deffunction_pp_form(VALUE self)
5312
+ {
5313
+ Deffunction *deffunction;
5314
+
5315
+ TypedData_Get_Struct(self, Deffunction, &Deffunction_type, deffunction);
5316
+
5317
+ return rb_str_new2(DeffunctionPPForm(deffunction));
5318
+ }
5319
+
5320
+ static VALUE clips_environment_deffunction_static_pp_form(VALUE self, VALUE rbDeffunction)
5321
+ {
5322
+ return clips_environment_deffunction_pp_form(rbDeffunction);
5323
+ }
5324
+
5325
+ static VALUE clips_environment_deffunction_is_deletable(VALUE self)
5326
+ {
5327
+ Deffunction *deffunction;
5328
+
5329
+ TypedData_Get_Struct(self, Deffunction, &Deffunction_type, deffunction);
5330
+
5331
+ if (DeffunctionIsDeletable(deffunction)) {
5332
+ return Qtrue;
5333
+ } else {
5334
+ return Qfalse;
5335
+ }
5336
+ }
5337
+
5338
+ static VALUE clips_environment_deffunction_static_is_deletable(VALUE self, VALUE rbDeffunction)
5339
+ {
5340
+ return clips_environment_deffunction_is_deletable(rbDeffunction);
5341
+ }
5342
+
5343
+ static VALUE clips_environment_deffunction_defmodule_name(VALUE self)
5344
+ {
5345
+ Deffunction *function;
5346
+
5347
+ TypedData_Get_Struct(self, Deffunction, &Deffunction_type, function);
5348
+
5349
+ return ID2SYM(rb_intern(DeffunctionModule(function)));
5350
+ }
5351
+
5352
+ static VALUE clips_environment_deffunction_static_defmodule_name(VALUE self, VALUE rbDeffunction)
5353
+ {
5354
+ return clips_environment_deffunction_defmodule_name(rbDeffunction);
5355
+ }
5356
+
5357
+ static VALUE clips_environment_deffunction_defmodule(VALUE self)
5358
+ {
5359
+ Deffunction *function;
5360
+ const char *defmoduleName;
5361
+ Defmodule *defmodule = NULL;
5362
+ Environment *env;
5363
+
5364
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
5365
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
5366
+
5367
+ TypedData_Get_Struct(self, Deffunction, &Deffunction_type, function);
5368
+
5369
+ defmoduleName = DeffunctionModule(function);
5370
+
5371
+ if (defmoduleName != NULL) {
5372
+ defmodule = FindDefmodule(env, defmoduleName);
5373
+ }
5374
+
5375
+ if (defmodule != NULL) {
5376
+ return TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Defmodule")), &Defmodule_type, defmodule);
5377
+ } else {
5378
+ return Qnil;
5379
+ }
5380
+ }
5381
+
5382
+ static VALUE clips_environment_deffunction_static_defmodule(VALUE self, VALUE rbDeffunction)
5383
+ {
5384
+ return clips_environment_deffunction_defmodule(rbDeffunction);
5385
+ }
5386
+
5387
+ static VALUE clips_environment_deffunction_call(int argc, VALUE *argv, VALUE self)
5388
+ {
5389
+ FunctionCallBuilder *fcb;
5390
+ Deffunction *function;
5391
+ CLIPSValue value;
5392
+ VALUE out;
5393
+ const char *functionName, *defmoduleName, *currentDefmoduleName;
5394
+ Environment *env;
5395
+
5396
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
5397
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
5398
+
5399
+ TypedData_Get_Struct(self, Deffunction, &Deffunction_type, function);
5400
+
5401
+ functionName = DeffunctionName(function);
5402
+ defmoduleName = DeffunctionModule(function);
5403
+ currentDefmoduleName = DefmoduleName(GetCurrentModule(env));
5404
+
5405
+ fcb = CreateFunctionCallBuilder(env, argc);
5406
+
5407
+ for (int i = 0; i < argc; i++) {
5408
+ value = VALUE_to_CLIPSValue(argv[i], env);
5409
+ FCBAppend(fcb, &value);
5410
+ }
5411
+
5412
+ switch(FCBCall(fcb, functionName, &value))
5413
+ {
5414
+ case FCBE_NO_ERROR:
5415
+ break;
5416
+ case FCBE_NULL_POINTER_ERROR:
5417
+ FCBDispose(fcb);
5418
+ rb_raise(rb_eStandardError, "Somehow the FunctionCallBuilder or Deffunction name was NULL\n");
5419
+ break;
5420
+ case FCBE_FUNCTION_NOT_FOUND_ERROR:
5421
+ FCBDispose(fcb);
5422
+ rb_raise(rb_eStandardError, "A function, deffunction, or generic function could not be found with the name %s defined in module %s from the current module %s\n", functionName, defmoduleName, currentDefmoduleName);
5423
+ break;
5424
+ case FCBE_INVALID_FUNCTION_ERROR:
5425
+ FCBDispose(fcb);
5426
+ rb_raise(rb_eStandardError, "The function or command has a specialized parser (such as the assert command) and cannot be invoked.\n");
5427
+ break;
5428
+ case FCBE_ARGUMENT_COUNT_ERROR:
5429
+ FCBDispose(fcb);
5430
+ rb_raise(rb_eStandardError,"The function was passed the incorrect number of arguments.\n");
5431
+ break;
5432
+ case FCBE_ARGUMENT_TYPE_ERROR:
5433
+ FCBDispose(fcb);
5434
+ rb_raise(rb_eStandardError,"The function was passed an argument with an invalid type.\n");
5435
+ break;
5436
+ case FCBE_PROCESSING_ERROR:
5437
+ FCBDispose(fcb);
5438
+ rb_raise(rb_eStandardError,"An error occurred while the function was being evaluated.\n");
5439
+ break;
5440
+ default:
5441
+ FCBDispose(fcb);
5442
+ rb_raise(rb_eStandardError,"Something went wrong calling the deffunction %s\n",functionName);
5443
+ break;
5444
+ }
5445
+
5446
+ FCBDispose(fcb);
5447
+
5448
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
5449
+
5450
+ return out;
5451
+ }
5452
+
5453
+ static VALUE clips_environment_deffunction_static_call(int argc, VALUE *argv, VALUE klass)
5454
+ {
5455
+ return clips_environment_deffunction_call(argc-1, argv+1, argv[0]);
5456
+ }
5457
+
5141
5458
  void Init_clipsruby(void)
5142
5459
  {
5143
5460
  VALUE rbCLIPS = rb_define_module("CLIPS");
@@ -5203,6 +5520,10 @@ void Init_clipsruby(void)
5203
5520
  rb_define_method(rbEnvironment, "find_defclass", clips_environment_find_defclass, 1);
5204
5521
  rb_define_singleton_method(rbEnvironment, "find_instance", clips_environment_static_find_instance, -1);
5205
5522
  rb_define_method(rbEnvironment, "find_instance", clips_environment_find_instance, -1);
5523
+ rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
5524
+ rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
5525
+ rb_define_singleton_method(rbEnvironment, "find_deffunction", clips_environment_static_find_deffunction, 2);
5526
+ rb_define_method(rbEnvironment, "find_deffunction", clips_environment_find_deffunction, 1);
5206
5527
  rb_define_singleton_method(rbEnvironment, "get_current_module", clips_environment_static_get_current_module, 1);
5207
5528
  rb_define_method(rbEnvironment, "get_current_module", clips_environment_get_current_module, 0);
5208
5529
  rb_define_singleton_method(rbEnvironment, "set_current_module", clips_environment_static_set_current_module, 2);
@@ -5221,8 +5542,8 @@ void Init_clipsruby(void)
5221
5542
  rb_define_method(rbEnvironment, "get_defmodule_list", clips_environment_get_defmodule_list, 0);
5222
5543
  rb_define_singleton_method(rbEnvironment, "get_activation_list", clips_environment_static_get_activation_list, 1);
5223
5544
  rb_define_method(rbEnvironment, "get_activation_list", clips_environment_get_activation_list, 0);
5224
- rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
5225
- rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
5545
+ rb_define_singleton_method(rbEnvironment, "get_deffunction_list", clips_environment_static_get_deffunction_list, -1);
5546
+ rb_define_method(rbEnvironment, "get_deffunction_list", clips_environment_get_deffunction_list, -1);
5226
5547
  rb_define_singleton_method(rbEnvironment, "watch", clips_environment_static_watch, 2);
5227
5548
  rb_define_method(rbEnvironment, "watch", clips_environment_watch, 1);
5228
5549
  rb_define_singleton_method(rbEnvironment, "watch_all", clips_environment_static_watch_all, 1);
@@ -5368,6 +5689,8 @@ void Init_clipsruby(void)
5368
5689
  rb_define_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_get_deftemplate_list, 0);
5369
5690
  rb_define_singleton_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_static_get_defrule_list, 1);
5370
5691
  rb_define_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_get_defrule_list, 0);
5692
+ rb_define_singleton_method(rbDefmodule, "get_deffunction_list", clips_environment_defmodule_static_get_deffunction_list, 1);
5693
+ rb_define_method(rbDefmodule, "get_deffunction_list", clips_environment_defmodule_get_deffunction_list, 0);
5371
5694
  rb_define_singleton_method(rbDefmodule, "find_instance", clips_environment_defmodule_static_find_instance, -1);
5372
5695
  rb_define_method(rbDefmodule, "find_instance", clips_environment_defmodule_find_instance, -1);
5373
5696
  rb_define_singleton_method(rbDefmodule, "refresh_agenda", clips_environment_defmodule_static_refresh_agenda, 1);
@@ -5469,4 +5792,19 @@ void Init_clipsruby(void)
5469
5792
  rb_define_method(rbActivation, "pp_form", clips_environment_activation_pp_form, 0);
5470
5793
  rb_define_singleton_method(rbActivation, "delete", clips_environment_activation_static_delete, 1);
5471
5794
  rb_define_method(rbActivation, "delete", clips_environment_activation_delete, 0);
5795
+
5796
+ VALUE rbDeffunction = rb_define_class_under(rbEnvironment, "Deffunction", rb_cObject);
5797
+ rb_define_alloc_func(rbDeffunction, deffunction_alloc);
5798
+ rb_define_singleton_method(rbDeffunction, "name", clips_environment_deffunction_static_name, 1);
5799
+ rb_define_method(rbDeffunction, "name", clips_environment_deffunction_name, 0);
5800
+ rb_define_singleton_method(rbDeffunction, "pp_form", clips_environment_deffunction_static_pp_form, 1);
5801
+ rb_define_method(rbDeffunction, "pp_form", clips_environment_deffunction_pp_form, 0);
5802
+ rb_define_singleton_method(rbDeffunction, "is_deletable", clips_environment_deffunction_static_is_deletable, 1);
5803
+ rb_define_method(rbDeffunction, "is_deletable", clips_environment_deffunction_is_deletable, 0);
5804
+ rb_define_singleton_method(rbDeffunction, "defmodule", clips_environment_deffunction_static_defmodule, 1);
5805
+ rb_define_method(rbDeffunction, "defmodule", clips_environment_deffunction_defmodule, 0);
5806
+ rb_define_singleton_method(rbDeffunction, "defmodule_name", clips_environment_deffunction_static_defmodule_name, 1);
5807
+ rb_define_method(rbDeffunction, "defmodule_name", clips_environment_deffunction_defmodule_name, 0);
5808
+ rb_define_singleton_method(rbDeffunction, "call", clips_environment_deffunction_static_call, -1);
5809
+ rb_define_method(rbDeffunction, "call", clips_environment_deffunction_call, -1);
5472
5810
  }
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.45
4
+ version: 0.0.47
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston