-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexpr_lib.lua
More file actions
1550 lines (1176 loc) · 43.8 KB
/
expr_lib.lua
File metadata and controls
1550 lines (1176 loc) · 43.8 KB
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
--[[
____ _ _ ___ ___ ____ ___ ___ __ ____ _ _ _ ___ _ _ ____
F ___J FJ LJ F _ ", F _ ", F ___J F __". F __". FJ F __ ] F L L] /.\ F __". FJ L] F___ J
J |___: J \/ F J `-' |J `-'(| J |___: J (___| J (___| J L J |--| L J \| L //_\\ J |--\ LJ | | L `-__| L
| _____| / \ | __/F| _ L | _____| J\___ \ J\___ \ | | | | | | | |\ | / ___ \ | | J |J J F L |__ (
F L____: / /\ \ F |__/ F |_\ L F L____: .--___) \.--___) \ F J F L__J J F L\\ J / L___J \ F L__J |J\ \/ /F .-____] J
J________LJ__//\\__LJ__| J__| \\__LJ________LJ\______JJ\______JJ____LJ\______/FJ__L \\__L J__L J__LJ______/F \\__// J\______/F
|________||__/ \__||__L |__| J__||________| J______F J______F|____| J______F |__L J__| |__L J__||______F \__/ J______F
::Expression Advanced 3 Library::
`````````````````````````````````
Some operators, methods and functions can return more then one value of the same type at once.
You need to tell the compiler how many results it returns even if that is 0.
Parameters should always be class id's separated by a comma (,); e.g "n,n,s".
All documentation below is to be considered work in progress and this api will more then likely change.
::HOOKS::
Expression3.RegisterExtension -> Called when extensions should be registered.
Expression3.LoadClasses -> None extended classes must be registered inside this hook.
Expression3.LoadExtendedClasses -> Extended classes must be registered inside this hook.
Expression3.LoadConstructors -> Constructors must be registered inside this hook.
Expression3.LoadMethods -> Methods must be registered inside this hook.
Expression3.LoadMethods -> Methods must be registered inside this hook.
Expression3.LoadAttributes -> Attributes must be registered inside this hook.
Expression3.LoadLibraries -> Libraries must be registered inside this hook.
Expression3.LoadFunctions -> Functions must be registered inside this hook.
Expression3.PostRegisterExtensions -> This is called once expadv3 has loaded its extensions.
Expression3.PostCompile.System.<function> -> This is called after compiling every function on the system library, -> ressult class, result count = (comiler, instruction, token, expressions)
(replace <function> with the name of the function on the library..
Expression3.Entity.BuildSandbox -> This is called when building the sandboxed enviroment for an entity. -> (entity, context, enviroment)
Expression3.Start.Entity -> This is called when an entity is about to run for the first time. -> (entity, context)
Expression3.Entity.Think -> Called by all expression 3 entitys during the entitys think function -> (entity, context)
Expression3.Entity.Update -> This is called when an entity has sucessfuly executed. -> (entity, context)
Expression3.Entity.Stop -> This is called when an entity has shutdown for any given reason. -> (entity, context)
Expression3.GolemInit -> this is called when the editor is created.
Expression3.OpenGolem -> this is called when the editor opens.
Expression3.CloseGolem -> this is called when the editor closes.
Expression3.AddGolemTabTypes -> This is called when custom tab types should be registered on the editor. -> (Editor)
Expression3.LoadWiki -> This is called when its time to register the helpers to the wiki.
Expression3.ExtendBaseEntity -> Called during the creation of the base entity table, can be used to register new methods onto the base entity, -> (table entitytbl);
Expression3.ExtendContext -> Called during the creation of the base context table, can be used to register new methods onto the base context,, -> (table basse context);
::IMPORTANT::
You should use 'Extension = EXPR_LIB.RegisterExtension(string)' to create a new Extension object.
You should then use the api methods on the new Extension to register everything.
Doing it this way means you do not need to add the hooks yourself as the extension will load the contents at the correct time.
Do not forget to call Extension:EnableExtension() once your done otherwise the extension will not load itself.
It is possible to register an extension outside the extension folder by creating it inside Expression3.RegisterExtensions hook.
::RULES::
A constructor's function can be a string, if so the compiler will attempt to use a native lua function at the given string; e.g string.replace.
The first parameter to a constructor's function will always be context unless exclude context is true;
Some operator's and casting operator's function is optional, if not given the compiler will attempt to use lua's native method.
The first parameter to an operator / casting operator function will always be context unless exclude context is true;
A method's function can be a string, if so the compiler will attempt to use a native lua method on that object.
The first parameter to a method's function will always be context unless exclude context is true;
NO LONGER SUPPORTED: A function's function can be a string, if so the compiler will attempt to use a native lua function at the given string; e.g string.replace.
The first parameter to a function's function will always be context unless exclude context is true;
::Examples::
Using a string as an operation.
Operator: extension:RegisterConstructor("v", "n,n,n", "Vector", true);
Input: new vector(1,2,3);
OutPut: Vector(1,2,3);
Using a function as operation with context.
Operator: extension:RegisterConstructor("v", "n,n,n", function(c,x,y,z) end, false);
Input: new vector(1,2,3);
OutPut: _Ops["v(n,n,n)"](context, 1,2,3);
using a function as operation without context.
Operator: extension:RegisterConstructor("v", "n,n,n", function(x,y,z) end, true);
Input: new vector(1,2,3);
OutPut: _Ops["v(n,n,n)"](1,2,3);
::EXPR_LIB::
EXPR_LIB.SetPrice(int price)
Sets the price of the methods / functions / constructors your defining, this is currently unused but will be used if we need to change the way e3 manages performance.
EXPR_LIB.RegisterPermission(string name, string image, string desc)
Registers a new permission node, this allows you to add player granted access for a gate.
EXPR_LIB.RegisterClass(string short name, string class name, string class boolean = function(object) isType, boolean = function(object) isValid)
Registers a new class with expression 3.
EXPR_LIB.RegisterExtendedClass(string short name, string class name, string base class name, boolean = function(object) isType, boolean = function(object) isValid)
Registers a new class based of an existing class.
EXPR_LIB.RegisterConstructor(str class, str parameters, obj = function(ctx, ...) constructor, boolean exclude context)
Registers a constructor for class with expression 3; new vector(1, 2, 3)
EXPR_LIB.RegisterMethod(class, str name, str parameters, str type, number amount of values returned, (obj = function(ctx*, ...) method / string)*, boolean exclude context)
Registers a method with expression 3 on class;
if operator is a string then it will use the method str on object without context as a parameter.
EXPR_LIB.RegisterAttribute(class, str name, str type, string native field)
Adds an attribute to a class, this does not take an operator or a function.
-> E3)Var.Attribute = Value :: Lua)Var.Field = Value
EXPR_LIB.RegisterOperator(str operation, str parameters, str type, number amount of values returned, obj = function(ctx*, ...) operator*, boolean exclude context)
Registers an operator with expression 3;
if operator is nil then it will use the native operator on object.
::OPERATORS::
This list will expand as time goes on and more are added.
and (type1, type2) type1 && type2
or (type1, type2) type1 || type2
add (type1, type2) type1 + type2
sub (type1, type2) type1 - type2
div (type1, type2) type1 / type2
mul (type1, type2) type1 * type2
exp (type1, type2) type1 ^ type2
mod (type1, type2) type1 % type2
ten (type1, type2, type3) type1 ? type2 : type3
or (type1, type2) type1 || type2
and (type1, type2) type1 && type2
bxor (type1, type2) type1 ^^ type2
bor (type1, type2) type1 | type2
band (type1, type2) type1 & type2
neq (type1, type2) type1 != type2
eq (type1, type2) type1 == type2
lth (type1, type2) type1 < type2
leg (type1, type2) type1 <= type2
gth (type1, type2) type1 > type2
geq (type1, type2) type1 >= type2
bshl (type1, type2) type1 << type2
bshr (type1, type2) type1 >> type2
neg (type1) -type1
not (type1) !type1
len (type1) #type1
call (type1, ...) type(...)
EXPR_LIB.RegisterCastingOperator(str type, str parameter, obj = function(ctx*, ...) operator, boolean exclude context)
Registers a casting operator with expression 3 for casting from one class to another;
type1(type2) type1 = (type1) type2
EXPR_LIB.RegisterLibrary(name)
Registers a new library with expression 3.
Every function must part of a library.
EXPR_LIB.RegisterFunction(str library, str name, str parameters, str type, number amount of values returned, (obj = function(ctx, ...) / str) function, boolean exclude context)
Registers a function with library, these functions are overloaded.
NO LONGER SUPPORTED: If function is a string then expression 3 will use _G[str function]() without context as a parameter.
REMOVED: EXPR_LIB.RegisterEvent(str name, str parameters, str type, number amount of values returned)
Registers an event with expression 3.
EXPR_LIB.GetClass(str class)
EXPR_LIB.RegisterExtension(str name)
Returns and registers a new extension with expression 3;
This will allow you to add to the api without manually using the required events.
::Extension::
Extension:SetPrice(int price)
Sets the price of the method, function, constructors your about to define. This works the same way as EXPR_LIB.SetPrice(int) and is also unused.
Extension:RegisterClass(string short name, string class name, boolean = function(object) isType, boolean = function(object) isValid)
Calls EXPR_LIB.RegisterClass(...) at the correct time with all given valid parameter.
Extension:RegisterExtendedClass(string short name, string class name, string base class name, boolean = function(object) isType, boolean = function(object) isValid)
Calls EXPR_LIB.RegisterExtendedClass(...) at the correct time with all given valid parameter.
Extension.RegisterConstructorRegisterConstructor(str class, str parameters, obj = function(ctx*, ...) constructor, boolean exclude context)
Calls EXPR_LIB.RegisterConstructorRegisterConstructor(...) at the correct time with all given valid parameters.
Extension:RegisterMethod(class, str name, str parameters, str type, number amount of values returned, (obj = function(ctx*, ...) method) / string*, boolean exclude context)
Calls EXPR_LIB.RegisterMethod(...) at the correct time with all given valid parameters.
Extension:RegisterAttribute(class, str name, str type, string native field)
Calls EXPR_LIB.RegisterAttribute(...) at the correct time with all given valid parameters.
Extension:RegisterOperator(str operation, str parameters, str type, number amount of values returned, obj = function(ctx*, ...) operator*, boolean exclude context)
Calls EXPR_LIB.RegisterOperator(...) at the correct time with all given valid parameters.
Extension:RegisterCastingOperator(str type, str parameter, obj = function(ctx, ...) operator, boolean exclude context)
Calls EXPR_LIB.RegisterCastingOperator(...) at the correct time with all given valid parameters.
Extension:RegisterLibrary(name)
Calls EXPR_LIB.RegisterLibrary(...) at the correct time with all given valid parameters.
Extension:RegisterFunction(str library, str name, str parameters, str type, number amount of values returned, (obj = function(ctx*, ...)) function, boolean exclude context)
Calls EXPR_LIB.RegisterFunction(...) at the correct time with all given valid parameters.
Extension:RegisterEvent(str name, str parameters, str type, number amount of values returned)
Calls EXPR_LIB.RegisterEvent(...) at the correct time with all given valid parameters.
Extension:EnableExtension()
Must be called to allow the extension to register its contents.
::Editor Extension::
Extension.RegisterEditorMenu(str name, str icon, panel function(panel editor), function(panel editor, panel tab, boolean save))
CLIENTSIDE ONLY: Used to add a new tab to the lefthand menu with its own menu icon to open it.
The first function (arg #3) is called when the tab is created for the first time. The panel returned is used as the tabs main panel.
The second function (arg #4) is called when the tab is closed.
]]
EXPR_LIB = {};
--[[
]]
print("E3 Lib Loading.");
if (not CLIENT) then
util.AddNetworkString("Expression3.InitializedClient");
util.AddNetworkString("Expression3.OpenGolem");
end
--[[
]]
function EXPR_LIB.ThrowInternal(level, msg, fst, ...)
if (fst) then
msg = string.format(msg, fst, ...);
end
error(msg, level);
end
--[[
]]
local classes;
local classIDs;
local loadClasses = false;
--[[
Prices are currently not used for anything, they where a back up plan.
]]
EXPR_MIN = 1;
EXPR_LOW = 10;
EXPR_MED = 25;
EXPR_HIGH = 50;
local PRICE = EXPR_LOW;
function EXPR_LIB.SetPrice(price)
PRICE = price;
end
--[[
]]
local STATE = 1;
EXPR_SERVER = 0;
EXPR_SHARED = 1;
EXPR_CLIENT = 2;
function EXPR_LIB.SetServerState()
STATE = EXPR_SERVER;
end
function EXPR_LIB.SetSharedState()
STATE = EXPR_SHARED;
end
function EXPR_LIB.SetClientState()
STATE = EXPR_CLIENT;
end
--[[
]]
EXPR_LIB.PERMS = { };
function EXPR_LIB.RegisterPermission(name, image, desc)
EXPR_LIB.PERMS[name] = {name, image, desc};
end
--[[
]]
local events = {};
local loadEvents = false;
function EXPR_LIB.RegisterEvent(name, parameter, type, count, desc)
if (not loadEvents) then
EXPR_LIB.ThrowInternal(0, "Attempt to register Event %s(%s) outside of Hook::Expression3.LoadEvents", name, parameter);
end
local state, signature = EXPR_LIB.SortArgs(parameter);
if (not state) then
EXPR_LIB.ThrowInternal(0, "%s for Event %s(%s)", signature, name, parameter);
end
if not type then type = "_nil"; end
local res = EXPR_LIB.GetClass(type);
if (not res) then
EXPR_LIB.ThrowInternal(0, "Attempt to register Event %s(%s) with none existing return class %s", name, parameter, type);
end
local evt = {};
evt.name = name;
evt.state = STATE;
evt.parameter = signature;
evt.signature = string.format("%s(%s)", name, signature);
evt.result = res.id;
evt.rCount = count or 0;
if CLIENT then
evt.desc = desc;
end
events[evt.signature] = evt;
return evt;
end
--[[
]]
function EXPR_LIB.RegisterClass(id, name, isType, isValid, desc)
if (not loadClasses) then
EXPR_LIB.ThrowInternal(0, "Attempt to register class %s outside of Hook::Expression3.LoadClasses }}", name);
end
if (string.len(id) > 1) then
id = "_" .. id;
end
if (classIDs[id]) then
EXPR_LIB.ThrowInternal(0, "Attempt to register class %s with conflicting id %s", name, id);
end
local class = {};
if (type(name) == "table") then
-- Register aliases for classes.
for _, v in pairs(name) do
classes[string.lower(v)] = class;
end
name = name[1];
end
class.id = string.lower(id);
class.name = string.lower(name);
class.base = "o";
class.state = STATE;
class.price = PRICE;
class.isType = isType;
class.isValid = isValid;
class.attributes = {};
class.constructors = {};
if CLIENT then
class.desc = desc;
end
classIDs[class.id] = class;
classes[class.name] = class;
--MsgN("Registered Class: ", class.id, " - ", class.name);
return class;
end
--[[
]]
function EXPR_LIB.RegisterExtendedClass(id, name, base, isType, isValid, desc)
if (not loadClasses) then
EXPR_LIB.ThrowInternal(0, "Attempt to register class %s outside of Hook::Expression3.LoadClasses", name);
end
local cls = EXPR_LIB.GetClass(base);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register extended class %s from none existing class %s", class, base);
end
local class = EXPR_LIB.RegisterClass(id, name, isType, isValid, desc);
class.base = cls.id;
return class;
end
function EXPR_LIB.RegisterWiredInport(class, wiretype, func)
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register wired inport for none existing class %s", class);
end
if (SERVER) then
if (not WireLib.DT[wiretype]) then
EXPR_LIB.ThrowInternal(0, "Attempt to register wired inport for class %s, with invalid wire type %s", class, wiretype);
end
end
cls.wire_out_func = func;
cls.wire_out_class = wiretype;
end
function EXPR_LIB.RegisterWiredOutport(class, wiretype, func)
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register wired outport for none existing class %s", class);
end
if (SERVER) then
if (not WireLib.DT[wiretype]) then
EXPR_LIB.ThrowInternal(0, "Attempt to register wired outport for class %s, with invalid wire type %s", class, wiretype);
end
end
cls.wire_in_func = func;
cls.wire_in_class = wiretype;
end
function EXPR_LIB.RegisterSyncable(class, sync_sv, sync_cl)
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register wired syncable for none existing class %s", class);
end
cls.wire_sync_sv = sync_sv;
cls.wire_sync_cl = sync_cl;
end
function EXPR_LIB.RegisterNativeDefault(class, native)
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register native default for none existing class %s", class);
end
cls.native_default = native;
end
local loadConstructors = false;
function EXPR_LIB.RegisterConstructor(class, parameter, constructor, excludeContext, desc)
if (not loadConstructors) then
EXPR_LIB.ThrowInternal(0, "Attempt to register Constructor new %s(%s) outside of Hook::Expression3.LoadConstructors", class, parameter);
end
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register Constructor new %s(%s) for none existing class", class, parameter);
end
local state, signature = EXPR_LIB.SortArgs(parameter);
if (not state) then
EXPR_LIB.ThrowInternal(0, "%s for Constructor new %s(%s)", signature, class, parameter);
end
local op = {};
op.name = name;
op.class = cls.id;
op.state = STATE;
op.price = PRICE;
op.parameter = signature;
op.signature = string.format("%s(%s)", cls.id, signature);
op.result = cls.id;
op.rCount = count;
op.operator = constructor;
op.context = not excludeContext;
if CLIENT then
op.desc = desc;
end
cls.constructors[op.signature] = op;
return op;
end
local methods;
local loadMethods = false;
function EXPR_LIB.RegisterMethod(class, name, parameter, type, count, method, excludeContext, desc)
-- if method is nil lua, compiler will use native Object:(...);
if (not loadMethods) then
EXPR_LIB.ThrowInternal(0, "Attempt to register method %s.%s(%s) outside of Hook::Expression3.LoadMethods", class, name, parameter);
end
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register method %s.%s(%s) for none existing class %s", class, name, parameter, class);
end
local state, signature = EXPR_LIB.SortArgs(parameter);
if (not state) then
EXPR_LIB.ThrowInternal(0, "%s for method %s.%s(%s)", signature, class, name, parameter);
end
local res = EXPR_LIB.GetClass(type);
if (not res) then
EXPR_LIB.ThrowInternal(0, "Attempt to register method %s.%s(%s) with none existing return class %s", class, name, parameter, type);
end
local meth = {};
meth.name = name;
meth.class = cls.id;
meth.state = STATE;
meth.price = PRICE;
meth.parameter = signature;
meth.signature = string.format("%s.%s(%s)", cls.id, name, signature);
meth.result = res.id;
meth.rCount = count;
meth.operator = method;
meth.context = not excludeContext;
if CLIENT then
meth.desc = desc;
end
methods[meth.signature] = meth;
-- <Insert Heisenburg joke here>
return meth;
end
local loadAttributes;
function EXPR_LIB.RegisterAttribute(class, attribute, type, native, desc)
native = native or attribute;
if (not loadAttributes) then
EXPR_LIB.ThrowInternal(0, "Attempt to register attribute %s.%s outside of Hook::Expression3.LoadAttributes", class, attribute);
end
local cls = EXPR_LIB.GetClass(class);
if (not cls) then
EXPR_LIB.ThrowInternal(0, "Attempt to register attribute %s.%s for none existing class %s", class, attribute, class);
end
local typ = EXPR_LIB.GetClass(type);
if (not typ) then
EXPR_LIB.ThrowInternal(0, "Attempt to register attribute %s.%s of none existing class %s", class, attribute, type);
end
local atr = {};
atr.field = native;
atr.class = typ.id;
atr.attribute = attribute;
if CLIENT then
atr.desc = desc;
end
cls.attributes[attribute] = atr;
--MsgN("Registered attribute: ", class .. "." .. attribute);
return atr;
end
local operators;
local loadOperators = false;
function EXPR_LIB.RegisterOperator(operation, parameter, type, count, operator, excludeContext, desc)
-- if operator is nil lua, compiler will use native if possible (+, -, /, *, ^, etc)
if (not loadOperators) then
EXPR_LIB.ThrowInternal(0, "Attempt to register operator %s(%s) outside of Hook::Expression3.LoadOperators", operation, parameter);
end
local state, signature = EXPR_LIB.SortArgs(parameter);
if (not state) then
EXPR_LIB.ThrowInternal(0, "%s for operator %s(%s)", signature, operation, parameter);
end
local res = EXPR_LIB.GetClass(type);
if (not res) then
EXPR_LIB.ThrowInternal(0, "Attempt to register operator %s(%s) with none existing return class %s", operation, parameter, type);
end
local op = {};
op.name = operation;
op.state = STATE;
op.price = PRICE;
op.parameter = signature;
op.signature = string.format("%s(%s)", operation, signature);
op.result = res.id;
op.rCount = count;
op.operator = operator;
op.context = not excludeContext;
op.operation = operation;
if CLIENT then
op.desc = desc;
end
operators[op.signature] = op;
return op;
end
local castOperators;
function EXPR_LIB.RegisterCastingOperator(type, parameter, operator, excludeContext, desc)
if (not loadOperators) then
EXPR_LIB.ThrowInternal(0, "Attempt to register casting operator [(%s) %s] outside of Hook::Expression3.LoadOperators", type, parameter);
end
if (not operator) then
EXPR_LIB.ThrowInternal(0, "Attempt to register native casting operator [(%s) %s] an operation function is required.", type, parameter);
end
local state, signature = EXPR_LIB.SortArgs(parameter);
if (not state) then
EXPR_LIB.ThrowInternal(0, "%s for casting operator [(%s) %s]", signature, type, parameter);
end
local res = EXPR_LIB.GetClass(type);
if (not res) then
EXPR_LIB.ThrowInternal(0, "Attempt to register casting operator [(%s) %s] for none existing class %s", type, parameter, type);
end
local op = {};
op.parameter = signature;
op.state = STATE;
op.price = PRICE;
op.signature = string.format("(%s)%s", type, signature);
op.result = res.id;
op.rCount = 1;
op.operator = operator;
op.context = not excludeContext;
if CLIENT then
op.desc = desc;
end
castOperators[op.signature] = op;
return op;
end
local libraries;
local loadLibraries = false;
function EXPR_LIB.RegisterLibrary(name, desc)
if (not loadLibraries) then
EXPR_LIB.ThrowInternal(0, "Attempt to register library %s) outside of Hook::Expression3.LoadLibariess", name);
end
local lib = {};
lib.name = string.lower(name);
lib._functions = {};
lib._constants = {};
if CLIENT then
lib.desc = desc;
end
libraries[lib.name] = lib;
--MsgN("Registered library: ", lib.name);
end
local functions;
local loadFunctions = false;
local blank = function() end
function EXPR_LIB.RegisterFunction(library, name, parameter, type, count, _function, excludeContext, desc)
if (not loadFunctions) then
EXPR_LIB.ThrowInternal(0, "Attempt to register function %s.%s(%s) outside of Hook::Expression3.LoadFunctions", library, name, parameter);
end
local lib = libraries[string.lower(library)];
if (not lib) then
EXPR_LIB.ThrowInternal(0, "Attempt to register function %s.%s(%s) to none existing library %s", library, name, parameter, library);
end
local state, signature = EXPR_LIB.SortArgs(parameter);
if (not state) then
EXPR_LIB.ThrowInternal(0, "%s for function %s.%s(%s)", signature, library, name, parameter);
end
local res = EXPR_LIB.GetClass(type);
if (not res) then
EXPR_LIB.ThrowInternal(0, "Attempt to register function %s.%s(%s) with none existing return class %s", library, name, parameter, type);
end
local op = {};
op.name = name;
op.state = STATE;
op.price = PRICE;
op.parameter = signature;
op.signature = string.format("%s(%s)", name, signature);
op.result = res.id;
op.rCount = count;
op.operator = _function or blank;
op.context = not excludeContext;
if CLIENT then
op.desc = desc;
end
lib._functions[op.signature] = op;
--MsgN("Registered function ", library, ".", op.signature);
return op;
end
--[[
]]
local constants;
local loadConstants = false;
function EXPR_LIB.RegisterConstant(library, name, type, value, native, desc)
if (not loadConstants) then
EXPR_LIB.ThrowInternal(0, "Attempt to register constant %s.%s outside of Hook::Expression3.LoadConstantss", library, name);
end
local lib = libraries[string.lower(library)];
if (not lib) then
EXPR_LIB.ThrowInternal(0, "Attempt to register constant %s.%s to none existing library %s", library, name, library);
end
local res = EXPR_LIB.GetClass(type);
if (not res) then
EXPR_LIB.ThrowInternal(0, "Attempt to register constant %s.%s of none existing class %s", library, name, type);
end
if native then
if not isstring(value) then
EXPR_LIB.ThrowInternal(0, "Attempt to register constant %s.%s using invalid native value %s", library, name, tostring(value));
end
elseif isstring(value) then
native = true;
value = string.format(" %q ", value);
elseif isnumber(value) then
native = true;
value = string.format(" %i ", value);
else
EXPR_LIB.ThrowInternal(0, "Attempt to register constant %s.%s using invalid value %s", library, name, tostring(value));
end
local signature = string.format("%s.%s", library, name);
local op = {};
op.name = name;
op.state = STATE;
op.result = res.id;
op.value = value;
op.native = native;
op.signature = signature;
if CLIENT then
op.desc = desc;
end
lib._constants[op.name] = op;
--MsgN("Registered constant ", library, ".", op.name);
return op;
end
function EXPR_LIB.GetAllClasses()
local res = {};
if ( EXPR_CLASSES ) then
for _, v in pairs(EXPR_CLASSES) do
res[v] = v;
end
end
return res;
end
function EXPR_LIB.GetClass(class)
if not isstring(class) then
debug.Trace();
EXPR_LIB.ThrowInternal(0, "EXPR_LIB.GetClass(s) was given %s.", type(class));
end
if (not class or class == "") then
class = "void";
end
if (classes[class]) then
return classes[class];
end
if (string.len(class) > 1 and string.sub(class, 1, 1) ~= "_") then
class = "_" .. class;
end
return classIDs[class];
end
function EXPR_LIB.IsValidClass(class)
return EXPR_LIB.GetClass(class) ~= nil;
end
function EXPR_LIB.SortArgs(parameter)
if (parameter == "") then
return true, "";
end
local varg = false;
local signature = {};
local split = string.Explode(",", parameter);
if (split[#split] == "...") then
split[#split] = nil;
varg = true;
end
for k, v in pairs(split) do
local cls = EXPR_LIB.GetClass(v);
if (v == "...") then
return false, string.format("Vararg (...) must be last parameter", v, k);
elseif (not cls) then
return false, string.format("Invalid class (%s) for parameter #%i", v, k);
else
signature[k] = cls.id;
end
end
if (varg) then
signature[#signature + 1] = "...";
end
return true, table.concat(signature, ","), varg;
end
--[[
:::Extension Base For Loading Sainly:::
'''''''''''''''''''''''''''''''''''''''
Since we need to add everything in a specific order, this is a extension base that can do this for you.
]]
local Extension = {};
Extension.__index = Extension;
function EXPR_LIB.RegisterExtension(name)
local ext = {};
ext.name = name;
ext.perms = {};
ext.classes = {};
ext.state = EXPR_SHARED;
ext.price = EXPR_LOW;
ext.constructors = {};
ext.methods = {};
ext.attributes = {};
ext.operators = {};
ext.castOperators = {};
ext.libraries = {};
ext.functions = {};
ext.constants = {};
ext.events = {};
return setmetatable(ext, Extension);
end
function EXPR_LIB.GetExtensionMetatable()
return Extension;
end
function Extension.SetPrice(this, price)
this.price = price;
end
function Extension.SetServerState(this)
this.state = EXPR_SERVER;
end
function Extension.SetSharedState(this)
this.state = EXPR_SHARED;
end
function Extension.SetClientState(this)
this.state = EXPR_CLIENT;
end
function Extension.RegisterPermission(this, name, image, desc)
this.perms[#this.perms+1] = {name, image, desc};
end
function Extension.RegisterEvent(this, name, parameter, type, count, desc)
this.events[#this.events+1] = {name, parameter, type, count, this.state, desc};
end
function Extension.RegisterClass(this, id, name, isType, isValid, desc)
local entry = {id, name, isType, isValid, this.state};
this.classes[#this.classes + 1] = entry;
end
function Extension.RegisterExtendedClass(this, id, name, base, isType, isValid, desc)
local entry = {[0] = base, id, name, isType, isValid, this.state, desc};
this.classes[#this.classes + 1] = entry;
end
function Extension.RegisterWiredInport(this, class, wiretype, func)
hook.Add("Expression3.LoadConstructors", "Expression3.WireInput." .. class, function()
if this.enabled then
EXPR_LIB.RegisterWiredInport(class, wiretype, func);
end
end);
end
function Extension.RegisterWiredOutport(this, class, wiretype, func)
hook.Add("Expression3.LoadConstructors", "Expression3.WireOutput." .. class, function()
if (this.enabled) then
EXPR_LIB.RegisterWiredOutport(class, wiretype, func);
end
end);
end
function Extension.RegisterSyncable(this, class, sync_sv, sync_cl)
hook.Add("Expression3.LoadConstructors", "Expression3.Syncable." .. class, function()
if (this.enabled) then
EXPR_LIB.RegisterSyncable(class, sync_sv, sync_cl);
end
end);
end
function Extension.RegisterNativeDefault(this, class, native, desc)
hook.Add("Expression3.LoadConstructors", "Expression3.Native." .. class, function()
if (this.enabled) then
EXPR_LIB.RegisterNativeDefault(class, native);
end
end);
end
function Extension.RegisterConstructor(this, class, parameter, constructor, excludeContext, desc)
local entry = {class, parameter, constructor, excludeContext, this.state, this.price, desc};
this.constructors[#this.constructors + 1] = entry;
end
function Extension.RegisterMethod(this, class, name, parameter, type, count, method, excludeContext, desc)
local entry = {class, name, parameter, type, count, method, excludeContext, this.state, this.price, desc};
this.methods[#this.methods + 1] = entry;
end
function Extension.RegisterAttribute(this, class, attribute, type, native)
local entry = {class, attribute, type, native, this.state, this.price, desc};
this.attributes[#this.attributes + 1] = entry;
end
function Extension.RegisterOperator(this, operation, parameter, type, count, operator, excludeContext, desc)
local entry = {operation, parameter, type, count, operator, excludeContext, this.state, this.price, desc};
this.operators[#this.operators + 1] = entry;
end
function Extension.RegisterCastingOperator(this, type, parameter, operator, excludeContext, desc)
local entry = {type, parameter, operator, excludeContext, this.state, this.price, desc};
this.castOperators[#this.castOperators + 1] = entry;
end
function Extension.RegisterLibrary(this, name)
local entry = {name, name};
this.libraries[#this.libraries + 1] = entry;
end
function Extension.RegisterFunction(this, library, name, parameter, type, count, _function, excludeContext, desc)
local entry = {library, name, parameter, type, count, _function, excludeContext, this.state, this.price, desc};
this.functions[#this.functions + 1] = entry;
end
function Extension.RegisterConstant(this, library, name, type, value, native, desc)