clipsruby 0.0.32 → 0.0.33

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 +90 -0
  3. data/ext/clipsruby/clipsruby.c +249 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d63c4466f611752b18eac8e195f3614784dd64b80ac007457fb550bc88847ee5
4
- data.tar.gz: 353a3eb4fe11406b0b2b704a669b1933b0a3ec4c6c10c4b288cd0bf7b5a1fe58
3
+ metadata.gz: eebbbd0b179f769e1bc079a0cedda8a3ba5198a83347bfb37abc48d6edfe8d41
4
+ data.tar.gz: 9adb9650801d7a7bbd290aac1f3c6666dfe6e2527b2fc022dc6285dfad6756f1
5
5
  SHA512:
6
- metadata.gz: 88e76e4afa90cf21db3718ed033a2463c8f38f5f9c17d3e643b901d4f9d83b36ec0c8d904d311db96cdaf6935b9694982508eebb5326c1eb43977c80660b40d5
7
- data.tar.gz: 48665d09ede14f7707abaf1ad38c8202c12ee0fe655402d257399379e074e367b2bd18b3e3bec704bc5cfdfb280286890f325360384eb5e1d2a93d5ae3c57b0e
6
+ metadata.gz: 840d6111ab2c3b27d764a2bf2dea8b88b447f4730345e1e54ef22f0e3aa64edb21ee362e9c57088cbffc29d561106e28fbfd25acee381ef1d819d3297ae6a279
7
+ data.tar.gz: 4cd8587d33b239d66093cebdf12efda954adc37c620c1112a35295771f7ea3ccc74415e2a7303d7581fe0494c577f9200512f7a59d898c4e8077105b7157d099
data/README.md CHANGED
@@ -155,6 +155,16 @@ fact = CLIPS::Environment.assert_hash(env, :my_deftemplate, a: 1, b: "asdf", c:
155
155
  fact2 = env.assert_hash(:my_deftemplate, d: 4.5, e: :asdf)
156
156
  ```
157
157
 
158
+ ### `CLIPS::Environment.make_instance`
159
+ ### `CLIPS::Environment#make_instance`
160
+
161
+ Make a string as an Instance in the CLIPS environment.
162
+
163
+ ```ruby
164
+ instance = CLIPS::Environment.make_instance(env, "(of USER)")
165
+ instance2 = env.make_instance("(of USER)")
166
+ ```
167
+
158
168
  ### `CLIPS::Environment.find_fact`
159
169
  ### `CLIPS::Environment#find_fact`
160
170
 
@@ -404,6 +414,86 @@ CLIPS::Environment::Fact.modify(fact, bar: 123)
404
414
  fact.modify(foo: "my new foo!")
405
415
  ```
406
416
 
417
+ ### `CLIPS::Environment::Instance.unmake`
418
+ ### `CLIPS::Environment::Instance#unmake`
419
+
420
+ Unmakes an instance in the environment, deleting it.
421
+
422
+ ```ruby
423
+ CLIPS::Environment::Instance.unmake(instance)
424
+ instance.unmake
425
+ ```
426
+
427
+ ### `CLIPS::Environment::Instance.delete`
428
+ ### `CLIPS::Environment::Instance#delete`
429
+
430
+ Deletes an instance in the environment.
431
+
432
+ ```ruby
433
+ CLIPS::Environment::Instance.delete(instance)
434
+ instance.delete
435
+ ```
436
+
437
+ ### `CLIPS::Environment::Instance.name`
438
+ ### `CLIPS::Environment::Instance#name`
439
+
440
+ Returns the name of an Instance as a symbol
441
+
442
+ ```ruby
443
+ CLIPS::Environment::Instance.name(instance)
444
+ instance.name
445
+ ```
446
+
447
+ ### `CLIPS::Environment::Instance.pp_form`
448
+ ### `CLIPS::Environment::Instance#pp_form`
449
+
450
+ Returns a pretty printed string representation of an Instance
451
+
452
+ ```ruby
453
+ CLIPS::Environment::Instance.pp_form(instance)
454
+ instance.pp_form
455
+ ```
456
+
457
+ ### `CLIPS::Environment::Instance._class`
458
+ ### `CLIPS::Environment::Instance#_class`
459
+
460
+ Returns the Defclass of an Instance
461
+
462
+ ```ruby
463
+ CLIPS::Environment::Instance._class(instance)
464
+ instance._class
465
+ ```
466
+
467
+ ### `CLIPS::Environment::Defclass.name`
468
+ ### `CLIPS::Environment::Defclass#name`
469
+
470
+ Returns the name of an Defclass as a symbol
471
+
472
+ ```ruby
473
+ CLIPS::Environment::Defclass.name(defclass)
474
+ defclass.name
475
+ ```
476
+
477
+ ### `CLIPS::Environment::Defclass.pp_form`
478
+ ### `CLIPS::Environment::Defclass#pp_form`
479
+
480
+ Returns a pretty printed string representation of an Defclass
481
+
482
+ ```ruby
483
+ CLIPS::Environment::Defclass.pp_form(defclass)
484
+ defclass.pp_form
485
+ ```
486
+
487
+ ### `CLIPS::Environment::Defclass.defmodule_name`
488
+ ### `CLIPS::Environment::Defclass#defmodule_name`
489
+
490
+ Returns the name of the defmodule in which the defclass is defined
491
+
492
+ ```ruby
493
+ CLIPS::Environment::Defclass.defmodule_name(defclass)
494
+ defclass.defmodule_name
495
+ ```
496
+
407
497
  ### `CLIPS::Environment.find_defrule`
408
498
  ### `CLIPS::Environment#find_defrule`
409
499
 
@@ -37,7 +37,6 @@ static const rb_data_type_t Defmodule_type = {
37
37
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
38
38
  };
39
39
 
40
-
41
40
  size_t defrule_size(const void *data)
42
41
  {
43
42
  return sizeof(Defrule);
@@ -50,6 +49,18 @@ static const rb_data_type_t Defrule_type = {
50
49
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
51
50
  };
52
51
 
52
+ size_t defclass_size(const void *data)
53
+ {
54
+ return sizeof(Defclass);
55
+ }
56
+
57
+ static const rb_data_type_t Defclass_type = {
58
+ .function = {
59
+ .dsize = defclass_size
60
+ },
61
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
62
+ };
63
+
53
64
  size_t fact_size(const void *data)
54
65
  {
55
66
  return sizeof(Fact);
@@ -62,6 +73,18 @@ static const rb_data_type_t Fact_type = {
62
73
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
63
74
  };
64
75
 
76
+ size_t instance_size(const void *data)
77
+ {
78
+ return sizeof(Instance);
79
+ }
80
+
81
+ static const rb_data_type_t Instance_type = {
82
+ .function = {
83
+ .dsize = instance_size
84
+ },
85
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
86
+ };
87
+
65
88
  static VALUE clips_environment_fact_deftemplate(VALUE self)
66
89
  {
67
90
  VALUE rbDeftemplate, rbEnvironment;
@@ -173,6 +196,11 @@ VALUE deftemplate_alloc(VALUE self)
173
196
  return TypedData_Wrap_Struct(self, &Deftemplate_type, NULL);
174
197
  }
175
198
 
199
+ VALUE defclass_alloc(VALUE self)
200
+ {
201
+ return TypedData_Wrap_Struct(self, &Defclass_type, NULL);
202
+ }
203
+
176
204
  VALUE defrule_alloc(VALUE self)
177
205
  {
178
206
  return TypedData_Wrap_Struct(self, &Defrule_type, NULL);
@@ -183,6 +211,11 @@ VALUE fact_alloc(VALUE self)
183
211
  return TypedData_Wrap_Struct(self, &Fact_type, NULL);
184
212
  }
185
213
 
214
+ VALUE instance_alloc(VALUE self)
215
+ {
216
+ return TypedData_Wrap_Struct(self, &Instance_type, NULL);
217
+ }
218
+
186
219
  VALUE environment_alloc(VALUE self)
187
220
  {
188
221
  return TypedData_Wrap_Struct(self, &Environment_type, CreateEnvironment());
@@ -218,6 +251,199 @@ static VALUE clips_environment_static_assert_string(VALUE self, VALUE rbEnvironm
218
251
  return clips_environment_assert_string(rbEnvironment, string);
219
252
  }
220
253
 
254
+ static VALUE clips_environment_defclass_name(VALUE self)
255
+ {
256
+ Defclass *defclass;
257
+
258
+ TypedData_Get_Struct(self, Defclass, &Defclass_type, defclass);
259
+
260
+ return ID2SYM(rb_intern(DefclassName(defclass)));
261
+ }
262
+
263
+ static VALUE clips_environment_defclass_static_name(VALUE self, VALUE rbDefclass)
264
+ {
265
+ return clips_environment_defclass_name(rbDefclass);
266
+ }
267
+
268
+ static VALUE clips_environment_defclass_defmodule_name(VALUE self)
269
+ {
270
+ Defclass *defclass;
271
+
272
+ TypedData_Get_Struct(self, Defclass, &Defclass_type, defclass);
273
+
274
+ return ID2SYM(rb_intern(DefclassModule(defclass)));
275
+ }
276
+
277
+ static VALUE clips_environment_defclass_static_defmodule_name(VALUE self, VALUE rbDefclass)
278
+ {
279
+ return clips_environment_defclass_defmodule_name(rbDefclass);
280
+ }
281
+
282
+ static VALUE clips_environment_defclass_pp_form(VALUE self)
283
+ {
284
+ Defclass *defclass;
285
+
286
+ TypedData_Get_Struct(self, Defclass, &Defclass_type, defclass);
287
+
288
+ return rb_str_new2(DefclassPPForm(defclass));
289
+ }
290
+
291
+ static VALUE clips_environment_defclass_static_pp_form(VALUE self, VALUE rbDefclass)
292
+ {
293
+ return clips_environment_defclass_pp_form(rbDefclass);
294
+ }
295
+
296
+ static VALUE clips_environment_make_instance(VALUE self, VALUE string)
297
+ {
298
+ Environment *env;
299
+
300
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
301
+
302
+ Instance *instance = MakeInstance(env, StringValueCStr(string));
303
+
304
+ if (instance == NULL) {
305
+ return Qnil;
306
+ }
307
+
308
+ VALUE rb_instance =
309
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Instance")), &Instance_type, instance);
310
+
311
+ rb_iv_set(rb_instance, "@environment", self);
312
+
313
+ return rb_instance;
314
+ }
315
+
316
+ static VALUE clips_environment_static_make_instance(VALUE self, VALUE rbEnvironment, VALUE string)
317
+ {
318
+ return clips_environment_make_instance(rbEnvironment, string);
319
+ }
320
+
321
+ static VALUE clips_environment_instance_unmake(VALUE self)
322
+ {
323
+ Instance *instance;
324
+
325
+ TypedData_Get_Struct(self, Instance, &Instance_type, instance);
326
+
327
+ switch (UnmakeInstance(instance)) {
328
+ case UIE_NO_ERROR:
329
+ break;
330
+ case UIE_NULL_POINTER_ERROR:
331
+ rb_warn("could not unmake instance; null pointer error. This could be a bug in clipsruby!");
332
+ return Qfalse;
333
+ case UIE_COULD_NOT_DELETE_ERROR:
334
+ rb_warn("could not unmake instance! is pattern matching currently happening with this instance?");
335
+ return Qfalse;
336
+ case UIE_DELETED_ERROR:
337
+ rb_warn("could not unmake instance! instance is already deleted");
338
+ return Qfalse;
339
+ case UIE_RULE_NETWORK_ERROR:
340
+ rb_warn("could not unmake instance! An error occurs while the unmaking was being processed in the rule network");
341
+ return Qfalse;
342
+ }
343
+
344
+ return Qtrue;
345
+ }
346
+
347
+ static VALUE clips_environment_instance_static_unmake(VALUE self, VALUE rbInstance)
348
+ {
349
+ return clips_environment_instance_unmake(rbInstance);
350
+ }
351
+
352
+ static VALUE clips_environment_instance_delete(VALUE self)
353
+ {
354
+ Instance *instance;
355
+
356
+ TypedData_Get_Struct(self, Instance, &Instance_type, instance);
357
+
358
+ switch (DeleteInstance(instance)) {
359
+ case UIE_NO_ERROR:
360
+ break;
361
+ case UIE_NULL_POINTER_ERROR:
362
+ rb_warn("could not delete instance; null pointer error. This could be a bug in clipsruby!");
363
+ return Qfalse;
364
+ case UIE_COULD_NOT_DELETE_ERROR:
365
+ rb_warn("could not delete instance! is pattern matching currently happening with this instance?");
366
+ return Qfalse;
367
+ case UIE_DELETED_ERROR:
368
+ rb_warn("could not delete instance! instance is already deleted");
369
+ return Qfalse;
370
+ case UIE_RULE_NETWORK_ERROR:
371
+ rb_warn("could not delete instance! An error occurs while the unmaking was being processed in the rule network");
372
+ return Qfalse;
373
+ }
374
+
375
+ return Qtrue;
376
+ }
377
+
378
+ static VALUE clips_environment_instance_static_delete(VALUE self, VALUE rbInstance)
379
+ {
380
+ return clips_environment_instance_delete(rbInstance);
381
+ }
382
+
383
+ static VALUE clips_environment_instance_class(VALUE self)
384
+ {
385
+ Defclass *defclass;
386
+ Instance *instance;
387
+ VALUE rbEnvironment, rb_defclass;
388
+
389
+ rbEnvironment = rb_iv_get(self, "@environment");
390
+
391
+ TypedData_Get_Struct(self, Instance, &Instance_type, instance);
392
+
393
+ defclass = InstanceClass(instance);
394
+
395
+ rb_defclass =
396
+ TypedData_Wrap_Struct(rb_const_get(rb_obj_class(rbEnvironment), rb_intern("Defclass")), &Defclass_type, defclass);
397
+
398
+ rb_iv_set(rb_defclass, "@environment", rbEnvironment);
399
+
400
+ return rb_defclass;
401
+ }
402
+
403
+ static VALUE clips_environment_instance_static_class(VALUE self, VALUE rbInstance)
404
+ {
405
+ return clips_environment_instance_class(rbInstance);
406
+ }
407
+
408
+ static VALUE clips_environment_instance_name(VALUE self)
409
+ {
410
+ Instance *instance;
411
+
412
+ TypedData_Get_Struct(self, Instance, &Instance_type, instance);
413
+
414
+ return ID2SYM(rb_intern(InstanceName(instance)));
415
+ }
416
+
417
+ static VALUE clips_environment_instance_static_name(VALUE self, VALUE rbInstance)
418
+ {
419
+ return clips_environment_instance_name(rbInstance);
420
+ }
421
+
422
+ static VALUE clips_environment_instance_pp_form(VALUE self)
423
+ {
424
+ Environment *env;
425
+ Instance *instance;
426
+ StringBuilder *sb;
427
+ VALUE toReturn;
428
+
429
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
430
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
431
+ sb = CreateStringBuilder(env, 0);
432
+
433
+ TypedData_Get_Struct(self, Instance, &Instance_type, instance);
434
+
435
+ InstancePPForm(instance, sb);
436
+ toReturn = rb_str_new2(sb->contents);
437
+ SBDispose(sb);
438
+
439
+ return toReturn;
440
+ }
441
+
442
+ static VALUE clips_environment_instance_static_pp_form(VALUE self, VALUE rbInstance)
443
+ {
444
+ return clips_environment_instance_pp_form(rbInstance);
445
+ }
446
+
221
447
  static VALUE clips_environment_build(VALUE self, VALUE string)
222
448
  {
223
449
  Environment *env;
@@ -3232,6 +3458,8 @@ void Init_clipsruby(void)
3232
3458
  rb_define_method(rbEnvironment, "unwatch_focus", clips_environment_unwatch_focus, 0);
3233
3459
  rb_define_singleton_method(rbEnvironment, "get_watch_state", clips_environment_static_get_watch_state, 2);
3234
3460
  rb_define_method(rbEnvironment, "get_watch_state", clips_environment_get_watch_state, 1);
3461
+ rb_define_singleton_method(rbEnvironment, "make_instance", clips_environment_static_make_instance, 2);
3462
+ rb_define_method(rbEnvironment, "make_instance", clips_environment_make_instance, 1);
3235
3463
 
3236
3464
  VALUE rbDeffacts = rb_define_class_under(rbEnvironment, "Deffacts", rb_cObject);
3237
3465
  rb_define_alloc_func(rbDeffacts, deffacts_alloc);
@@ -3332,5 +3560,25 @@ void Init_clipsruby(void)
3332
3560
  rb_define_singleton_method(rbDefrule, "defmodule_name", clips_environment_defrule_static_defmodule_name, 1);
3333
3561
  rb_define_method(rbDefrule, "defmodule_name", clips_environment_defrule_defmodule_name, 0);
3334
3562
 
3563
+ VALUE rbDefclass = rb_define_class_under(rbEnvironment, "Defclass", rb_cObject);
3564
+ rb_define_alloc_func(rbDefclass, defclass_alloc);
3565
+ rb_define_singleton_method(rbDefclass, "name", clips_environment_defclass_static_name, 1);
3566
+ rb_define_method(rbDefclass, "name", clips_environment_defclass_name, 0);
3567
+ rb_define_singleton_method(rbDefclass, "defmodule_name", clips_environment_defclass_static_defmodule_name, 1);
3568
+ rb_define_method(rbDefclass, "defmodule_name", clips_environment_defclass_defmodule_name, 0);
3569
+ rb_define_singleton_method(rbDefclass, "pp_form", clips_environment_defclass_static_pp_form, 1);
3570
+ rb_define_method(rbDefclass, "pp_form", clips_environment_defclass_pp_form, 0);
3571
+
3335
3572
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
3573
+ rb_define_alloc_func(rbInstance, instance_alloc);
3574
+ rb_define_singleton_method(rbInstance, "unmake", clips_environment_instance_static_unmake, 1);
3575
+ rb_define_method(rbInstance, "unmake", clips_environment_instance_unmake, 0);
3576
+ rb_define_singleton_method(rbInstance, "delete", clips_environment_instance_static_delete, 1);
3577
+ rb_define_method(rbInstance, "delete", clips_environment_instance_delete, 0);
3578
+ rb_define_singleton_method(rbInstance, "_class", clips_environment_instance_static_class, 1);
3579
+ rb_define_method(rbInstance, "_class", clips_environment_instance_class, 0);
3580
+ rb_define_singleton_method(rbInstance, "name", clips_environment_instance_static_name, 1);
3581
+ rb_define_method(rbInstance, "name", clips_environment_instance_name, 0);
3582
+ rb_define_singleton_method(rbInstance, "pp_form", clips_environment_instance_static_pp_form, 1);
3583
+ rb_define_method(rbInstance, "pp_form", clips_environment_instance_pp_form, 0);
3336
3584
  }
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.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston