-
Notifications
You must be signed in to change notification settings - Fork 8
/
CrystalLUA.pas
21569 lines (19712 loc) · 609 KB
/
CrystalLUA.pas
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
unit CrystalLUA;
{******************************************************************************}
{ Copyright (c) Dmitry Mozulyov }
{ }
{ Permission is hereby granted, free of charge, to any person obtaining a copy }
{ of this software and associated documentation files (the "Software"), to deal}
{ in the Software without restriction, including without limitation the rights }
{ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell }
{ copies of the Software, and to permit persons to whom the Software is }
{ furnished to do so, subject to the following conditions: }
{ }
{ The above copyright notice and this permission notice shall be included in }
{ all copies or substantial portions of the Software. }
{ }
{ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR }
{ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, }
{ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE }
{ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER }
{ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,}
{ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN }
{ THE SOFTWARE. }
{ }
{ email: [email protected] }
{ skype: dimandevil }
{ repository: https://github.com/d-mozulyov/CrystalLUA }
{******************************************************************************}
// compiler directives
{$ifdef FPC}
{$mode delphiunicode}
{$asmmode intel}
{$define INLINESUPPORT}
{$define INLINESUPPORTSIMPLE}
{$ifdef CPU386}
{$define CPUX86}
{$endif}
{$ifdef CPUX86_64}
{$define CPUX64}
{$endif}
{$else}
{$if CompilerVersion >= 24}
{$LEGACYIFEND ON}
{$ifend}
{$if CompilerVersion >= 15}
{$WARN UNSAFE_CODE OFF}
{$WARN UNSAFE_TYPE OFF}
{$WARN UNSAFE_CAST OFF}
{$WARN SYMBOL_DEPRECATED OFF}
{$ifend}
{$if CompilerVersion >= 20}
{$define INLINESUPPORT}
{$ifend}
{$if CompilerVersion >= 17}
{$define INLINESUPPORTSIMPLE}
{$ifend}
{$if CompilerVersion < 23}
{$define CPUX86}
{$ifend}
{$if CompilerVersion >= 23}
{$define UNITSCOPENAMES}
{$define RETURNADDRESS}
{$ifend}
{$if CompilerVersion >= 21}
{$WEAKLINKRTTI ON}
{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
{$define EXTENDEDRTTI}
{$ifend}
{$if (not Defined(NEXTGEN)) and (CompilerVersion >= 20)}
{$define INTERNALCODEPAGE}
{$ifend}
{$endif}
{$U-}{$V+}{$B-}{$X+}{$T+}{$P+}{$H+}{$J-}{$Z1}{$A4}
{$O+}{$R-}{$I-}{$Q-}{$W-}
{$if Defined(CPUX86) or Defined(CPUX64)}
{$define CPUINTEL}
{$ifend}
{$if Defined(CPUX64) or Defined(CPUARM64)}
{$define LARGEINT}
{$ifend}
{$if (not Defined(CPUX64)) and (not Defined(CPUARM64))}
{$define SMALLINT}
{$ifend}
{$if Defined(FPC) or (CompilerVersion >= 18)}
{$define OPERATORSUPPORT}
{$ifend}
{$ifdef KOLERROR}
{$define KOL_MCK}
{$endif}
{$ifdef KOL_MCK}
{$define KOL}
{$endif}
{$ifdef MSWINDOWS}
{$define LUA_NATIVEFUNC}
{$endif}
interface
uses {$ifdef UNITSCOPENAMES}System.Types, System.TypInfo, System.RTLConsts{$else}Types, TypInfo, RTLConsts{$endif},
{$ifdef UNICODE}{$ifdef UNITSCOPENAMES}System.Character{$else}Character{$endif},{$endif}
{$ifdef MSWINDOWS}{$ifdef UNITSCOPENAMES}Winapi.Windows{$else}Windows{$endif},{$endif}
{$ifdef CPUARM64}System.Rtti,{$endif}
{$ifdef POSIX}Posix.Base, Posix.String_, Posix.Unistd, Posix.SysTypes, Posix.PThread,{$endif}
{$ifdef KOL}
KOL,
{$endif}
{$ifdef KOLERROR}
err
{$else}
{$ifdef UNITSCOPENAMES}System.SysUtils{$else}SysUtils{$endif}
{$endif};
type
// standard types
{$ifdef FPC}
PUInt64 = ^UInt64;
PBoolean = ^Boolean;
PString = ^string;
{$else}
{$if CompilerVersion < 15}
UInt64 = Int64;
PUInt64 = ^UInt64;
{$ifend}
{$if CompilerVersion < 19}
NativeInt = Integer;
NativeUInt = Cardinal;
{$ifend}
{$if CompilerVersion < 22}
PNativeInt = ^NativeInt;
PNativeUInt = ^NativeUInt;
{$ifend}
{$endif}
{$if Defined(FPC) or (CompilerVersion < 23)}
TExtended80Rec = Extended;
PExtended80Rec = ^TExtended80Rec;
{$ifend}
TBytes = {$if (not Defined(FPC)) and (CompilerVersion >= 23)}TArray<Byte>{$else}array of Byte{$ifend};
PBytes = ^TBytes;
{$ifNdef EXTENDEDRTTI}
TCallConv = (ccReg, ccCdecl, ccPascal, ccStdCall, ccSafeCall);
{$endif}
// exception class
ELua = class(Exception)
{$ifdef KOLERROR}
constructor Create(const Msg: string);
constructor CreateFmt(const Msg: string; const Args: array of const);
constructor CreateRes(Ident: NativeUInt); overload;
constructor CreateRes(ResStringRec: PResStringRec); overload;
constructor CreateResFmt(Ident: NativeUInt; const Args: array of const); overload;
constructor CreateResFmt(ResStringRec: PResStringRec; const Args: array of const); overload;
{$endif}
end;
// CrystalLUA string types
{$ifNdef UNICODE}
UnicodeString = WideString;
PUnicodeString = PWideString;
{$endif}
{$ifdef NEXTGEN}
AnsiChar = Byte;
PAnsiChar = PByte;
AnsiString = TBytes;
WideString = UnicodeString;
PWideString = PUnicodeString;
ShortString = array[Byte] of Byte;
PShortString = ^ShortString;
{$endif}
LuaString = UnicodeString;
PLuaString = PUnicodeString;
{$ifNdef UNICODE}
{$define LUA_LENGTH_SHIFT}
{$endif}
LuaChar = WideChar;
PLuaChar = PWideChar;
// internal string identifier: utf8 or ansi
__luaname = type PAnsiChar;
// internal character pointer: utf8 or ansi
__luadata = type PAnsiChar;
// internal character storage: utf8 or ansi
__luabuffer = type AnsiString;
// internal memory offset (optional pointer in 32-bit platforms)
__luapointer = type Integer;
// internal parametrized function
__luafunction = type {$ifdef LUA_NATIVEFUNC}Pointer{$else}Integer{$endif};
// internal containers
__TLuaMemoryHeap = array[1..12{$ifdef LARGEINT}* 2{$endif}] of Byte;
__TLuaStack = array[1..12{$ifdef LARGEINT}* 2{$endif}] of Byte;
__TLuaBuffer = array[1..12{$ifdef LARGEINT}* 2{$endif}] of Byte;
__TLuaDictionary = array[1..20{$ifdef LARGEINT}* 2{$endif}] of Byte;
__TLuaStringDictionary = array[1..28{$ifdef LARGEINT}* 2{$endif}] of Byte;
__TLuaInvokableBuilder = array[1..28{$ifdef LARGEINT}* 2{$endif}] of Byte;
type
TLua = class;
PLuaMetaType = ^TLuaMetaType;
PLuaArg = ^TLuaArg;
// incorrect script use exception
ELuaScript = class(ELua);
// script stack overflow
ELuaStackOverflow = class(ELuaScript);
// Lua types, that is used between script and native side
TLuaArgType = (
// simple types
ltEmpty, ltBoolean, ltInteger, ltDouble, ltPointer, ltString,
// difficult types
ltClass, ltObject, ltRecord, ltArray, ltSet, ltTable
{ToDo: ltInterface, ltMethod, ltReference }
);
PLuaArgType = ^TLuaArgType;
// internal base stucture for records, arrays, sets, etc (inside TLuaArg)
TLuaDifficultType = object
protected
FAlign: array[0..1] of Byte; {FLuaType + reserved}
FIsRef: Boolean;
FIsConst: Boolean;
public
Data: Pointer;
{ info: information type }
property IsRef: Boolean read FIsRef write FIsRef;
property IsConst: Boolean read FIsConst write FIsConst;
end;
// record instance information: Pointer/IsRef/IsConst/RecordInfo
PLuaRecordInfo = ^TLuaRecordInfo;
TLuaRecord = object(TLuaDifficultType)
public
Info: PLuaRecordInfo;
end;
PLuaRecord = ^TLuaRecord;
// array instance information: Pointer/IsRef/IsConst/ArrayInfo
PLuaArrayInfo = ^TLuaArrayInfo;
TLuaArray = object(TLuaDifficultType)
public
Info: PLuaArrayInfo;
end;
PLuaArray = ^TLuaArray;
// set instance information: Pointer/IsRef/IsConst/SetInfo
PLuaSetInfo = ^TLuaSetInfo;
TLuaSet = object(TLuaDifficultType)
public
Info: PLuaSetInfo;
end;
PLuaSet = ^TLuaSet;
// universal CrystalLUA argument
TLuaArg = object
private
FInterface: IInterface;
{$ifdef AUTOREFCOUNT}
FObject: TObject;
{$endif}
FString: LuaString;
F: packed record
LuaType: TLuaArgType;
AdvancedData: array[0..2] of Byte; { used in TLuaRecord/TLuaArray etc }
case Integer of
0: (VDouble: Double);
1: (VBoolean: Boolean);
2: (VPointer: Pointer);
3: (VInteger: Integer);
4: (VNativeInt: NativeInt);
5: (VData: Pointer; VInfo: Pointer; VCode: Pointer);
end;
function TypeException(const AType: TLuaArgType): ELua;
function VariantException: ELua;
procedure CheckDifficultSetter(const AValue: TLuaDifficultType; const AName: PChar; const AReturnAddress: Pointer);
function GetLuaTypeName: string;
function GetEmpty: Boolean;
procedure SetEmpty(const AValue: Boolean);
function GetBoolean: Boolean;
procedure SetBoolean(const AValue: Boolean);
function GetInteger: Integer;
procedure SetInteger(const AValue: Integer);
function GetDouble: Double;
procedure SetDouble(AValue: Double);
function GetString: LuaString;
procedure SetString(const AValue: LuaString);
function GetPointer: Pointer;
procedure SetPointer(const AValue: Pointer);
function GetVariant: Variant;
procedure SetVariant(const AValue: Variant);
function GetClass: TClass;
procedure SetClass(const AValue: TClass);
function GetObject: TObject;
procedure SetObject(const AValue: TObject);
function GetRecord: TLuaRecord;
procedure SetRecord(const AValue: TLuaRecord);
function GetArray: TLuaArray;
procedure SetArray(const AValue: TLuaArray);
function GetSet: TLuaSet;
procedure SetSet(const AValue: TLuaSet);
public
property LuaType: TLuaArgType read F.LuaType;
property LuaTypeName: string read GetLuaTypeName;
property Empty: Boolean read GetEmpty write SetEmpty;
property AsBoolean: Boolean read GetBoolean write SetBoolean;
property AsInteger: Integer read GetInteger write SetInteger;
property AsDouble: Double read GetDouble write SetDouble;
property AsString: LuaString read GetString write SetString;
property AsPointer: Pointer read GetPointer write SetPointer;
property AsVariant: Variant read GetVariant write SetVariant;
property AsClass: TClass read GetClass write SetClass;
property AsObject: TObject read GetObject write SetObject;
property AsRecord: TLuaRecord read GetRecord write SetRecord;
property AsArray: TLuaArray read GetArray write SetArray;
property AsSet: TLuaSet read GetSet write SetSet;
function ForceBoolean: Boolean;
function ForceInteger: NativeInt;
function ForceDouble: Double;
function ForceString: LuaString;
function ForcePointer: Pointer;
function ForceVariant: Variant;
function ForceClass: TClass;
function ForceObject: TObject;
function ForceRecord: TLuaRecord;
function ForceArray: TLuaArray;
function ForceSet: TLuaSet;
end;
TLuaArgDynArray = array of TLuaArg;
PLuaArgDynArray = ^TLuaArgDynArray;
TLuaArgList = array[0..High(Integer) div SizeOf(TLuaArg) - 1] of TLuaArg;
PLuaArgList = ^TLuaArgList;
TLuaArgs = packed record
Items: PLuaArgList;
Count: Integer;
end;
PLuaArgs = ^TLuaArgs;
{ TLuaArguments object
Temporary argument and memory manager for script and universal functions }
TLuaArguments = object
protected
F: packed record
case Integer of
0: (
ParamArgs: TLuaArgs;
ResultArgs: TLuaArgs;
ParamCapacity: Integer;
ResultCapacity: Integer;
);
1: (
Args: array[0..1] of TLuaArgs;
Capacities: array[0..1] of Integer;
)
end;
FHeap: __TLuaMemoryHeap;
FHeapCurrent: PByte;
FHeapOverflow: PByte;
FHeapEmpty: NativeInt;
FAllocatedMetaTypes: Pointer;
procedure GrowSetArgsCount(const AValue: Integer; const AIndex: NativeInt);
procedure SetArgsCount(const AValue: Integer; const AIndex: NativeInt);
procedure SetParamCount(const AValue: Integer); {$ifdef INLINESUPPORT}inline;{$endif}
procedure SetResultCount(const AValue: Integer); {$ifdef INLINESUPPORT}inline;{$endif}
function GrowAdd: PLuaArg;
function GrowAlloc(const ASize: NativeUInt): Pointer;
function AllocMetaType(const AMetaType: PLuaMetaType): Pointer;
procedure Clear;
procedure Finalize;
public
function AllocRecord(const AInfo: PLuaRecordInfo): Pointer;
function AllocArray(const AInfo: PLuaArrayInfo): Pointer;
function AllocSet(const AInfo: PLuaSetInfo): Pointer;
function Add: PLuaArg;
function AddRecord(const AInfo: PLuaRecordInfo): Pointer;
function AddArray(const AInfo: PLuaArrayInfo): Pointer;
function AddSet(const AInfo: PLuaSetInfo): Pointer;
property ParamArgs: TLuaArgs read F.ParamArgs;
property Params: PLuaArgList read F.ParamArgs.Items;
property ParamCount: Integer read F.ParamArgs.Count;
property ResultArgs: TLuaArgs read F.ResultArgs;
property Results: PLuaArgList read F.ResultArgs.Items;
property ResultCount: Integer read F.ResultArgs.Count write SetResultCount;
end;
PLuaArguments = ^TLuaArguments;
TLuaScriptFrame = packed record
Arguments: TLuaArguments;
Buffer: TBytes;
BufferCapacity: NativeUInt;
end;
PLuaScriptFrame = ^TLuaScriptFrame;
TLuaReference = (lrDefault, lrWeak, lrUnsafe);
PLuaReference = ^TLuaReference;
TLuaPropAccessMode = (amNone, amInstField, amInstProc, amStaticField, amStaticProc);
PLuaPropAccessMode = ^TLuaPropAccessMode;
TLuaMethodKind = (mkStatic, mkInstance, mkClass, mkConstructor, mkDestructor, {ToDo}mkOperator);
PLuaMethodKind = ^TLuaMethodKind;
TLuaProcCallback = procedure(const AArgs: PLuaArgList; const AArguments: PLuaArguments);
TLuaMethodCallback = procedure(const AInstance: Pointer; const AArgs: PLuaArgList; const AArguments: PLuaArguments);
TLuaPropAccess = packed record
Mode: TLuaPropAccessMode;
Reference: TLuaReference;
case Integer of
0: (Offset: NativeUInt);
1: (Address: Pointer);
end;
PLuaPropAccess = ^TLuaPropAccess;
TLuaProcParam = packed record
Name: LuaString;
TypeInfo: PTypeInfo;
Flags: TParamFlags;
PointerDepth: Integer;
end;
PLuaProcParam = ^TLuaProcParam;
TLuaMetaKind = (mtClass, mtInterface, mtRecord, mtArray, mtSet);
PLuaMetaKind = ^TLuaMetaKind;
TLuaMetaType = object
protected
F: record
Marker: Integer;
Kind: TLuaMetaKind;
Weak: Boolean;
Managed: Boolean;
HFA: Boolean;
Size: Integer;
{$ifdef LARGEINT}
Ptr: __luapointer;
{$endif}
Ref: Integer;
case Integer of
0: (TypeInfo: PTypeInfo);
1: (ClassType: TClass);
end;
FLua: TLua;
FName: LuaString;
FNameSpace: __TLuaDictionary;
// ToDo
{.$ifdef SMALLINT}
function GetPtr: __luapointer; {$ifdef INLINESUPPORT}inline;{$endif}
{.$endif}
procedure CheckInstance(const AKind: TLuaMetaKind; const AReturnAddress: Pointer);
procedure FillManagedValue;
procedure FillHFAValue;
function GetHFAElementType: TFloatType;
function GetHFAElementCount: Integer;
function GetReturnReferenced: Boolean;
protected
property Kind: TLuaMetaKind read F.Kind;
property Ptr: __luapointer read GetPtr;//{$ifdef SMALLINT}GetPtr{$else .LARGEINT}F.Ptr{$endif};
property Ref: Integer read F.Ref;
property Weak: Boolean read F.Weak;
property Managed: Boolean read F.Managed;
property HFA: Boolean read F.HFA;
property HFAElementType: TFloatType read GetHFAElementType;
property HFAElementCount: Integer read GetHFAElementCount;
property ReturnReferenced: Boolean read GetReturnReferenced;
function ParamReferenced(const ACallConv: TCallConv = ccReg; const AIsConst: Boolean = True): Boolean;
procedure Dispose(const AValue: Pointer{/TObject/IInterface});
procedure Clear(var AInstance; const AFillZero: Boolean);
procedure Assign(var AInstance; const AValue: Pointer{/TObject/IInterface});
public
property Lua: TLua read FLua;
property Name: LuaString read FName;
property Size: Integer read F.Size;
end;
// operators
TLuaOperator = (loNeg, loAdd, loSub, loMul, loDiv, loMod, loPow, loCompare);
PLuaOperator = ^TLuaOperator;
TLuaOperators = set of TLuaOperator;
PLuaOperators = ^TLuaOperators;
TLuaOperatorCallback = procedure(var AResult, ALeft, ARight; const AKind: TLuaOperator);
// all information (such as name, field, methods)
// you should use it to operate records between native and script
TLuaRecordInfo = object(TLuaMetaType)
protected
FOperators: TLuaOperators;
FOperatorCallback: TLuaOperatorCallback;
procedure SetOperators(const AValue: TLuaOperators);
procedure SetOperatorCallback(const AValue: TLuaOperatorCallback);
public
procedure RegMethod(const AMethodName: LuaString; const ACallback: TLuaMethodCallback; const AMinArgsCount: Word = 0; const AMaxArgsCount: Word = High(Word); const AIsStatic: Boolean = False); overload;
procedure RegMethod(const AMethodName: LuaString; const AAddress: Pointer; const ATypeInfo: PTypeInfo; const AIsStatic: Boolean = False); overload;
procedure RegMethod(const AMethodName: LuaString; const AAddress: Pointer;
const AParams: array of TLuaProcParam;
const AResultType: PTypeInfo = nil; const AIsResultUnsafe: Boolean = False;
const AIsStatic: Boolean = False; const ACallConv: TCallConv = ccReg); overload;
procedure RegField(const AName: LuaString; const AOffset: NativeUInt; const ATypeInfo: Pointer; const AReference: TLuaReference = lrDefault); overload;
procedure RegField(const AName: LuaString; const AField: Pointer; const ATypeInfo: Pointer; const ARecord: Pointer = nil; const AReference: TLuaReference = lrDefault); overload;
procedure RegClassField(const AName: LuaString; const AAddress: Pointer; const ATypeInfo: Pointer; const AReference: TLuaReference = lrDefault);
procedure RegProperty(const AName: LuaString; const AGetter, ASetter: TLuaPropAccess;
const ATypeInfo: PTypeInfo; const AConstRefHint: Boolean = True; const AIndex: Integer = Low(Integer));
procedure RegComplexProperty(const AName: LuaString;
const AGetter, ASetter: TLuaPropAccess; const AArguments: array of TLuaProcParam;
const ATypeInfo: PTypeInfo; const ADefault: Boolean = False;
const AConstRefHint: Boolean = True; const AIndex: Integer = Low(Integer));
property Operators: TLuaOperators read FOperators write SetOperators;
property OperatorCallback: TLuaOperatorCallback read FOperatorCallback write SetOperatorCallback;
end;
// information needed to use arrays between native and script side
TLuaArrayInfo = object(TLuaMetaType)
protected
// basics
FIsDynamic: Boolean;
FDimention: Integer;
FBounds: PInteger; // static array bounds
FItemSize: Integer;
// finalizations
FFinalTypeInfo: PTypeInfo; // final item type info or self for dynamic
FFinalItemsCount: Integer;
// managing: multiplies (static), typeinfo (dynamic)
FMultiplies: array[0..0] of NativeInt;
public
property IsDynamic: Boolean read FIsDynamic;
property Dimention: Integer read FDimention;
property Bounds: PInteger read FBounds;
property ItemSize: Integer read FItemSize;
end;
// information needed to use sets between native and script side
TLuaSetInfo = object(TLuaMetaType)
protected
FItemTypeInfo: PTypeInfo;
FLow: Integer;
FHigh: Integer;
FCorrection: Integer;
FRealSize: Integer;
FAndMasks: Integer;
function Description(const AValue: Pointer): LuaString;
public
property Low: Integer read FLow;
property High: Integer read FHigh;
end;
// (internal) information needed to use interfaces between native and script side
PLuaInterfaceInfo = ^TLuaInterfaceInfo;
TLuaInterfaceInfo = object(TLuaMetaType)
Parent: __luapointer;
Count: Integer;
function InheritsFrom(const AValue: PLuaInterfaceInfo): Boolean;
end;
// (internal) information needed to use classes between native and script side
PLuaClassInfo = ^TLuaClassInfo;
TLuaClassInfo = object(TLuaMetaType)
protected
function VmtOffset(const AProc: Pointer; const AStandardProcs: Boolean): NativeInt;
public
// lua_CFunction
CFunctionCreate, CFunctionFree: Pointer;
// special registered method
AssignCallback: Pointer;
CreateCallback: Pointer;
CreateCallbackArgsCount: Integer;
// advanced
Parent: __luapointer;
DefaultProperty: __luapointer{inherited bit reset};
property ClassType: TClass read F.ClassType;
end;
TLuaScriptBOM = (sbNone, sbUTF8, sbUTF16, sbUTF16BE, cbUTF32, cbUTF32BE);
PLuaScriptBOM = ^TLuaScriptBOM;
TLuaBufferUnique = function(var AData: __luabuffer): NativeInt;
TLuaOnPreprocessScript = procedure(var AData, ASource: __luabuffer; var AOffset: Integer; const AUnitName: LuaString; const AUnique: TLuaBufferUnique) of object;
TLuaUnitLine = record
Chars: __luadata;
Count: Integer;
end;
PLuaUnitLine = ^TLuaUnitLine;
TLuaUnit = class(TObject)
private
FLua: TLua;
FIndex: Integer;
FName: LuaString;
FNameLength: Integer;
FData: __luabuffer;
FDataOffset: Integer;
FFileName: string;
FLinesCount: Integer;
FLines: array of TLuaUnitLine;
function GetItem(const AIndex: Integer): LuaString;
function GetLine(const AIndex: Integer): TLuaUnitLine;
procedure InitializeLines;
public
procedure SaveToFile(const AFileName: string); overload;
procedure SaveToFile; overload;
property Lua: TLua read FLua;
property Index: Integer read FIndex;
property Name: LuaString read FName;
property FileName: string read FFileName;
property Data: __luabuffer read FData;
property LinesCount: Integer read FLinesCount;
property Items[const Index: Integer]: LuaString read GetItem; default;
property Lines[const Index: Integer]: TLuaUnitLine read GetLine;
end;
{ TLua class
Script and registered types/functions manager }
TLuaOnRegisterError = function(const APath, AError: LuaString; const ACallDepth: Integer; const ACritical: Boolean): Boolean of object;
TLua = class(TInterfacedObject)
protected
// unicode routine
FCodePage: Word;
FUnicodeTable: array[Byte] of Word;
FUTF8Table: array[Byte] of Cardinal;
procedure SetCodePage(AValue: Word);
function AnsiFromUnicode(ATarget: PAnsiChar; ACodePage: Word; ASource: PWideChar; ALength: Integer): Integer;
procedure UnicodeFromAnsi(ATarget: PWideChar; ASource: PAnsiChar; ACodePage: Word; ALength: Integer);
{ class function Utf8FromUnicode(ATarget: PAnsiChar; ASource: PWideChar; ALength: Integer): Integer; static; }
{ class function UnicodeFromUtf8(ATarget: PWideChar; ASource: PAnsiChar; ALength: Integer): Integer; static; }
function Utf8FromAnsi(ATarget: PAnsiChar; ASource: PAnsiChar; ACodePage: Word; ALength: Integer): Integer;
function AnsiFromUtf8(ATarget: PAnsiChar; ACodePage: Word; ASource: PAnsiChar; ALength: Integer): Integer;
function AnsiFromAnsi(ATarget: PAnsiChar; ATargetCodePage: Word; ASource: PAnsiChar; ASourceCodePage: Word; ALength: Integer): Integer;
protected
// stack helpers
FHandle: Pointer;
FInternalBuffer: __TLuaBuffer;
FInvokableBuilder: __TLuaInvokableBuilder;
FStringBuffer: record
{$ifNdef NEXTGEN}
Short: ShortString;
Ansi: AnsiString;
Wide: WideString;
{$endif}
Unicode: UnicodeString;
UnicodeReserved: UnicodeString;
Lua: LuaString;
LuaReserved: LuaString;
Default: string;
end;
FTempBuffer: packed record
V: Variant;
Intf: IInterface;
O: TObject;
M: TLuaOnPreprocessScript{TMethod};
MUnsafe: TMethod;
A: TLuaArg;
case Integer of
0: (B: Boolean);
1: (D: Double);
2: (E: Extended);
3: (I: Integer);
4: (C: Cardinal);
5: (I64: Int64);
6: (N: NativeInt);
end;
FParamBuffer: packed record
UserData: Pointer{PLuaUserData};
Prop: Pointer{PLuaProperty};
end;
procedure unpack_lua_string(var AResult: LuaString; const ARttiName: ShortString); overload;
procedure unpack_lua_string(var AResult: LuaString; const AChars: __luadata; const ACount: Integer); overload;
procedure unpack_lua_string(var AResult: LuaString; const AName: __luaname); overload;
procedure unpack_lua_string(var AResult: LuaString; const ABuffer: __luabuffer); overload;
procedure push_ansi_chars(const S: PAnsiChar; const ACodePage: Word; const ACount: Integer);
procedure push_utf8_chars(const S: PAnsiChar; const ACount: Integer);
procedure push_wide_chars(const S: PWideChar; const ACount: Integer);
{$ifNdef NEXTGEN}
procedure push_short_string(const S: ShortString);
procedure push_ansi_string(const S: AnsiString);
procedure push_wide_string(const S: WideString);
{$endif}
procedure push_unicode_string(const S: UnicodeString);
procedure push_lua_string(const S: LuaString); {$ifdef INLINESUPPORTSIMPLE}inline;{$endif}
{$ifNdef NEXTGEN}
procedure stack_short_string(var S: ShortString; const AStackIndex: Integer; const AMaxLength: Integer);
procedure stack_ansi_string(var S: AnsiString; const AStackIndex: Integer; const ACodePage: Word);
procedure stack_wide_string(var S: WideString; const AStackIndex: Integer);
{$endif}
procedure stack_unicode_string(var S: UnicodeString; const AStackIndex: Integer);
procedure stack_lua_string(var S: LuaString; const AStackIndex: Integer); {$ifdef INLINESUPPORTSIMPLE}inline;{$endif}
procedure stack_force_unicode_string(var S: UnicodeString; const AStackIndex: Integer; const AExtendedMode: Boolean = True);
function push_metatype_instance(const AMetaType: PLuaMetaType; const ASource; const AOwner, ATemporary: Boolean): Pointer{PLuaUserData};
function push_complex_property(const APropertyInfo; const AInstance: Pointer): Pointer{PLuaUserData};
function push_luaarg(const AValue: TLuaArg): Boolean;
function push_variant(const AValue: Variant): Boolean;
function push_argument(const AValue: TVarRec): Boolean;
procedure stack_pop(const ACount: Integer = 1);
function stack_variant(var AResult: Variant; const AStackIndex: Integer; const AOleMode: Boolean): Boolean;
function stack_luaarg(var AResult: TLuaArg; const AStackIndex: integer; const AAllowLuaTable: Boolean): Boolean;
protected
// global name space
FRef: Integer;
FEmptyRefs: __TLuaStack;
FMemoryHeap: __TLuaMemoryHeap;
FNames: __TLuaStringDictionary {TLuaNames: <LuaString,__luaname>};
FMetaTypes: __TLuaDictionary {Pointer, PLuaMetaType};
FClosureTypes: __TLuaDictionary {PTypeInfo, PLuaClosureType};
FGlobalEntities: __TLuaDictionary {__luaname, PLuaGlobalEntity};
FGlobalMetaTable: Integer;
FFormatWrapper: Integer;
FObjectMetaType: PLuaClassInfo;
// standard name spaces
FStdObjectNameSpace: __TLuaDictionary;
FStdInterfaceNameSpace: __TLuaDictionary;
FStdRecordNameSpace: __TLuaDictionary;
FStdArrayNameSpace: __TLuaDictionary;
FStdSetNameSpace: __TLuaDictionary;
// special meta tables
FClosureMetaTable: Integer;
// internal reference table
function global_alloc_ref: Integer;
procedure global_free_ref(var ARef: Integer);
procedure global_fill_value(const ARef: Integer);
procedure global_push_value(const ARef: Integer);
// public globals
function GetGlobalEntity(const AName: LuaString; const AModeCreate: Boolean): Pointer{PLuaGlobalEntity};
function GetRecordInfo(const AName: LuaString): PLuaRecordInfo;
function GetArrayInfo(const AName: LuaString): PLuaArrayInfo;
function GetSetInfo(const AName: LuaString): PLuaSetInfo;
function GetVariable(const AName: LuaString): Variant;
procedure SetVariable(const AName: LuaString; const AValue: Variant);
function GetVariableEx(const AName: LuaString): TLuaArg;
procedure SetVariableEx(const AName: LuaString; const AValue: TLuaArg);
function GetTableVariable(const ATable, AName: LuaString): Variant;
procedure SetTableVariable(const ATable, AName: LuaString; const AValue: Variant);
function GetTableVariableEx(const ATable, AName: LuaString): TLuaArg;
procedure SetTableVariableEx(const ATable, AName: LuaString; const AValue: TLuaArg);
private
// registrations
{$ifdef LUA_NATIVEFUNC}
FCFunctionHeap: array[1..8{$ifdef LARGEINT}* 2{$endif}] of Byte{TLuaCFunctionHeap};
{$endif}
FRegisteredTypeNames: __TLuaStringDictionary {TLuaRegisteredTypeNames: <LuaString,PLuaRegisteredTypeName>};
function alloc_luafunction(const ACallback: Pointer; const P1, P2: __luapointer): __luafunction; overload;
function alloc_luafunction(const AMethod: Pointer{PLuaMethod}): __luafunction; overload;
procedure alloc_push_luafunction(const ACallback: Pointer; const P1, P2: __luapointer);
procedure push_luafunction(const AFunction: __luafunction);
function function_topointer(const AStackIndex: Integer): Pointer;
function alloc_push_closure(const AReferenceOwner: Boolean): Pointer{PLuaClosureMethod};
procedure InternalRegisterCallback(const AName: __luaname; const ACallback: Pointer; const P1: __luapointer = -1; const P2: __luapointer = -1);
procedure InternalRegTypeName(const ATypeName: LuaString; const ATypeInfo: PTypeInfo; const APointerDepth: Integer);
procedure InternalRegStandardTypeNames;
function InternalNewMetaTable: Integer;
function InternalRegisterMetaTable(const AMetaType: PLuaMetaType = nil): Integer;
function InternalTableToMetaType(const AStackIndex: Integer): PLuaMetaType;
function InternalAddGlobal(const AKind: Byte{TLuaGlobalKind}; const AName: __luaname): Pointer{PLuaGlobalEntity};
function InternalAddMetaType(const AKind: TLuaMetaKind; const AName: LuaString; const ATypeInfo: Pointer;
const AInstanceSize: Integer; const AAdditionalSize: NativeInt = 0): PLuaMetaType;
procedure InternalReplaceChildNameSpace(const AParentMetaItem: Pointer{PLuaDictionaryItem};
const AName: __luaname; const ALastValue, AValue: __luapointer; const AIsDefaultProp: Boolean);
function InternalAddMethod(const AMetaType: PLuaMetaType; const AName: LuaString;
const AAddress: Pointer; const AMethodKind: TLuaMethodKind; const AInvokable: __luapointer; const ACritical: Boolean;
{Universal} const AMinArgsCount: Word = 0; const AMaxArgsCount: Word = High(Word)): __luapointer;
function InternalAddProperty(const AName: LuaString; const AOptions: Pointer{PLuaPropertyOptions};
const AAutoRegister, ACritical: Boolean): __luapointer;
function InternalAddField(const AMetaType: PLuaMetaType; const AName: LuaString;
const AOffset: NativeUInt; const ATypeInfo: PTypeInfo; const AReference: TLuaReference;
const AClassField, AAutoRegister, ACritical: Boolean): __luapointer;
function InternalAddClass(const AClass: TClass; const AUseRtti: Boolean; const ACritical: Boolean): PLuaClassInfo;
function InternalGetClassInfo(const AClass: TClass): PLuaClassInfo;
function InternalAddRecord(const ATypeInfo: PTypeInfo; const ACritical: Boolean): PLuaRecordInfo;
function InternalAddRecordEx(const AName: LuaString; const ATypeInfo: Pointer; const AUseRtti: Boolean; const ACritical: Boolean): PLuaRecordInfo;
function InternalAddInterface(const ATypeInfo: PTypeInfo; const ACritical: Boolean): PLuaInterfaceInfo;
function InternalAddArray(const ATypeInfo: PTypeInfo; const ACritical: Boolean): PLuaArrayInfo;
function InternalAddArrayEx(const AIdentifier, AItemTypeInfo: Pointer; const ABounds: array of Integer; const ACritical: Boolean): PLuaArrayInfo;
function InternalAddSet(const ATypeInfo: PTypeInfo; const ACritical: Boolean): PLuaSetInfo;
procedure InternalAddEnum(const ATypeInfo: PTypeInfo; const ACritical: Boolean);
function InternalInvokableBuilderEnter: __TLuaInvokableBuilder;
procedure InternalInvokableBuilderLeave(const AValue: __TLuaInvokableBuilder);
function InternalAutoRegister(const ATypeInfo: PTypeInfo; const AUseRtti: Boolean = True; const ACritical: Boolean = False): Pointer{PLuaMetaType/PLuaClosureType};
function InternalBuildInvokable(const AMetaType: PLuaMetaType; const ATypeInfo: PTypeInfo; const AMethodKind: TLuaMethodKind; const ACritical: Boolean): __luapointer; overload;
function InternalBuildInvokable(const AMetaType: PLuaMetaType; const AName: LuaString; const AParams: array of TLuaProcParam; const AResultType: PTypeInfo; const AIsResultUnsafe: Boolean; const AMethodKind: TLuaMethodKind; const ACallConv: TCallConv; const ACritical: Boolean): __luapointer; overload;
private
// script callbacks helpers
function __print: Integer;
function __printf: Integer;
function __GetUserData(const AMetaType: __luapointer; const ACheckAlreadyDestroyed: Boolean = True): Pointer;
function __GetSelfInstance(const AMethodName: __luaname): Pointer;
function __GetSelfClass(const AMethodName: __luaname; const AAllowInstance: Boolean): TClass;
function __InitTableValues(const AUserData: Pointer{PLuaUserData}; const AStackIndex: Integer): Integer;
function __ExecuteSetMethod(const AUserData: Pointer{PLuaUserData}; const AFirstArgIndex, AArgsCount, AMethod: Integer): Integer;
// specific script callbacks
function __len(const AMetaType: __luapointer): Integer;
function __tostring(const AMetaType: __luapointer): Integer;
function __gc(const AMetaType: __luapointer): Integer;
function __call(const AMetaType: __luapointer; const AParamMode: Boolean): Integer;
function __operator(const AMetaType: __luapointer; const AKind: Cardinal{Byte}): Integer;
function __closuregc: Integer;
// index/newindex helpers
function push_standard(const AMetaType: PLuaMetaType; const AStdIndex: Cardinal): Boolean;
function set_standard(const AMetaType: PLuaMetaType; const AStdIndex: Cardinal): Boolean;
procedure push_prop_tempgetter(const AInstance: Pointer; const AProp: Pointer);
function call_prop_getter(const AInstance: Pointer; const AProp: Pointer): Pointer;
procedure call_prop_setter(const AInstance: Pointer; const AProp: Pointer; const AValue: NativeInt);
// index/newindex
function __index(const AMetaType: __luapointer): Integer;
function __newindex(const AMetaType: __luapointer; const AParamMode: Boolean): Integer;
function __global_index(const AModifyLow, AModifyHigh: Cardinal): Integer;
function __global_newindex(const AModifyLow, AModifyHigh: Cardinal): Integer;
protected
function __InheritsFrom(const AMetaType: PLuaMetaType; const AArgsCount: Integer): Integer;
function __Assign(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __Free(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __ClassCreate(const AMetaType: PLuaMetaType; const AArgsCount: Integer): Integer;
function __IntfAddRef(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __IntfRelease(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __DynArrayInclude(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __DynArrayResize(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __SetInclude(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __SetExclude(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
function __SetContains(const AUserData: Pointer{PLuaUserData}; const AArgsCount: Integer): Integer;
private
// method callbacks
function UniversalMethodCallback(const AMethod: Pointer{PLuaMethod}; const AArgsCount: Integer): Integer;
function InvokableMethodCallback(const AMethod: Pointer{PLuaMethod}; const AInvokableData: Pointer): Integer;
function __MethodCallback(const AMethodLow, AMethodHigh: Cardinal): Integer;
private
// errors
FReturnAddress: Pointer;
FFrames: Pointer{PLuaNativeFrame};
FPrintRegisterError: Boolean;
FOnRegisterError: TLuaOnRegisterError;
procedure NativeFrameEnter(var AFrame{: TLuaNativeFrame}; const AName: PShortString; const ACritical: Boolean);
procedure NativeFrameLeave;
procedure NativeFrameRename(const AName: PShortString);
procedure NativeFrameBufferedRename(var ANameBuffer: ShortString; const AName: LuaString);
procedure InternalError(const AText: LuaString);
procedure InternalErrorFmt(const AFmtStr: LuaString; const AArgs: array of const);
procedure RegisterError(const AText: LuaString);
procedure RegisterErrorFmt(const AFmtStr: LuaString; const AArgs: array of const);
procedure RegisterErrorTypeExists(const AName: LuaString);
private
// scripts and units routine
FOnPreprocessScript: TLuaOnPreprocessScript;
FStackFrames: array[1 - 1..16] of TLuaScriptFrame;
FStackFrameIndex: NativeUInt;
FArguments: PLuaArguments{PLuaScriptFrame};
FUnitCount: Integer;
FUnits: array of TLuaUnit;
procedure CheckScriptError(const AErrCode: Integer; AUnit: TLuaUnit = nil);
function EnterScript(const AReturnAddress: Pointer): Pointer;
procedure LeaveScriptStack(const AReturnAddress: Pointer);
function InternalConvertScript(var AData: __luabuffer): Integer;
procedure InternalPreprocessScript(var ABuffer: __luabuffer; const AOffset: Integer);
function InternalRunScript(var AData: __luabuffer; const AOffset: Integer; const AUnitName: __luaname; const AUnit: TLuaUnit; const AMakeResult: Boolean; var AExceptionAddress: Pointer; const AReturnAddress: Pointer): Exception;
procedure InternalLoadScript(var AData: __luabuffer; const AUnitName: LuaString; const AFileName: string);
function GetUnit(const AIndex: Integer): TLuaUnit;
function GetUnitByName(const AName: LuaString): TLuaUnit;
public
constructor Create;
destructor Destroy; override;
procedure GarbageCollection;
// errors
procedure Error(const AText: LuaString);
procedure ErrorFmt(const AFmtStr: LuaString; const AArgs: array of const);
// scripts
procedure RunScript(const AScript: LuaString);
procedure LoadScript(const AFileName: string); overload;
procedure LoadScript(const ABuffer: Pointer; const ABufferSize: Integer; const ABOM: TLuaScriptBOM; const AUnitName: LuaString = ''); overload;
procedure LoadScript(const AInstance: THandle; const AName, AResType: PChar; const UnitName: LuaString); overload;
procedure LoadScript(const ABuffer: TBytes; const ABOM: TLuaScriptBOM = sbNone; const AUnitName: LuaString = ''); overload;
// methods
function VariableExists(const AName: LuaString): Boolean; overload;
function ProcExists(const AName: LuaString): Boolean; overload;
function VariableExists(const ATable, AName: LuaString): Boolean; overload;
function ProcExists(const ATable, AName: LuaString): Boolean; overload;
function Call(const AProcName: LuaString): TLuaArgs; overload;
function Call(const AProcName: LuaString; const AArgs: array of TLuaArg): TLuaArgs; overload;
function Call(const AProcName: LuaString; const AArgs: array of const): TLuaArgs; overload;
function Call(const ATable, AProcName: LuaString): TLuaArgs; overload;
function Call(const ATable, AProcName: LuaString; const AArgs: array of TLuaArg): TLuaArgs; overload;
function Call(const ATable, AProcName: LuaString; const AArgs: array of const): TLuaArgs; overload;
// registrations
procedure RegTypeName(const ATypeName: LuaString; const ATypeInfo: PTypeInfo; const APointerDepth: Integer = 0);
procedure RegClass(const AClass: TClass; const AUseRtti: Boolean = True);
procedure RegClasses(const AClasses: array of TClass; const AUseRtti: Boolean = True);
function RegRecord(const ATypeInfo: PTypeInfo): PLuaRecordInfo; overload;
function RegRecord(const AName: LuaString; const ATypeInfo: PTypeInfo; const AUseRtti: Boolean = True): PLuaRecordInfo; overload;
function RegArray(const ATypeInfo: PTypeInfo): PLuaArrayInfo; overload;
function RegArray(const AIdentifier: Pointer; const AItemTypeInfo: PTypeInfo; const ABounds: array of Integer): PLuaArrayInfo; overload;
function RegSet(const ATypeInfo: PTypeInfo): PLuaSetInfo;
procedure RegProc(const AProcName: LuaString; const ACallback: TLuaProcCallback; const AMinArgsCount: Word = 0; const AMaxArgsCount: Word = High(Word)); overload;
procedure RegProc(const AProcName: LuaString; const AAddress: Pointer; const ATypeInfo: PTypeInfo); overload;
procedure RegProc(const AProcName: LuaString; const AAddress: Pointer; const AParams: array of TLuaProcParam;
const AResultType: PTypeInfo = nil; const AIsResultUnsafe: Boolean = False;
const ACallConv: TCallConv = ccReg); overload;
procedure RegMethod(const AClass: TClass; const AMethodName: LuaString; const ACallback: TLuaMethodCallback; const AMinArgsCount: Word = 0; const AMaxArgsCount: Word = High(Word); const AMethodKind: TLuaMethodKind = mkInstance); overload;
procedure RegMethod(const AClass: TClass; const AMethodName: LuaString; const AAddress: Pointer; const ATypeInfo: PTypeInfo; const AMethodKind: TLuaMethodKind = mkInstance); overload;
procedure RegMethod(const AClass: TClass; const AMethodName: LuaString; const AAddress: Pointer;
const AParams: array of TLuaProcParam; const AResultType: PTypeInfo = nil; const AIsResultUnsafe: Boolean = False;
const AMethodKind: TLuaMethodKind = mkInstance; const ACallConv: TCallConv = ccReg); overload;
procedure RegProperty(const AClass: TClass; const AName: LuaString;
const AGetter, ASetter: TLuaPropAccess; const ATypeInfo: PTypeInfo;
const AConstRefHint: Boolean = True; const AIndex: Integer = Low(Integer));
procedure RegComplexProperty(const AClass: TClass; const AName: LuaString;
const AGetter, ASetter: TLuaPropAccess; const AArguments: array of TLuaProcParam; const ATypeInfo: PTypeInfo;
const ADefault: Boolean = False; const AConstRefHint: Boolean = True; const AIndex: Integer = Low(Integer));
procedure RegVariable(const AName: LuaString; const AInstance; const AClass: TClass;
const AIsConst: Boolean = False; const AReference: TLuaReference = lrDefault); overload;
procedure RegVariable(const AName: LuaString; const AInstance; const ATypeInfo: PTypeInfo;
const AIsConst: Boolean = False; const AReference: TLuaReference = lrDefault); overload;
procedure RegConst(const AName: LuaString; const AValue: Variant); overload;
procedure RegConst(const AName: LuaString; const AValue: TLuaArg); overload;
procedure RegEnum(const ATypeInfo: PTypeInfo);
// advanced properties
property Arguments: PLuaArguments read FArguments;
property Variable[const Name: LuaString]: Variant read GetVariable write SetVariable;
property VariableEx[const Name: LuaString]: TLuaArg read GetVariableEx write SetVariableEx;
property TableVariable[const Table, Name: LuaString]: Variant read GetTableVariable write SetTableVariable;
property TableVariableEx[const Table, Name: LuaString]: TLuaArg read GetTableVariableEx write SetTableVariableEx;
property RecordInfo[const Name: LuaString]: PLuaRecordInfo read GetRecordInfo;
property ArrayInfo[const Name: LuaString]: PLuaArrayInfo read GetArrayInfo;
property SetInfo[const Name: LuaString]: PLuaSetInfo read GetSetInfo;
// basic properties
property Handle: Pointer read FHandle;
property PrintRegisterError: Boolean read FPrintRegisterError write FPrintRegisterError;
property OnRegisterError: TLuaOnRegisterError read FOnRegisterError write FOnRegisterError;
// script units
property OnPreprocessScript: TLuaOnPreprocessScript read FOnPreprocessScript write FOnPreprocessScript;
property UnitCount: Integer read FUnitCount;
property Units[const Index: Integer]: TLuaUnit read GetUnit;
property UnitByName[const Name: LuaString]: TLuaUnit read GetUnitByName;
end;
const
// special registering methods: constructor and Assign
LUA_CONSTRUCTOR = 'constructor';
LUA_ASSIGN = 'assign';
// special TypeInfo
TypeInfoTClass = PTypeInfo(NativeUInt($7FFF0000));
TypeInfoPointer = PTypeInfo(NativeUInt($7EEE0000));
TypeInfoLuaArg = PTypeInfo(NativeUInt($7DDD0000));
TypeInfoPWideChar = PTypeInfo(NativeUInt($7CCC0000));
TypeInfoPAnsiChar = PTypeInfo(NativeUInt($7BBB0000));
TypeInfoPUTF8Char = PTypeInfo(NativeUInt($7BBB0000) + 65001);
// special complex properties parameters
INDEXED_PROPERTY = PLuaRecordInfo(NativeUInt($7EEEEEEE));
NAMED_PROPERTY = PLuaRecordInfo(NativeUInt($7AAAAAAA));
// all possible operators
ALL_OPERATORS: TLuaOperators = [Low(TLuaOperator)..High(TLuaOperator)];
// helper functions
function CreateLua: TLua;
function LuaPropNone: TLuaPropAccess;
function LuaPropField(const AOffset: NativeUInt; const AReference: TLuaReference = lrDefault): TLuaPropAccess; overload;
function LuaPropField(const AAddress: Pointer; const AReference: TLuaReference = lrDefault): TLuaPropAccess; overload;
function LuaPropField(const AInstance, AAddress: Pointer; const AReference: TLuaReference = lrDefault): TLuaPropAccess; overload;
function LuaPropProc(const AAddress: Pointer; const AReference: TLuaReference = lrDefault): TLuaPropAccess;