clips-bindings 0.1.2+clips-6.4.2

Safe, idiomatic, custom-written Rust bindings for the CLIPS 6.4.2 embedding API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
//! Private declarations for the CLIPS 6.4.2 C ABI.
//!
//! Nothing here is public. Layouts are verified in `src/abi.rs` and the
//! signatures are audited against the 6.4.2 headers.

use std::ffi::{c_char, c_void};

pub type RouterQuery = unsafe extern "C" fn(*mut Environment, *const c_char, *mut c_void) -> bool;
pub type RouterWrite =
    unsafe extern "C" fn(*mut Environment, *const c_char, *const c_char, *mut c_void);
pub type RouterRead =
    unsafe extern "C" fn(*mut Environment, *const c_char, *mut c_void) -> std::ffi::c_int;
pub type RouterUnread = unsafe extern "C" fn(
    *mut Environment,
    *const c_char,
    std::ffi::c_int,
    *mut c_void,
) -> std::ffi::c_int;
pub type RouterExit = unsafe extern "C" fn(*mut Environment, std::ffi::c_int, *mut c_void);

#[repr(C)]
pub struct Environment {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct Fact {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct FactBuilder {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct Instance {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct InstanceBuilder {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct MultifieldBuilder {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct FunctionCallBuilder {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct FactModifier {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct InstanceModifier {
    _opaque: [u8; 0],
}
macro_rules! opaque_construct {
    ($($name:ident),+ $(,)?) => { $(#[repr(C)] pub struct $name { _opaque: [u8; 0] })+ };
}
opaque_construct!(
    Deftemplate,
    Defrule,
    Deffacts,
    Defglobal,
    Deffunction,
    Defgeneric,
    Defclass,
    Definstances,
    Defmodule
);
#[repr(C)]
pub struct Defmethod {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct Activation {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct FocalModule {
    _opaque: [u8; 0],
}
#[repr(C)]
pub struct UDFContext {
    pub environment: *mut Environment,
    pub context: *mut c_void,
    pub the_function: *mut c_void,
    pub last_position: u32,
    pub last_arg: *mut c_void,
    pub return_value: *mut UDFValue,
}
#[repr(C)]
pub struct UDFValue {
    pub supplemental_info: *mut c_void,
    pub value: CLIPSValue,
    pub begin: usize,
    pub range: usize,
    pub next: *mut UDFValue,
}
pub type UserDefinedFunction =
    unsafe extern "C" fn(*mut Environment, *mut UDFContext, *mut UDFValue);
pub type VoidCallFunction = unsafe extern "C" fn(*mut Environment, *mut c_void);
pub type BoolCallFunction = unsafe extern "C" fn(*mut Environment, *mut c_void) -> bool;
pub type RuleFiredFunction = unsafe extern "C" fn(*mut Environment, *mut Activation, *mut c_void);
/// Called as `(environment, subject, context)`; the assert and retract hooks
/// pass the fact as the subject.
pub type VoidCallFunctionWithArg = unsafe extern "C" fn(*mut Environment, *mut c_void, *mut c_void);
pub type ModifyCallFunction =
    unsafe extern "C" fn(*mut Environment, *mut Fact, *mut Fact, *mut c_void);
pub type SaveCallFunction =
    unsafe extern "C" fn(*mut Environment, *mut Defmodule, *const c_char, *mut c_void);
pub type ParserErrorFunction = unsafe extern "C" fn(
    *mut Environment,
    *const c_char,
    *const c_char,
    *const c_char,
    std::ffi::c_long,
    *mut c_void,
);

#[repr(C)]
pub struct TypeHeader {
    pub type_: u16,
}

#[repr(C)]
pub union CLIPSValue {
    pub value: *mut c_void,
    pub header: *mut TypeHeader,
    pub integer: *mut CLIPSInteger,
    pub float: *mut CLIPSFloat,
    pub lexeme: *mut CLIPSLexeme,
    pub multifield: *mut Multifield,
    pub fact: *mut Fact,
    pub instance: *mut Instance,
}
impl Copy for CLIPSValue {}
impl Clone for CLIPSValue {
    fn clone(&self) -> Self {
        *self
    }
}

#[repr(C)]
pub struct CLIPSInteger {
    pub header: TypeHeader,
    pub next: *mut CLIPSInteger,
    pub count: std::ffi::c_long,
    pub flags: u32,
    pub contents: i64,
}

#[repr(C)]
pub struct CLIPSFloat {
    pub header: TypeHeader,
    pub next: *mut CLIPSFloat,
    pub count: std::ffi::c_long,
    pub flags: u32,
    pub contents: f64,
}

#[repr(C)]
pub struct CLIPSLexeme {
    pub header: TypeHeader,
    pub next: *mut CLIPSLexeme,
    pub count: std::ffi::c_long,
    pub flags: u32,
    pub contents: *const c_char,
}

#[repr(C)]
pub struct Multifield {
    pub header: TypeHeader,
    pub busy_count: u32,
    pub length: usize,
    pub next: *mut Multifield,
    pub contents: [CLIPSValue; 1],
}

unsafe extern "C" {
    pub fn CreateEnvironment() -> *mut Environment;
    pub fn DestroyEnvironment(environment: *mut Environment) -> bool;
    pub fn Clear(environment: *mut Environment) -> bool;
    pub fn Reset(environment: *mut Environment);
    pub fn Run(environment: *mut Environment, limit: i64) -> i64;
    pub fn Build(environment: *mut Environment, construct: *const c_char) -> u32;
    pub fn Eval(
        environment: *mut Environment,
        expression: *const c_char,
        value: *mut CLIPSValue,
    ) -> u32;
    pub fn Load(environment: *mut Environment, path: *const c_char) -> u32;
    /// Unlike `Load`, this reports success as a bool rather than a `LoadError`.
    pub fn LoadFromString(
        environment: *mut Environment,
        source: *const c_char,
        length: usize,
    ) -> bool;
    pub fn RetainCV(environment: *mut Environment, value: *mut CLIPSValue);
    pub fn ReleaseCV(environment: *mut Environment, value: *mut CLIPSValue);

    pub fn GetHaltExecution(environment: *mut Environment) -> bool;
    pub fn SetHaltExecution(environment: *mut Environment, halt: bool);
    pub fn GetHaltRules(environment: *mut Environment) -> bool;
    pub fn SetHaltRules(environment: *mut Environment, halt: bool);
    pub fn GetBetaMemoryResizing(environment: *mut Environment) -> bool;
    /// Returns the previous setting.
    pub fn SetBetaMemoryResizing(environment: *mut Environment, resize: bool) -> bool;

    pub fn Write(environment: *mut Environment, text: *const c_char);
    pub fn Writeln(environment: *mut Environment, text: *const c_char);
    pub fn WriteString(
        environment: *mut Environment,
        logical_name: *const c_char,
        text: *const c_char,
    );

    pub fn AssertString(environment: *mut Environment, fact: *const c_char) -> *mut Fact;
    pub fn GetAssertStringError(environment: *mut Environment) -> u32;
    pub fn Retract(fact: *mut Fact) -> u32;
    pub fn FactIndex(fact: *mut Fact) -> i64;
    pub fn FactIsDeleted(environment: *mut Environment, fact: *mut Fact) -> bool;
    pub fn GetNextFact(environment: *mut Environment, fact: *mut Fact) -> *mut Fact;
    pub fn GetNumberOfFacts(environment: *mut Environment) -> std::ffi::c_ulong;
    pub fn RetainFact(fact: *mut Fact);
    pub fn ReleaseFact(fact: *mut Fact);
    pub fn FactPPForm(fact: *mut Fact, builder: *mut StringBuilder, ignore_defaults: bool);
    pub fn GetFactSlot(fact: *mut Fact, slot: *const c_char, value: *mut CLIPSValue) -> u32;

    pub fn FactRelation(fact: *mut Fact) -> *mut CLIPSLexeme;
    pub fn FactDeftemplate(fact: *mut Fact) -> *mut Deftemplate;
    pub fn FactSlotNames(fact: *mut Fact, value: *mut CLIPSValue);
    pub fn FindIndexedFact(environment: *mut Environment, index: i64) -> *mut Fact;
    pub fn GetNextFactInTemplate(template: *mut Deftemplate, fact: *mut Fact) -> *mut Fact;
    pub fn GetFactListChanged(environment: *mut Environment) -> bool;
    pub fn SetFactListChanged(environment: *mut Environment, changed: bool);
    pub fn RetractAllFacts(environment: *mut Environment) -> u32;

    pub fn CreateFactBuilder(
        environment: *mut Environment,
        template: *const c_char,
    ) -> *mut FactBuilder;
    pub fn FBPutSlotInteger(builder: *mut FactBuilder, slot: *const c_char, value: i64) -> u32;
    pub fn FBPutSlotFloat(builder: *mut FactBuilder, slot: *const c_char, value: f64) -> u32;
    pub fn FBPutSlotSymbol(
        builder: *mut FactBuilder,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn FBPutSlotString(
        builder: *mut FactBuilder,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn FBPutSlotInstanceName(
        builder: *mut FactBuilder,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn FBPutSlotFact(builder: *mut FactBuilder, slot: *const c_char, value: *mut Fact) -> u32;
    pub fn FBPutSlotInstance(
        builder: *mut FactBuilder,
        slot: *const c_char,
        value: *mut Instance,
    ) -> u32;
    pub fn FBPutSlotMultifield(
        builder: *mut FactBuilder,
        slot: *const c_char,
        value: *mut Multifield,
    ) -> u32;
    pub fn FBPutSlot(builder: *mut FactBuilder, slot: *const c_char, value: *mut CLIPSValue)
    -> u32;
    pub fn FBAssert(builder: *mut FactBuilder) -> *mut Fact;
    pub fn FBError(environment: *mut Environment) -> u32;
    pub fn FBAbort(builder: *mut FactBuilder);
    pub fn FBDispose(builder: *mut FactBuilder);

    pub fn CreateStringBuilder(environment: *mut Environment, size: usize) -> *mut StringBuilder;
    pub fn SBDispose(builder: *mut StringBuilder);

    pub fn CreateInstanceBuilder(
        environment: *mut Environment,
        class: *const c_char,
    ) -> *mut InstanceBuilder;
    pub fn IBPutSlotInteger(builder: *mut InstanceBuilder, slot: *const c_char, value: i64) -> u32;
    pub fn IBPutSlotFloat(builder: *mut InstanceBuilder, slot: *const c_char, value: f64) -> u32;
    pub fn IBPutSlotSymbol(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn IBPutSlotString(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn IBPutSlotInstanceName(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn IBPutSlotFact(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *mut Fact,
    ) -> u32;
    pub fn IBPutSlotInstance(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *mut Instance,
    ) -> u32;
    pub fn IBPutSlotMultifield(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *mut Multifield,
    ) -> u32;
    pub fn IBPutSlot(
        builder: *mut InstanceBuilder,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> u32;
    pub fn IBMake(builder: *mut InstanceBuilder, name: *const c_char) -> *mut Instance;
    pub fn IBError(environment: *mut Environment) -> u32;
    pub fn IBAbort(builder: *mut InstanceBuilder);
    pub fn IBDispose(builder: *mut InstanceBuilder);
    pub fn RetainInstance(instance: *mut Instance);
    pub fn ReleaseInstance(instance: *mut Instance);
    pub fn InstanceName(instance: *mut Instance) -> *const c_char;
    pub fn InstanceIsDeleted(environment: *mut Environment, instance: *mut Instance) -> bool;
    pub fn UnmakeInstance(instance: *mut Instance) -> u32;
    pub fn UnmakeAllInstances(environment: *mut Environment) -> u32;
    pub fn GetGlobalNumberOfInstances(environment: *mut Environment) -> std::ffi::c_ulong;
    pub fn GetInstancesChanged(environment: *mut Environment) -> bool;
    pub fn SetInstancesChanged(environment: *mut Environment, changed: bool);
    pub fn GetNextInstance(environment: *mut Environment, instance: *mut Instance)
    -> *mut Instance;
    pub fn InstancePPForm(instance: *mut Instance, builder: *mut StringBuilder);
    pub fn DirectGetSlot(
        instance: *mut Instance,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> u32;

    pub fn MakeInstance(environment: *mut Environment, source: *const c_char) -> *mut Instance;
    pub fn GetMakeInstanceError(environment: *mut Environment) -> u32;
    pub fn FindInstance(
        environment: *mut Environment,
        module: *mut Defmodule,
        name: *const c_char,
        search_imports: bool,
    ) -> *mut Instance;
    pub fn InstanceClass(instance: *mut Instance) -> *mut Defclass;
    pub fn GetNextInstanceInClass(class: *mut Defclass, instance: *mut Instance) -> *mut Instance;
    pub fn DirectPutSlot(
        instance: *mut Instance,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> u32;
    pub fn DirectPutSlotInteger(instance: *mut Instance, slot: *const c_char, value: i64) -> u32;
    pub fn DirectPutSlotFloat(instance: *mut Instance, slot: *const c_char, value: f64) -> u32;
    pub fn DirectPutSlotSymbol(
        instance: *mut Instance,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn DirectPutSlotString(
        instance: *mut Instance,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn DirectPutSlotInstanceName(
        instance: *mut Instance,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn DirectPutSlotFact(instance: *mut Instance, slot: *const c_char, value: *mut Fact)
    -> u32;
    pub fn DirectPutSlotInstance(
        instance: *mut Instance,
        slot: *const c_char,
        value: *mut Instance,
    ) -> u32;
    pub fn DirectPutSlotMultifield(
        instance: *mut Instance,
        slot: *const c_char,
        value: *mut Multifield,
    ) -> u32;

    pub fn CreateMultifieldBuilder(
        environment: *mut Environment,
        size: usize,
    ) -> *mut MultifieldBuilder;
    pub fn MBAppendInteger(builder: *mut MultifieldBuilder, value: i64);
    pub fn MBAppendFloat(builder: *mut MultifieldBuilder, value: f64);
    pub fn MBAppendSymbol(builder: *mut MultifieldBuilder, value: *const c_char);
    pub fn MBAppendString(builder: *mut MultifieldBuilder, value: *const c_char);
    pub fn MBAppendInstanceName(builder: *mut MultifieldBuilder, value: *const c_char);
    pub fn MBAppendFact(builder: *mut MultifieldBuilder, value: *mut Fact);
    pub fn MBAppendInstance(builder: *mut MultifieldBuilder, value: *mut Instance);
    pub fn MBAppendMultifield(builder: *mut MultifieldBuilder, value: *mut Multifield);
    pub fn MBAppend(builder: *mut MultifieldBuilder, value: *mut CLIPSValue);
    pub fn MBCreate(builder: *mut MultifieldBuilder) -> *mut Multifield;
    pub fn StringToMultifield(
        environment: *mut Environment,
        source: *const c_char,
    ) -> *mut Multifield;
    pub fn ImplodeMultifield(
        environment: *mut Environment,
        value: *mut UDFValue,
    ) -> *mut CLIPSLexeme;
    pub fn MBReset(builder: *mut MultifieldBuilder);
    pub fn MBDispose(builder: *mut MultifieldBuilder);

    pub fn CreateFunctionCallBuilder(
        environment: *mut Environment,
        size: usize,
    ) -> *mut FunctionCallBuilder;
    pub fn FCBAppendInteger(builder: *mut FunctionCallBuilder, value: i64);
    pub fn FCBAppendFloat(builder: *mut FunctionCallBuilder, value: f64);
    pub fn FCBAppendSymbol(builder: *mut FunctionCallBuilder, value: *const c_char);
    pub fn FCBAppendString(builder: *mut FunctionCallBuilder, value: *const c_char);
    pub fn FCBAppendInstanceName(builder: *mut FunctionCallBuilder, value: *const c_char);
    pub fn FCBAppendFact(builder: *mut FunctionCallBuilder, value: *mut Fact);
    pub fn FCBAppendInstance(builder: *mut FunctionCallBuilder, value: *mut Instance);
    pub fn FCBAppendMultifield(builder: *mut FunctionCallBuilder, value: *mut Multifield);
    pub fn FCBAppend(builder: *mut FunctionCallBuilder, value: *mut CLIPSValue);
    pub fn FCBCall(
        builder: *mut FunctionCallBuilder,
        name: *const c_char,
        result: *mut CLIPSValue,
    ) -> u32;
    pub fn FCBPopArgument(builder: *mut FunctionCallBuilder);
    pub fn FCBReset(builder: *mut FunctionCallBuilder);
    pub fn FCBDispose(builder: *mut FunctionCallBuilder);

    pub fn CreateFactModifier(environment: *mut Environment, fact: *mut Fact) -> *mut FactModifier;
    pub fn FMPutSlotInteger(modifier: *mut FactModifier, slot: *const c_char, value: i64) -> u32;
    pub fn FMPutSlotFloat(modifier: *mut FactModifier, slot: *const c_char, value: f64) -> u32;
    pub fn FMPutSlotSymbol(
        modifier: *mut FactModifier,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn FMPutSlotString(
        modifier: *mut FactModifier,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn FMPutSlotInstanceName(
        modifier: *mut FactModifier,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn FMPutSlotFact(modifier: *mut FactModifier, slot: *const c_char, value: *mut Fact)
    -> u32;
    pub fn FMPutSlotInstance(
        modifier: *mut FactModifier,
        slot: *const c_char,
        value: *mut Instance,
    ) -> u32;
    pub fn FMPutSlotMultifield(
        modifier: *mut FactModifier,
        slot: *const c_char,
        value: *mut Multifield,
    ) -> u32;
    pub fn FMPutSlot(
        modifier: *mut FactModifier,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> u32;
    pub fn FMModify(modifier: *mut FactModifier) -> *mut Fact;
    pub fn FMError(environment: *mut Environment) -> u32;
    pub fn FMAbort(modifier: *mut FactModifier);
    pub fn FMDispose(modifier: *mut FactModifier);

    pub fn CreateInstanceModifier(
        environment: *mut Environment,
        instance: *mut Instance,
    ) -> *mut InstanceModifier;
    pub fn IMPutSlotInteger(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: i64,
    ) -> u32;
    pub fn IMPutSlotFloat(modifier: *mut InstanceModifier, slot: *const c_char, value: f64) -> u32;
    pub fn IMPutSlotSymbol(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn IMPutSlotString(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn IMPutSlotInstanceName(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *const c_char,
    ) -> u32;
    pub fn IMPutSlotFact(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *mut Fact,
    ) -> u32;
    pub fn IMPutSlotInstance(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *mut Instance,
    ) -> u32;
    pub fn IMPutSlotMultifield(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *mut Multifield,
    ) -> u32;
    pub fn IMPutSlot(
        modifier: *mut InstanceModifier,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> u32;
    pub fn IMModify(modifier: *mut InstanceModifier) -> *mut Instance;
    pub fn IMError(environment: *mut Environment) -> u32;
    pub fn IMAbort(modifier: *mut InstanceModifier);
    pub fn IMDispose(modifier: *mut InstanceModifier);

    pub fn FindDeftemplate(environment: *mut Environment, name: *const c_char) -> *mut Deftemplate;
    pub fn GetNextDeftemplate(
        environment: *mut Environment,
        current: *mut Deftemplate,
    ) -> *mut Deftemplate;
    pub fn DeftemplateName(value: *mut Deftemplate) -> *const c_char;
    pub fn FindDefrule(environment: *mut Environment, name: *const c_char) -> *mut Defrule;
    pub fn GetNextDefrule(environment: *mut Environment, current: *mut Defrule) -> *mut Defrule;
    pub fn DefruleName(value: *mut Defrule) -> *const c_char;
    pub fn FindDeffacts(environment: *mut Environment, name: *const c_char) -> *mut Deffacts;
    pub fn GetNextDeffacts(environment: *mut Environment, current: *mut Deffacts) -> *mut Deffacts;
    pub fn DeffactsName(value: *mut Deffacts) -> *const c_char;
    pub fn FindDefglobal(environment: *mut Environment, name: *const c_char) -> *mut Defglobal;
    pub fn GetNextDefglobal(
        environment: *mut Environment,
        current: *mut Defglobal,
    ) -> *mut Defglobal;
    pub fn DefglobalName(value: *mut Defglobal) -> *const c_char;
    pub fn FindDeffunction(environment: *mut Environment, name: *const c_char) -> *mut Deffunction;
    pub fn GetNextDeffunction(
        environment: *mut Environment,
        current: *mut Deffunction,
    ) -> *mut Deffunction;
    pub fn DeffunctionName(value: *mut Deffunction) -> *const c_char;
    pub fn FindDefgeneric(environment: *mut Environment, name: *const c_char) -> *mut Defgeneric;
    pub fn GetNextDefgeneric(
        environment: *mut Environment,
        current: *mut Defgeneric,
    ) -> *mut Defgeneric;
    pub fn DefgenericName(value: *mut Defgeneric) -> *const c_char;
    pub fn FindDefclass(environment: *mut Environment, name: *const c_char) -> *mut Defclass;
    pub fn GetNextDefclass(environment: *mut Environment, current: *mut Defclass) -> *mut Defclass;
    pub fn DefclassName(value: *mut Defclass) -> *const c_char;
    pub fn FindDefinstances(
        environment: *mut Environment,
        name: *const c_char,
    ) -> *mut Definstances;
    pub fn GetNextDefinstances(
        environment: *mut Environment,
        current: *mut Definstances,
    ) -> *mut Definstances;
    pub fn DefinstancesName(value: *mut Definstances) -> *const c_char;
    pub fn FindDefmodule(environment: *mut Environment, name: *const c_char) -> *mut Defmodule;
    pub fn GetNextDefmodule(
        environment: *mut Environment,
        current: *mut Defmodule,
    ) -> *mut Defmodule;
    pub fn DefmoduleName(value: *mut Defmodule) -> *const c_char;

    pub fn GetNextActivation(
        environment: *mut Environment,
        current: *mut Activation,
    ) -> *mut Activation;
    pub fn ActivationRuleName(activation: *mut Activation) -> *const c_char;
    pub fn ActivationGetSalience(activation: *mut Activation) -> i32;
    pub fn ActivationSetSalience(activation: *mut Activation, salience: i32) -> i32;
    pub fn ActivationPPForm(activation: *mut Activation, builder: *mut StringBuilder);
    pub fn MoveActivationToTop(environment: *mut Environment, activation: *mut Activation) -> bool;
    pub fn DeleteActivation(activation: *mut Activation);
    pub fn GetNumberOfActivations(environment: *mut Environment) -> std::ffi::c_ulong;
    pub fn GetSalienceEvaluation(environment: *mut Environment) -> u32;
    pub fn SetSalienceEvaluation(environment: *mut Environment, value: u32) -> u32;
    pub fn RefreshAllAgendas(environment: *mut Environment);
    pub fn ReorderAllAgendas(environment: *mut Environment);
    pub fn SetStrategy(environment: *mut Environment, value: u32) -> u32;
    pub fn GetStrategy(environment: *mut Environment) -> u32;
    pub fn ClearFocusStack(environment: *mut Environment);

    pub fn AddRouter(
        environment: *mut Environment,
        name: *const c_char,
        priority: i32,
        query: Option<RouterQuery>,
        write: Option<RouterWrite>,
        read: Option<RouterRead>,
        unread: Option<RouterUnread>,
        exit: Option<RouterExit>,
        context: *mut c_void,
    ) -> bool;
    pub fn DeleteRouter(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn ActivateRouter(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn DeactivateRouter(environment: *mut Environment, name: *const c_char) -> bool;

    pub fn Save(environment: *mut Environment, path: *const c_char) -> bool;
    pub fn Bsave(environment: *mut Environment, path: *const c_char) -> bool;
    pub fn Bload(environment: *mut Environment, path: *const c_char) -> bool;
    pub fn Bloaded(environment: *mut Environment) -> bool;
    pub fn SaveFacts(
        environment: *mut Environment,
        path: *const c_char,
        scope: std::ffi::c_uint,
    ) -> std::ffi::c_long;
    pub fn LoadFacts(environment: *mut Environment, path: *const c_char) -> std::ffi::c_long;
    pub fn LoadFactsFromString(
        environment: *mut Environment,
        source: *const c_char,
        length: usize,
    ) -> std::ffi::c_long;
    pub fn BinarySaveFacts(
        environment: *mut Environment,
        path: *const c_char,
        scope: std::ffi::c_uint,
    ) -> std::ffi::c_long;
    pub fn BinaryLoadFacts(environment: *mut Environment, path: *const c_char) -> std::ffi::c_long;
    pub fn SaveInstances(
        environment: *mut Environment,
        path: *const c_char,
        scope: std::ffi::c_uint,
    ) -> std::ffi::c_long;
    pub fn LoadInstances(environment: *mut Environment, path: *const c_char) -> std::ffi::c_long;
    pub fn LoadInstancesFromString(
        environment: *mut Environment,
        source: *const c_char,
        length: usize,
    ) -> std::ffi::c_long;
    pub fn RestoreInstances(environment: *mut Environment, path: *const c_char)
    -> std::ffi::c_long;
    pub fn RestoreInstancesFromString(
        environment: *mut Environment,
        source: *const c_char,
        length: usize,
    ) -> std::ffi::c_long;
    pub fn BinarySaveInstances(
        environment: *mut Environment,
        path: *const c_char,
        scope: std::ffi::c_uint,
    ) -> std::ffi::c_long;
    pub fn BinaryLoadInstances(
        environment: *mut Environment,
        path: *const c_char,
    ) -> std::ffi::c_long;

    pub fn AddUDF(
        environment: *mut Environment,
        name: *const c_char,
        return_types: *const c_char,
        min_args: u16,
        max_args: u16,
        argument_types: *const c_char,
        callback: Option<UserDefinedFunction>,
        c_name: *const c_char,
        context: *mut c_void,
    ) -> u32;
    pub fn RemoveUDF(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn UDFArgumentCount(context: *mut UDFContext) -> u32;
    pub fn UDFNthArgument(
        context: *mut UDFContext,
        position: u32,
        types: u32,
        value: *mut UDFValue,
    ) -> bool;
    pub fn UDFThrowError(context: *mut UDFContext);
    pub fn CreateFloat(environment: *mut Environment, value: f64) -> *mut CLIPSFloat;
    pub fn CreateInteger(environment: *mut Environment, value: i64) -> *mut CLIPSInteger;
    pub fn CreateBoolean(environment: *mut Environment, value: bool) -> *mut CLIPSLexeme;
    pub fn CreateSymbol(environment: *mut Environment, value: *const c_char) -> *mut CLIPSLexeme;
    pub fn CreateString(environment: *mut Environment, value: *const c_char) -> *mut CLIPSLexeme;
    pub fn CreateInstanceName(
        environment: *mut Environment,
        value: *const c_char,
    ) -> *mut CLIPSLexeme;

    pub fn Watch(environment: *mut Environment, item: std::ffi::c_int);
    pub fn Unwatch(environment: *mut Environment, item: std::ffi::c_int);
    pub fn WatchString(environment: *mut Environment, item: *const c_char) -> bool;
    pub fn UnwatchString(environment: *mut Environment, item: *const c_char) -> bool;
    pub fn GetWatchItem(environment: *mut Environment, item: *const c_char) -> std::ffi::c_int;
    pub fn GetWatchState(environment: *mut Environment, item: std::ffi::c_int) -> bool;
    pub fn SetWatchState(environment: *mut Environment, item: std::ffi::c_int, enabled: bool);
    pub fn SetCompilationsWatch(environment: *mut Environment, enabled: bool);
    pub fn GetCompilationsWatch(environment: *mut Environment) -> bool;
    pub fn SetPrintWhileLoading(environment: *mut Environment, enabled: bool);
    pub fn GetPrintWhileLoading(environment: *mut Environment) -> bool;
    pub fn SetLoadInProgress(environment: *mut Environment, enabled: bool);
    pub fn GetLoadInProgress(environment: *mut Environment) -> bool;
    pub fn ExecutingConstruct(environment: *mut Environment) -> bool;
    pub fn SetExecutingConstruct(environment: *mut Environment, enabled: bool);

    pub fn GetCurrentModule(environment: *mut Environment) -> *mut Defmodule;
    pub fn SetCurrentModule(
        environment: *mut Environment,
        module: *mut Defmodule,
    ) -> *mut Defmodule;
    pub fn GetNumberOfDefmodules(environment: *mut Environment) -> u16;
    pub fn Focus(module: *mut Defmodule);
    pub fn PopFocus(environment: *mut Environment) -> *mut Defmodule;
    pub fn GetNextFocus(
        environment: *mut Environment,
        current: *mut FocalModule,
    ) -> *mut FocalModule;
    pub fn FocalModuleName(focus: *mut FocalModule) -> *const c_char;

    pub fn DeftemplateModule(value: *mut Deftemplate) -> *const c_char;
    pub fn DeftemplatePPForm(value: *mut Deftemplate) -> *const c_char;
    pub fn DeftemplateIsDeletable(value: *mut Deftemplate) -> bool;
    pub fn Undeftemplate(value: *mut Deftemplate, environment: *mut Environment) -> bool;
    pub fn DefruleModule(value: *mut Defrule) -> *const c_char;
    pub fn DefrulePPForm(value: *mut Defrule) -> *const c_char;
    pub fn DefruleIsDeletable(value: *mut Defrule) -> bool;
    pub fn Undefrule(value: *mut Defrule, environment: *mut Environment) -> bool;
    pub fn DeffactsModule(value: *mut Deffacts) -> *const c_char;
    pub fn DeffactsPPForm(value: *mut Deffacts) -> *const c_char;
    pub fn DeffactsIsDeletable(value: *mut Deffacts) -> bool;
    pub fn Undeffacts(value: *mut Deffacts, environment: *mut Environment) -> bool;
    pub fn DefglobalModule(value: *mut Defglobal) -> *const c_char;
    pub fn DefglobalPPForm(value: *mut Defglobal) -> *const c_char;
    pub fn DefglobalIsDeletable(value: *mut Defglobal) -> bool;
    pub fn Undefglobal(value: *mut Defglobal, environment: *mut Environment) -> bool;
    pub fn DeffunctionModule(value: *mut Deffunction) -> *const c_char;
    pub fn DeffunctionPPForm(value: *mut Deffunction) -> *const c_char;
    pub fn DeffunctionIsDeletable(value: *mut Deffunction) -> bool;
    pub fn Undeffunction(value: *mut Deffunction, environment: *mut Environment) -> bool;
    pub fn DefgenericModule(value: *mut Defgeneric) -> *const c_char;
    pub fn DefgenericPPForm(value: *mut Defgeneric) -> *const c_char;
    pub fn DefgenericIsDeletable(value: *mut Defgeneric) -> bool;
    pub fn Undefgeneric(value: *mut Defgeneric, environment: *mut Environment) -> bool;
    pub fn DefclassModule(value: *mut Defclass) -> *const c_char;
    pub fn DefclassPPForm(value: *mut Defclass) -> *const c_char;
    pub fn DefclassIsDeletable(value: *mut Defclass) -> bool;
    pub fn Undefclass(value: *mut Defclass, environment: *mut Environment) -> bool;
    pub fn DefinstancesModule(value: *mut Definstances) -> *const c_char;
    pub fn DefinstancesPPForm(value: *mut Definstances) -> *const c_char;
    pub fn DefinstancesIsDeletable(value: *mut Definstances) -> bool;
    pub fn Undefinstances(value: *mut Definstances, environment: *mut Environment) -> bool;
    pub fn DefmodulePPForm(value: *mut Defmodule) -> *const c_char;

    pub fn GetDisjunctCount(environment: *mut Environment, rule: *mut Defrule) -> std::ffi::c_long;
    pub fn GetNthDisjunct(
        environment: *mut Environment,
        rule: *mut Defrule,
        index: std::ffi::c_long,
    ) -> *mut Defrule;
    pub fn Matches(rule: *mut Defrule, verbosity: std::ffi::c_int, value: *mut CLIPSValue);
    pub fn RemoveAllActivations(environment: *mut Environment);
    pub fn GetAgendaChanged(environment: *mut Environment) -> bool;
    pub fn SetAgendaChanged(environment: *mut Environment, changed: bool);
    pub fn RefreshAgenda(module: *mut Defmodule);
    pub fn ReorderAgenda(module: *mut Defmodule);
    pub fn RemoveAllBreakpoints(environment: *mut Environment);
    pub fn GetFocus(environment: *mut Environment) -> *mut Defmodule;
    pub fn GetFocusChanged(environment: *mut Environment) -> bool;
    pub fn SetFocusChanged(environment: *mut Environment, changed: bool);
    pub fn GetDefmoduleList(environment: *mut Environment, value: *mut CLIPSValue);

    pub fn SetBreak(rule: *mut Defrule);
    pub fn RemoveBreak(rule: *mut Defrule) -> bool;
    pub fn DefruleHasBreakpoint(rule: *mut Defrule) -> bool;
    pub fn Refresh(rule: *mut Defrule);
    pub fn DefruleGetWatchFirings(rule: *mut Defrule) -> bool;
    pub fn DefruleSetWatchFirings(rule: *mut Defrule, value: bool);
    pub fn DefruleGetWatchActivations(rule: *mut Defrule) -> bool;
    pub fn DefruleSetWatchActivations(rule: *mut Defrule, value: bool);
    pub fn DeftemplateGetWatch(value: *mut Deftemplate) -> bool;
    pub fn DeftemplateSetWatch(value: *mut Deftemplate, enabled: bool);
    pub fn DefglobalGetWatch(value: *mut Defglobal) -> bool;
    pub fn DefglobalSetWatch(value: *mut Defglobal, enabled: bool);
    pub fn DeffunctionGetWatch(value: *mut Deffunction) -> bool;
    pub fn DeffunctionSetWatch(value: *mut Deffunction, enabled: bool);
    pub fn DefgenericGetWatch(value: *mut Defgeneric) -> bool;
    pub fn DefgenericSetWatch(value: *mut Defgeneric, enabled: bool);
    pub fn DefclassGetWatchInstances(value: *mut Defclass) -> bool;
    pub fn DefclassSetWatchInstances(value: *mut Defclass, enabled: bool);
    pub fn DefclassGetWatchSlots(value: *mut Defclass) -> bool;
    pub fn DefclassSetWatchSlots(value: *mut Defclass, enabled: bool);

    pub fn AddResetFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveResetFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddClearFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveClearFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddClearReadyFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<BoolCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveClearReadyFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddPeriodicFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemovePeriodicFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddCleanupFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveCleanupFunction(environment: *mut Environment, name: *const c_char) -> bool;
    // The binary-load and module hooks have no CLIPS removal entry point.
    pub fn AddBeforeBloadFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    );
    pub fn AddAfterBloadFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    );
    pub fn AddAbortBloadFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    );
    pub fn AddClearBloadReadyFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<BoolCallFunction>,
        priority: i32,
        context: *mut c_void,
    );
    pub fn AddAfterModuleChangeFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunction>,
        priority: i32,
        context: *mut c_void,
    );
    pub fn AddBeforeRuleFiresFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<RuleFiredFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveBeforeRuleFiresFunction(
        environment: *mut Environment,
        name: *const c_char,
    ) -> bool;
    pub fn AddAfterRuleFiresFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<RuleFiredFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveAfterRuleFiresFunction(environment: *mut Environment, name: *const c_char)
    -> bool;

    pub fn AddAssertFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunctionWithArg>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveAssertFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddRetractFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<VoidCallFunctionWithArg>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveRetractFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddModifyFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<ModifyCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveModifyFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn AddSaveFunction(
        environment: *mut Environment,
        name: *const c_char,
        callback: Option<SaveCallFunction>,
        priority: i32,
        context: *mut c_void,
    ) -> bool;
    pub fn RemoveSaveFunction(environment: *mut Environment, name: *const c_char) -> bool;
    pub fn SetParserErrorCallback(
        environment: *mut Environment,
        callback: Option<ParserErrorFunction>,
        context: *mut c_void,
    ) -> Option<ParserErrorFunction>;

    pub fn MemUsed(environment: *mut Environment) -> i64;
    pub fn MemRequests(environment: *mut Environment) -> i64;
    pub fn ReleaseMem(environment: *mut Environment, amount: i64) -> i64;
    pub fn GetConserveMemory(environment: *mut Environment) -> bool;
    pub fn SetConserveMemory(environment: *mut Environment, enabled: bool) -> bool;
    pub fn GetProfilePercentThreshold(environment: *mut Environment) -> f64;
    pub fn SetProfilePercentThreshold(environment: *mut Environment, threshold: f64) -> f64;

    pub fn EnablePeriodicFunctions(environment: *mut Environment, enabled: bool) -> bool;
    pub fn EnableYieldFunction(environment: *mut Environment, enabled: bool) -> bool;

    pub fn DribbleOn(environment: *mut Environment, path: *const c_char) -> bool;
    pub fn DribbleActive(environment: *mut Environment) -> bool;
    pub fn DribbleOff(environment: *mut Environment) -> bool;

    pub fn DeftemplateSlotNames(template: *mut Deftemplate, value: *mut CLIPSValue);
    pub fn DeftemplateSlotDefaultValue(
        template: *mut Deftemplate,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn DeftemplateSlotCardinality(
        template: *mut Deftemplate,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn DeftemplateSlotAllowedValues(
        template: *mut Deftemplate,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn DeftemplateSlotRange(
        template: *mut Deftemplate,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn DeftemplateSlotTypes(
        template: *mut Deftemplate,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn DeftemplateSlotMultiP(template: *mut Deftemplate, slot: *const c_char) -> bool;
    pub fn DeftemplateSlotSingleP(template: *mut Deftemplate, slot: *const c_char) -> bool;
    pub fn DeftemplateSlotExistP(template: *mut Deftemplate, slot: *const c_char) -> bool;
    pub fn DeftemplateSlotDefaultP(
        template: *mut Deftemplate,
        slot: *const c_char,
    ) -> std::ffi::c_int;

    pub fn GetNextDefmethod(generic: *mut Defgeneric, current: u16) -> u16;
    pub fn GetDefmethodPointer(generic: *mut Defgeneric, index: std::ffi::c_long)
    -> *mut Defmethod;
    pub fn DefmethodIsDeletable(generic: *mut Defgeneric, index: u16) -> bool;
    pub fn Undefmethod(generic: *mut Defgeneric, index: u16, environment: *mut Environment)
    -> bool;
    pub fn DefmethodPPForm(generic: *mut Defgeneric, index: u16) -> *const c_char;
    pub fn DefmethodGetWatch(generic: *mut Defgeneric, index: u16) -> bool;
    pub fn DefmethodSetWatch(generic: *mut Defgeneric, index: u16, enabled: bool);
    pub fn GetMethodRestrictions(generic: *mut Defgeneric, index: u16, value: *mut CLIPSValue);
    pub fn DefmethodDescription(generic: *mut Defgeneric, index: u16, builder: *mut StringBuilder);
    pub fn DefglobalGetValue(global: *mut Defglobal, value: *mut CLIPSValue);
    pub fn DefglobalSetInteger(global: *mut Defglobal, value: i64);
    pub fn DefglobalSetFloat(global: *mut Defglobal, value: f64);
    pub fn DefglobalSetSymbol(global: *mut Defglobal, value: *const c_char);
    pub fn DefglobalSetString(global: *mut Defglobal, value: *const c_char);
    pub fn DefglobalSetInstanceName(global: *mut Defglobal, value: *const c_char);

    pub fn GetClassDefaultsMode(environment: *mut Environment) -> u32;
    /// Returns the previous mode.
    pub fn SetClassDefaultsMode(environment: *mut Environment, mode: u32) -> u32;
    /// Prints the handler chain a message would run, to a logical name.
    pub fn PreviewSend(class: *mut Defclass, logical_name: *const c_char, message: *const c_char);
    pub fn ClassAbstractP(class: *mut Defclass) -> bool;
    pub fn ClassReactiveP(class: *mut Defclass) -> bool;
    pub fn ClassSlots(class: *mut Defclass, value: *mut CLIPSValue, inherit: bool);
    pub fn ClassSuperclasses(class: *mut Defclass, value: *mut CLIPSValue, inherit: bool);
    pub fn ClassSubclasses(class: *mut Defclass, value: *mut CLIPSValue, inherit: bool);
    pub fn SlotFacets(class: *mut Defclass, slot: *const c_char, value: *mut CLIPSValue) -> bool;
    pub fn SlotSources(class: *mut Defclass, slot: *const c_char, value: *mut CLIPSValue) -> bool;
    pub fn SlotTypes(class: *mut Defclass, slot: *const c_char, value: *mut CLIPSValue) -> bool;
    pub fn SlotAllowedValues(
        class: *mut Defclass,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn SlotAllowedClasses(
        class: *mut Defclass,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn SlotRange(class: *mut Defclass, slot: *const c_char, value: *mut CLIPSValue) -> bool;
    pub fn SlotCardinality(
        class: *mut Defclass,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn SlotDefaultValue(
        class: *mut Defclass,
        slot: *const c_char,
        value: *mut CLIPSValue,
    ) -> bool;
    pub fn SlotDefaultP(
        environment: *mut Environment,
        class: *mut Defclass,
        slot: *const c_char,
    ) -> std::ffi::c_int;
    pub fn SlotExistP(class: *mut Defclass, slot: *const c_char, inherit: bool) -> bool;
    pub fn SlotWritableP(class: *mut Defclass, slot: *const c_char) -> bool;
    pub fn SlotInitableP(class: *mut Defclass, slot: *const c_char) -> bool;
    pub fn SlotPublicP(class: *mut Defclass, slot: *const c_char) -> bool;
    pub fn SlotDirectAccessP(class: *mut Defclass, slot: *const c_char) -> bool;
    pub fn SuperclassP(class: *mut Defclass, candidate: *mut Defclass) -> bool;
    pub fn SubclassP(class: *mut Defclass, candidate: *mut Defclass) -> bool;
    pub fn DefglobalSetValue(global: *mut Defglobal, value: *mut CLIPSValue);
    pub fn GetGlobalsChanged(environment: *mut Environment) -> bool;
    pub fn SetGlobalsChanged(environment: *mut Environment, changed: bool);
    pub fn GetResetGlobals(environment: *mut Environment) -> bool;
    pub fn SetResetGlobals(environment: *mut Environment, enabled: bool) -> bool;
    pub fn DefmessageHandlerGetWatch(class: *mut Defclass, index: u32) -> bool;
    pub fn DefmessageHandlerSetWatch(class: *mut Defclass, index: u32, enabled: bool);
    pub fn DefmessageHandlerName(class: *mut Defclass, index: u32) -> *const c_char;
    pub fn DefmessageHandlerType(class: *mut Defclass, index: u32) -> *const c_char;
    pub fn GetNextDefmessageHandler(class: *mut Defclass, current: u32) -> u32;
    pub fn FindDefmessageHandler(
        class: *mut Defclass,
        name: *const c_char,
        kind: *const c_char,
    ) -> u32;
    pub fn DefmessageHandlerIsDeletable(class: *mut Defclass, index: u32) -> bool;
    pub fn DefmessageHandlerPPForm(class: *mut Defclass, index: u32) -> *const c_char;
    pub fn UndefmessageHandler(
        class: *mut Defclass,
        index: u32,
        environment: *mut Environment,
    ) -> bool;
}

#[repr(C)]
pub struct StringBuilder {
    pub environment: *mut Environment,
    pub contents: *mut c_char,
    pub buffer_reset: usize,
    pub length: usize,
    pub buffer_maximum: usize,
}