clipsruby 0.0.31 → 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 +100 -0
  3. data/ext/clipsruby/clipsruby.c +264 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e60b635195b3e8fb7375f1f93d4fa5c8459c6eb5c3ed22e9e189029382e74da8
4
- data.tar.gz: a641f8b2fbbdeca662101ab05ad0dbd6b8fe4688c2ad6ba73f04a2de93badacc
3
+ metadata.gz: eebbbd0b179f769e1bc079a0cedda8a3ba5198a83347bfb37abc48d6edfe8d41
4
+ data.tar.gz: 9adb9650801d7a7bbd290aac1f3c6666dfe6e2527b2fc022dc6285dfad6756f1
5
5
  SHA512:
6
- metadata.gz: e7a266cd73117d6497c4c93d141311ceaaaff17550ba753af0eaa98c8051cac3b0ea44d36c4d796da5982354ba417b38a937a49e68992add8e290cbbb22811ab
7
- data.tar.gz: 82822e678d0342232792fc5ffb8d451e54d2e9e8cce877bdf5d8fa231c045a2477621c82d9b6d17967502d8135b6a5d1049a3539b6f8b84b82669bc4b493c312
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
 
@@ -424,6 +514,16 @@ CLIPS::Environment::Defrule.name(defrule)
424
514
  defrule.name
425
515
  ```
426
516
 
517
+ ### `CLIPS::Environment::Defrule.defmodule_name`
518
+ ### `CLIPS::Environment::Defrule#defmodule_name`
519
+
520
+ Returns the name of the defmodule in which the defrule is defined
521
+
522
+ ```ruby
523
+ CLIPS::Environment::Defrule.defmodule_name(defrule)
524
+ defrule.defmodule_name
525
+ ```
526
+
427
527
  ### `CLIPS::Environment::Defrule.is_deletable`
428
528
  ### `CLIPS::Environment::Defrule#is_deletable`
429
529
 
@@ -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;
@@ -110,6 +133,19 @@ static VALUE clips_environment_deftemplate_static_defmodule_name(VALUE self, VAL
110
133
  return clips_environment_deftemplate_defmodule_name(rbDeftemplate);
111
134
  }
112
135
 
136
+ static VALUE clips_environment_defrule_defmodule_name(VALUE self)
137
+ {
138
+ Defrule *rule;
139
+
140
+ TypedData_Get_Struct(self, Defrule, &Defrule_type, rule);
141
+
142
+ return ID2SYM(rb_intern(DefruleModule(rule)));
143
+ }
144
+
145
+ static VALUE clips_environment_defrule_static_defmodule_name(VALUE self, VALUE rbDefrule)
146
+ {
147
+ return clips_environment_defrule_defmodule_name(rbDefrule);
148
+ }
113
149
 
114
150
  void environment_free(void *data)
115
151
  {
@@ -160,6 +196,11 @@ VALUE deftemplate_alloc(VALUE self)
160
196
  return TypedData_Wrap_Struct(self, &Deftemplate_type, NULL);
161
197
  }
162
198
 
199
+ VALUE defclass_alloc(VALUE self)
200
+ {
201
+ return TypedData_Wrap_Struct(self, &Defclass_type, NULL);
202
+ }
203
+
163
204
  VALUE defrule_alloc(VALUE self)
164
205
  {
165
206
  return TypedData_Wrap_Struct(self, &Defrule_type, NULL);
@@ -170,6 +211,11 @@ VALUE fact_alloc(VALUE self)
170
211
  return TypedData_Wrap_Struct(self, &Fact_type, NULL);
171
212
  }
172
213
 
214
+ VALUE instance_alloc(VALUE self)
215
+ {
216
+ return TypedData_Wrap_Struct(self, &Instance_type, NULL);
217
+ }
218
+
173
219
  VALUE environment_alloc(VALUE self)
174
220
  {
175
221
  return TypedData_Wrap_Struct(self, &Environment_type, CreateEnvironment());
@@ -205,6 +251,199 @@ static VALUE clips_environment_static_assert_string(VALUE self, VALUE rbEnvironm
205
251
  return clips_environment_assert_string(rbEnvironment, string);
206
252
  }
207
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
+
208
447
  static VALUE clips_environment_build(VALUE self, VALUE string)
209
448
  {
210
449
  Environment *env;
@@ -3219,6 +3458,8 @@ void Init_clipsruby(void)
3219
3458
  rb_define_method(rbEnvironment, "unwatch_focus", clips_environment_unwatch_focus, 0);
3220
3459
  rb_define_singleton_method(rbEnvironment, "get_watch_state", clips_environment_static_get_watch_state, 2);
3221
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);
3222
3463
 
3223
3464
  VALUE rbDeffacts = rb_define_class_under(rbEnvironment, "Deffacts", rb_cObject);
3224
3465
  rb_define_alloc_func(rbDeffacts, deffacts_alloc);
@@ -3316,6 +3557,28 @@ void Init_clipsruby(void)
3316
3557
  rb_define_method(rbDefrule, "remove_break", clips_environment_defrule_remove_break, 0);
3317
3558
  rb_define_singleton_method(rbDefrule, "salience", clips_environment_defrule_static_salience, 1);
3318
3559
  rb_define_method(rbDefrule, "salience", clips_environment_defrule_salience, 0);
3560
+ rb_define_singleton_method(rbDefrule, "defmodule_name", clips_environment_defrule_static_defmodule_name, 1);
3561
+ rb_define_method(rbDefrule, "defmodule_name", clips_environment_defrule_defmodule_name, 0);
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);
3319
3571
 
3320
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);
3321
3584
  }
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.31
4
+ version: 0.0.33
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-24 00:00:00.000000000 Z
11
+ date: 2024-09-25 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