forked from DC-SWAT/DreamShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangelscript.h
More file actions
1732 lines (1534 loc) · 55.2 KB
/
angelscript.h
File metadata and controls
1732 lines (1534 loc) · 55.2 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
/*
AngelCode Scripting Library
Copyright (c) 2003-2011 Andreas Jonsson
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
The original version of this library can be located at:
http://www.angelcode.com/angelscript/
Andreas Jonsson
andreas@angelcode.com
*/
//
// angelscript.h
//
// The script engine interface
//
#ifndef ANGELSCRIPT_H
#define ANGELSCRIPT_H
#include <stddef.h>
#ifdef AS_USE_NAMESPACE
#define BEGIN_AS_NAMESPACE namespace AngelScript {
#define END_AS_NAMESPACE }
#define AS_NAMESPACE_QUALIFIER AngelScript::
#else
#define BEGIN_AS_NAMESPACE
#define END_AS_NAMESPACE
#define AS_NAMESPACE_QUALIFIER
#endif
BEGIN_AS_NAMESPACE
// AngelScript version
#define ANGELSCRIPT_VERSION 22200
#define ANGELSCRIPT_VERSION_STRING "2.22.0"
// Data types
class asIScriptEngine;
class asIScriptModule;
class asIScriptContext;
class asIScriptGeneric;
class asIScriptObject;
class asIObjectType;
class asIScriptFunction;
class asIBinaryStream;
class asIJITCompiler;
// Enumerations and constants
// Engine properties
enum asEEngineProp
{
asEP_ALLOW_UNSAFE_REFERENCES = 1,
asEP_OPTIMIZE_BYTECODE = 2,
asEP_COPY_SCRIPT_SECTIONS = 3,
asEP_MAX_STACK_SIZE = 4,
asEP_USE_CHARACTER_LITERALS = 5,
asEP_ALLOW_MULTILINE_STRINGS = 6,
asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7,
asEP_BUILD_WITHOUT_LINE_CUES = 8,
asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9,
asEP_REQUIRE_ENUM_SCOPE = 10,
asEP_SCRIPT_SCANNER = 11,
asEP_INCLUDE_JIT_INSTRUCTIONS = 12,
asEP_STRING_ENCODING = 13,
asEP_PROPERTY_ACCESSOR_MODE = 14,
asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15,
asEP_AUTO_GARBAGE_COLLECT = 16,
asEP_DISALLOW_GLOBAL_VARS = 17
};
// Calling conventions
enum asECallConvTypes
{
asCALL_CDECL = 0,
asCALL_STDCALL = 1,
asCALL_THISCALL = 2,
asCALL_CDECL_OBJLAST = 3,
asCALL_CDECL_OBJFIRST = 4,
asCALL_GENERIC = 5
};
// Object type flags
enum asEObjTypeFlags
{
asOBJ_REF = 0x01,
asOBJ_VALUE = 0x02,
asOBJ_GC = 0x04,
asOBJ_POD = 0x08,
asOBJ_NOHANDLE = 0x10,
asOBJ_SCOPED = 0x20,
asOBJ_TEMPLATE = 0x40,
asOBJ_ASHANDLE = 0x80,
asOBJ_APP_CLASS = 0x100,
asOBJ_APP_CLASS_CONSTRUCTOR = 0x200,
asOBJ_APP_CLASS_DESTRUCTOR = 0x400,
asOBJ_APP_CLASS_ASSIGNMENT = 0x800,
asOBJ_APP_CLASS_COPY_CONSTRUCTOR = 0x1000,
asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR),
asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR),
asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
asOBJ_APP_CLASS_CK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
asOBJ_APP_CLASS_CDK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_CAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_CDAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR),
asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
asOBJ_APP_CLASS_DK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_DAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT),
asOBJ_APP_CLASS_AK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_CLASS_K = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
asOBJ_APP_PRIMITIVE = 0x2000,
asOBJ_APP_FLOAT = 0x4000,
asOBJ_APP_CLASS_ALLINTS = 0x8000,
asOBJ_APP_CLASS_ALLFLOATS = 0x10000,
asOBJ_MASK_VALID_FLAGS = 0x1FFFF,
asOBJ_SCRIPT_OBJECT = 0x80000,
asOBJ_SHARED = 0x100000
};
// Behaviours
enum asEBehaviours
{
// Value object memory management
asBEHAVE_CONSTRUCT,
asBEHAVE_DESTRUCT,
// Reference object memory management
asBEHAVE_FACTORY,
asBEHAVE_LIST_FACTORY,
asBEHAVE_ADDREF,
asBEHAVE_RELEASE,
// Object operators
asBEHAVE_VALUE_CAST,
asBEHAVE_IMPLICIT_VALUE_CAST,
asBEHAVE_REF_CAST,
asBEHAVE_IMPLICIT_REF_CAST,
asBEHAVE_TEMPLATE_CALLBACK,
// Garbage collection behaviours
asBEHAVE_FIRST_GC,
asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC,
asBEHAVE_SETGCFLAG,
asBEHAVE_GETGCFLAG,
asBEHAVE_ENUMREFS,
asBEHAVE_RELEASEREFS,
asBEHAVE_LAST_GC = asBEHAVE_RELEASEREFS,
asBEHAVE_MAX
};
// Return codes
enum asERetCodes
{
asSUCCESS = 0,
asERROR = -1,
asCONTEXT_ACTIVE = -2,
asCONTEXT_NOT_FINISHED = -3,
asCONTEXT_NOT_PREPARED = -4,
asINVALID_ARG = -5,
asNO_FUNCTION = -6,
asNOT_SUPPORTED = -7,
asINVALID_NAME = -8,
asNAME_TAKEN = -9,
asINVALID_DECLARATION = -10,
asINVALID_OBJECT = -11,
asINVALID_TYPE = -12,
asALREADY_REGISTERED = -13,
asMULTIPLE_FUNCTIONS = -14,
asNO_MODULE = -15,
asNO_GLOBAL_VAR = -16,
asINVALID_CONFIGURATION = -17,
asINVALID_INTERFACE = -18,
asCANT_BIND_ALL_FUNCTIONS = -19,
asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20,
asWRONG_CONFIG_GROUP = -21,
asCONFIG_GROUP_IS_IN_USE = -22,
asILLEGAL_BEHAVIOUR_FOR_TYPE = -23,
asWRONG_CALLING_CONV = -24,
asBUILD_IN_PROGRESS = -25,
asINIT_GLOBAL_VARS_FAILED = -26
};
// Context states
enum asEContextState
{
asEXECUTION_FINISHED = 0,
asEXECUTION_SUSPENDED = 1,
asEXECUTION_ABORTED = 2,
asEXECUTION_EXCEPTION = 3,
asEXECUTION_PREPARED = 4,
asEXECUTION_UNINITIALIZED = 5,
asEXECUTION_ACTIVE = 6,
asEXECUTION_ERROR = 7
};
// Message types
enum asEMsgType
{
asMSGTYPE_ERROR = 0,
asMSGTYPE_WARNING = 1,
asMSGTYPE_INFORMATION = 2
};
// Garbage collector flags
enum asEGCFlags
{
asGC_FULL_CYCLE = 1,
asGC_ONE_STEP = 2,
asGC_DESTROY_GARBAGE = 4,
asGC_DETECT_GARBAGE = 8
};
// Token classes
enum asETokenClass
{
asTC_UNKNOWN = 0,
asTC_KEYWORD = 1,
asTC_VALUE = 2,
asTC_IDENTIFIER = 3,
asTC_COMMENT = 4,
asTC_WHITESPACE = 5
};
// Prepare flags
const int asPREPARE_PREVIOUS = -1;
// Config groups
const char * const asALL_MODULES = (const char * const)-1;
// Type id flags
enum asETypeIdFlags
{
asTYPEID_VOID = 0,
asTYPEID_BOOL = 1,
asTYPEID_INT8 = 2,
asTYPEID_INT16 = 3,
asTYPEID_INT32 = 4,
asTYPEID_INT64 = 5,
asTYPEID_UINT8 = 6,
asTYPEID_UINT16 = 7,
asTYPEID_UINT32 = 8,
asTYPEID_UINT64 = 9,
asTYPEID_FLOAT = 10,
asTYPEID_DOUBLE = 11,
asTYPEID_OBJHANDLE = 0x40000000,
asTYPEID_HANDLETOCONST = 0x20000000,
asTYPEID_MASK_OBJECT = 0x1C000000,
asTYPEID_APPOBJECT = 0x04000000,
asTYPEID_SCRIPTOBJECT = 0x08000000,
asTYPEID_TEMPLATE = 0x10000000,
asTYPEID_MASK_SEQNBR = 0x03FFFFFF
};
// Type modifiers
enum asETypeModifiers
{
asTM_NONE = 0,
asTM_INREF = 1,
asTM_OUTREF = 2,
asTM_INOUTREF = 3
};
// GetModule flags
enum asEGMFlags
{
asGM_ONLY_IF_EXISTS = 0,
asGM_CREATE_IF_NOT_EXISTS = 1,
asGM_ALWAYS_CREATE = 2
};
// Compile flags
enum asECompileFlags
{
asCOMP_ADD_TO_MODULE = 1
};
// Function types
enum asEFuncType
{
asFUNC_DUMMY =-1,
asFUNC_SYSTEM = 0,
asFUNC_SCRIPT = 1,
asFUNC_INTERFACE = 2,
asFUNC_VIRTUAL = 3,
asFUNC_FUNCDEF = 4,
asFUNC_IMPORTED = 5
};
//
// asBYTE = 8 bits
// asWORD = 16 bits
// asDWORD = 32 bits
// asQWORD = 64 bits
// asPWORD = size of pointer
//
typedef unsigned char asBYTE;
typedef unsigned short asWORD;
typedef unsigned int asUINT;
typedef size_t asPWORD;
#ifdef __LP64__
typedef unsigned int asDWORD;
typedef unsigned long asQWORD;
typedef long asINT64;
#else
typedef unsigned long asDWORD;
#if defined(__GNUC__) || defined(__MWERKS__)
typedef unsigned long long asQWORD;
typedef long long asINT64;
#else
typedef unsigned __int64 asQWORD;
typedef __int64 asINT64;
#endif
#endif
typedef void (*asFUNCTION_t)();
typedef void (*asGENFUNC_t)(asIScriptGeneric *);
typedef void *(*asALLOCFUNC_t)(size_t);
typedef void (*asFREEFUNC_t)(void *);
typedef void (*asCLEANENGINEFUNC_t)(asIScriptEngine *);
typedef void (*asCLEANMODULEFUNC_t)(asIScriptModule *);
typedef void (*asCLEANCONTEXTFUNC_t)(asIScriptContext *);
typedef void (*asCLEANFUNCTIONFUNC_t)(asIScriptFunction *);
typedef void (*asCLEANOBJECTTYPEFUNC_t)(asIObjectType *);
// This macro does basically the same thing as offsetof defined in stddef.h, but
// GNUC should not complain about the usage as I'm not using 0 as the base pointer.
#define asOFFSET(s,m) ((size_t)(&reinterpret_cast<s*>(100000)->m)-100000)
#define asFUNCTION(f) asFunctionPtr(f)
#if (defined(_MSC_VER) && _MSC_VER <= 1200) || (defined(__BORLANDC__) && __BORLANDC__ < 0x590)
// MSVC 6 has a bug that prevents it from properly compiling using the correct asFUNCTIONPR with operator >
// so we need to use ordinary C style cast instead of static_cast. The drawback is that the compiler can't
// check that the cast is really valid.
// BCC v5.8 (C++Builder 2006) and earlier have a similar bug which forces us to fall back to a C-style cast.
#define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())((r (*)p)(f)))
#else
#define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())(static_cast<r (*)p>(f)))
#endif
#ifndef AS_NO_CLASS_METHODS
class asCUnknownClass;
typedef void (asCUnknownClass::*asMETHOD_t)();
struct asSFuncPtr
{
union
{
// The largest known method point is 20 bytes (MSVC 64bit),
// but with 8byte alignment this becomes 24 bytes. So we need
// to be able to store at least that much.
char dummy[25];
struct {asMETHOD_t mthd; char dummy[25-sizeof(asMETHOD_t)];} m;
struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
} ptr;
asBYTE flag; // 1 = generic, 2 = global func, 3 = method
};
#if defined(__BORLANDC__)
// A bug in BCC (QC #85374) makes it impossible to distinguish const/non-const method overloads
// with static_cast<>. The workaround is to use an _implicit_cast instead.
#if __BORLANDC__ < 0x590
// BCC v5.8 (C++Builder 2006) and earlier have an even more annoying bug which causes
// the "pretty" workaround below (with _implicit_cast<>) to fail. For these compilers
// we need to use a traditional C-style cast.
#define AS_METHOD_AMBIGUITY_CAST(t) (t)
#else
template <typename T>
T _implicit_cast (T val)
{ return val; }
#define AS_METHOD_AMBIGUITY_CAST(t) AS_NAMESPACE_QUALIFIER _implicit_cast<t >
#endif
#else
#define AS_METHOD_AMBIGUITY_CAST(t) static_cast<t >
#endif
#define asMETHOD(c,m) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)())(&c::m))
#define asMETHODPR(c,m,p,r) asSMethodPtr<sizeof(void (c::*)())>::Convert(AS_METHOD_AMBIGUITY_CAST(r (c::*)p)(&c::m))
#else // Class methods are disabled
struct asSFuncPtr
{
union
{
char dummy[25]; // largest known class method pointer
struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
} ptr;
asBYTE flag; // 1 = generic, 2 = global func
};
#endif
struct asSMessageInfo
{
const char *section;
int row;
int col;
asEMsgType type;
const char *message;
};
// API functions
// ANGELSCRIPT_EXPORT is defined when compiling the dll or lib
// ANGELSCRIPT_DLL_LIBRARY_IMPORT is defined when dynamically linking to the
// dll through the link lib automatically generated by MSVC++
// ANGELSCRIPT_DLL_MANUAL_IMPORT is defined when manually loading the dll
// Don't define anything when linking statically to the lib
#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
#if defined(ANGELSCRIPT_EXPORT)
#define AS_API __declspec(dllexport)
#elif defined(ANGELSCRIPT_DLL_LIBRARY_IMPORT)
#define AS_API __declspec(dllimport)
#else // statically linked library
#define AS_API
#endif
#elif defined(__GNUC__)
#if defined(ANGELSCRIPT_EXPORT)
#define AS_API __attribute__((visibility ("default")))
#else
#define AS_API
#endif
#else
#define AS_API
#endif
#ifndef ANGELSCRIPT_DLL_MANUAL_IMPORT
extern "C"
{
// Engine
AS_API asIScriptEngine * asCreateScriptEngine(asDWORD version);
AS_API const char * asGetLibraryVersion();
AS_API const char * asGetLibraryOptions();
// Context
AS_API asIScriptContext * asGetActiveContext();
// Thread support
AS_API int asThreadCleanup();
// Memory management
AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);
AS_API int asResetGlobalMemoryFunctions();
}
#endif // ANGELSCRIPT_DLL_MANUAL_IMPORT
// Interface declarations
class asIScriptEngine
{
public:
// Memory management
virtual int AddRef() const = 0;
virtual int Release() const = 0;
// Engine properties
virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0;
virtual asPWORD GetEngineProperty(asEEngineProp property) const = 0;
// Compiler messages
virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) = 0;
virtual int ClearMessageCallback() = 0;
virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message) = 0;
// JIT Compiler
virtual int SetJITCompiler(asIJITCompiler *compiler) = 0;
virtual asIJITCompiler *GetJITCompiler() const = 0;
// Global functions
virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
virtual asUINT GetGlobalFunctionCount() const = 0;
virtual int GetGlobalFunctionIdByIndex(asUINT index) const = 0;
virtual asIScriptFunction *GetGlobalFunctionByIndex(asUINT index) const = 0;
virtual asIScriptFunction *GetGlobalFunctionByDecl(const char *declaration) const = 0;
// Global properties
virtual int RegisterGlobalProperty(const char *declaration, void *pointer) = 0;
virtual asUINT GetGlobalPropertyCount() const = 0;
virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0) const = 0;
// Object types
virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags) = 0;
virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset) = 0;
virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
virtual int RegisterInterface(const char *name) = 0;
virtual int RegisterInterfaceMethod(const char *intf, const char *declaration) = 0;
virtual asUINT GetObjectTypeCount() const = 0;
virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const = 0;
// String factory
virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv) = 0;
virtual int GetStringFactoryReturnTypeId() const = 0;
// Default array type
virtual int RegisterDefaultArrayType(const char *type) = 0;
virtual int GetDefaultArrayTypeId() const = 0;
// Enums
virtual int RegisterEnum(const char *type) = 0;
virtual int RegisterEnumValue(const char *type, const char *name, int value) = 0;
virtual asUINT GetEnumCount() const = 0;
virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup = 0) const = 0;
virtual int GetEnumValueCount(int enumTypeId) const = 0;
virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
// Funcdefs
virtual int RegisterFuncdef(const char *decl) = 0;
virtual asUINT GetFuncdefCount() const = 0;
virtual asIScriptFunction *GetFuncdefByIndex(asUINT index, const char **configGroup = 0) const = 0;
// Typedefs
virtual int RegisterTypedef(const char *type, const char *decl) = 0;
virtual asUINT GetTypedefCount() const = 0;
virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup = 0) const = 0;
// Configuration groups
virtual int BeginConfigGroup(const char *groupName) = 0;
virtual int EndConfigGroup() = 0;
virtual int RemoveConfigGroup(const char *groupName) = 0;
virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask) = 0;
#ifdef AS_DEPRECATED
// deprecated since 2011-10-04
virtual int SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess) = 0;
#endif
// Script modules
virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0;
virtual int DiscardModule(const char *module) = 0;
// Script functions
virtual asIScriptFunction *GetFunctionById(int funcId) const = 0;
#ifdef AS_DEPRECATED
// deprecated since 2011-10-03
virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const = 0;
#endif
// Type identification
virtual asIObjectType *GetObjectTypeById(int typeId) const = 0;
virtual int GetTypeIdByDecl(const char *decl) const = 0;
virtual const char *GetTypeDeclaration(int typeId) const = 0;
virtual int GetSizeOfPrimitiveType(int typeId) const = 0;
// Script execution
virtual asIScriptContext *CreateContext() = 0;
virtual void *CreateScriptObject(int typeId) = 0;
virtual void *CreateScriptObjectCopy(void *obj, int typeId) = 0;
virtual void CopyScriptObject(void *dstObj, void *srcObj, int typeId) = 0;
virtual void ReleaseScriptObject(void *obj, int typeId) = 0;
virtual void ReleaseScriptObject(void *obj, const asIObjectType *type) = 0;
virtual void AddRefScriptObject(void *obj, int typeId) = 0;
virtual void AddRefScriptObject(void *obj, const asIObjectType *type) = 0;
virtual bool IsHandleCompatibleWithObject(void *obj, int objTypeId, int handleTypeId) const = 0;
// String interpretation
virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, int *tokenLength = 0) const = 0;
// Garbage collection
virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE) = 0;
virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0, asUINT *newObjects = 0, asUINT *totalNewDestroyed = 0) const = 0;
virtual void NotifyGarbageCollectorOfNewObject(void *obj, int typeId) = 0;
virtual void GCEnumCallback(void *reference) = 0;
// User data
virtual void *SetUserData(void *data) = 0;
virtual void *GetUserData() const = 0;
virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback) = 0;
virtual void SetModuleUserDataCleanupCallback(asCLEANMODULEFUNC_t callback) = 0;
virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback) = 0;
virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback) = 0;
virtual void SetObjectTypeUserDataCleanupCallback(asCLEANOBJECTTYPEFUNC_t callback) = 0;
protected:
virtual ~asIScriptEngine() {}
};
class asIScriptModule
{
public:
virtual asIScriptEngine *GetEngine() const = 0;
virtual void SetName(const char *name) = 0;
virtual const char *GetName() const = 0;
// Compilation
virtual int AddScriptSection(const char *name, const char *code, size_t codeLength = 0, int lineOffset = 0) = 0;
virtual int Build() = 0;
virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) = 0;
virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset) = 0;
virtual asDWORD SetAccessMask(asDWORD accessMask) = 0;
// Functions
virtual asUINT GetFunctionCount() const = 0;
virtual int GetFunctionIdByIndex(asUINT index) const = 0;
virtual int GetFunctionIdByName(const char *name) const = 0;
virtual int GetFunctionIdByDecl(const char *decl) const = 0;
virtual asIScriptFunction *GetFunctionByIndex(asUINT index) const = 0;
virtual asIScriptFunction *GetFunctionByDecl(const char *decl) const = 0;
virtual asIScriptFunction *GetFunctionByName(const char *name) const = 0;
#ifdef AS_DEPRECATED
// deprecated since 2011-10-03
virtual asIScriptFunction *GetFunctionDescriptorByIndex(asUINT index) const = 0;
virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) const = 0;
#endif
virtual int RemoveFunction(int funcId) = 0;
// Global variables
virtual int ResetGlobalVars(asIScriptContext *ctx = 0) = 0;
virtual asUINT GetGlobalVarCount() const = 0;
virtual int GetGlobalVarIndexByName(const char *name) const = 0;
virtual int GetGlobalVarIndexByDecl(const char *decl) const = 0;
virtual const char *GetGlobalVarDeclaration(asUINT index) const = 0;
virtual int GetGlobalVar(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0) const = 0;
virtual void *GetAddressOfGlobalVar(asUINT index) = 0;
virtual int RemoveGlobalVar(asUINT index) = 0;
// Type identification
virtual asUINT GetObjectTypeCount() const = 0;
virtual asIObjectType *GetObjectTypeByIndex(asUINT index) const = 0;
virtual int GetTypeIdByDecl(const char *decl) const = 0;
// Enums
virtual asUINT GetEnumCount() const = 0;
virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId) const = 0;
virtual int GetEnumValueCount(int enumTypeId) const = 0;
virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const = 0;
// Typedefs
virtual asUINT GetTypedefCount() const = 0;
virtual const char *GetTypedefByIndex(asUINT index, int *typeId) const = 0;
// Dynamic binding between modules
virtual asUINT GetImportedFunctionCount() const = 0;
virtual int GetImportedFunctionIndexByDecl(const char *decl) const = 0;
virtual const char *GetImportedFunctionDeclaration(asUINT importIndex) const = 0;
virtual const char *GetImportedFunctionSourceModule(asUINT importIndex) const = 0;
virtual int BindImportedFunction(asUINT importIndex, int funcId) = 0;
virtual int UnbindImportedFunction(asUINT importIndex) = 0;
virtual int BindAllImportedFunctions() = 0;
virtual int UnbindAllImportedFunctions() = 0;
// Bytecode saving and loading
virtual int SaveByteCode(asIBinaryStream *out) const = 0;
virtual int LoadByteCode(asIBinaryStream *in) = 0;
// User data
virtual void *SetUserData(void *data) = 0;
virtual void *GetUserData() const = 0;
protected:
virtual ~asIScriptModule() {}
};
class asIScriptContext
{
public:
// Memory management
virtual int AddRef() const = 0;
virtual int Release() const = 0;
// Miscellaneous
virtual asIScriptEngine *GetEngine() const = 0;
// Execution
virtual int Prepare(asIScriptFunction *func) = 0;
virtual int Prepare(int funcId) = 0;
virtual int Unprepare() = 0;
virtual int SetObject(void *obj) = 0;
virtual int Execute() = 0;
virtual int Abort() = 0;
virtual int Suspend() = 0;
virtual asEContextState GetState() const = 0;
// Arguments
virtual int SetArgByte(asUINT arg, asBYTE value) = 0;
virtual int SetArgWord(asUINT arg, asWORD value) = 0;
virtual int SetArgDWord(asUINT arg, asDWORD value) = 0;
virtual int SetArgQWord(asUINT arg, asQWORD value) = 0;
virtual int SetArgFloat(asUINT arg, float value) = 0;
virtual int SetArgDouble(asUINT arg, double value) = 0;
virtual int SetArgAddress(asUINT arg, void *addr) = 0;
virtual int SetArgObject(asUINT arg, void *obj) = 0;
virtual void *GetAddressOfArg(asUINT arg) = 0;
// Return value
virtual asBYTE GetReturnByte() = 0;
virtual asWORD GetReturnWord() = 0;
virtual asDWORD GetReturnDWord() = 0;
virtual asQWORD GetReturnQWord() = 0;
virtual float GetReturnFloat() = 0;
virtual double GetReturnDouble() = 0;
virtual void *GetReturnAddress() = 0;
virtual void *GetReturnObject() = 0;
virtual void *GetAddressOfReturnValue() = 0;
// Exception handling
virtual int SetException(const char *string) = 0;
virtual int GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0;
virtual int GetExceptionFunction() = 0;
virtual const char *GetExceptionString() = 0;
virtual int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
virtual void ClearExceptionCallback() = 0;
// Debugging
virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
virtual void ClearLineCallback() = 0;
virtual asUINT GetCallstackSize() = 0;
virtual asIScriptFunction *GetFunction(asUINT stackLevel = 0) = 0;
virtual int GetLineNumber(asUINT stackLevel = 0, int *column = 0, const char **sectionName = 0) = 0;
virtual int GetVarCount(asUINT stackLevel = 0) = 0;
virtual const char *GetVarName(asUINT varIndex, asUINT stackLevel = 0) = 0;
virtual const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel = 0) = 0;
virtual int GetVarTypeId(asUINT varIndex, asUINT stackLevel = 0) = 0;
virtual void *GetAddressOfVar(asUINT varIndex, asUINT stackLevel = 0) = 0;
virtual bool IsVarInScope(asUINT varIndex, asUINT stackLevel = 0) = 0;
virtual int GetThisTypeId(asUINT stackLevel = 0) = 0;
virtual void *GetThisPointer(asUINT stackLevel = 0) = 0;
// User data
virtual void *SetUserData(void *data) = 0;
virtual void *GetUserData() const = 0;
protected:
virtual ~asIScriptContext() {}
};
class asIScriptGeneric
{
public:
// Miscellaneous
virtual asIScriptEngine *GetEngine() const = 0;
virtual int GetFunctionId() const = 0;
virtual asIScriptFunction *GetFunction() const = 0;
#ifdef AS_DEPRECATED
// deprecated since 2011-10-03
virtual asIScriptFunction *GetFunctionDescriptor() const = 0;
#endif
virtual void *GetFunctionUserData() const = 0;
// Object
virtual void *GetObject() = 0;
virtual int GetObjectTypeId() const = 0;
// Arguments
virtual int GetArgCount() const = 0;
virtual int GetArgTypeId(asUINT arg) const = 0;
virtual asBYTE GetArgByte(asUINT arg) = 0;
virtual asWORD GetArgWord(asUINT arg) = 0;
virtual asDWORD GetArgDWord(asUINT arg) = 0;
virtual asQWORD GetArgQWord(asUINT arg) = 0;
virtual float GetArgFloat(asUINT arg) = 0;
virtual double GetArgDouble(asUINT arg) = 0;
virtual void *GetArgAddress(asUINT arg) = 0;
virtual void *GetArgObject(asUINT arg) = 0;
virtual void *GetAddressOfArg(asUINT arg) = 0;
// Return value
virtual int GetReturnTypeId() const = 0;
virtual int SetReturnByte(asBYTE val) = 0;
virtual int SetReturnWord(asWORD val) = 0;
virtual int SetReturnDWord(asDWORD val) = 0;
virtual int SetReturnQWord(asQWORD val) = 0;
virtual int SetReturnFloat(float val) = 0;
virtual int SetReturnDouble(double val) = 0;
virtual int SetReturnAddress(void *addr) = 0;
virtual int SetReturnObject(void *obj) = 0;
virtual void *GetAddressOfReturnLocation() = 0;
protected:
virtual ~asIScriptGeneric() {}
};
class asIScriptObject
{
public:
// Memory management
virtual int AddRef() const = 0;
virtual int Release() const = 0;
// Type info
virtual int GetTypeId() const = 0;
virtual asIObjectType *GetObjectType() const = 0;
// Class properties
virtual asUINT GetPropertyCount() const = 0;
virtual int GetPropertyTypeId(asUINT prop) const = 0;
virtual const char *GetPropertyName(asUINT prop) const = 0;
virtual void *GetAddressOfProperty(asUINT prop) = 0;
virtual asIScriptEngine *GetEngine() const = 0;
virtual int CopyFrom(asIScriptObject *other) = 0;
protected:
virtual ~asIScriptObject() {}
};
class asIObjectType
{
public:
virtual asIScriptEngine *GetEngine() const = 0;
virtual const char *GetConfigGroup() const = 0;
// Memory management
virtual int AddRef() const = 0;
virtual int Release() const = 0;
// Type info
virtual const char *GetName() const = 0;
virtual asIObjectType *GetBaseType() const = 0;
virtual bool DerivesFrom(const asIObjectType *objType) const = 0;
virtual asDWORD GetFlags() const = 0;
virtual asUINT GetSize() const = 0;
virtual int GetTypeId() const = 0;
virtual int GetSubTypeId() const = 0;
virtual asIObjectType *GetSubType() const = 0;
// Interfaces
virtual asUINT GetInterfaceCount() const = 0;
virtual asIObjectType *GetInterface(asUINT index) const = 0;
virtual bool Implements(const asIObjectType *objType) const = 0;
// Factories
virtual asUINT GetFactoryCount() const = 0;
virtual int GetFactoryIdByIndex(asUINT index) const = 0;
virtual int GetFactoryIdByDecl(const char *decl) const = 0;
virtual asIScriptFunction *GetFactoryByIndex(asUINT index) const = 0;
virtual asIScriptFunction *GetFactoryByDecl(const char *decl) const = 0;
// Methods
virtual asUINT GetMethodCount() const = 0;
virtual int GetMethodIdByIndex(asUINT index, bool getVirtual = true) const = 0;
virtual int GetMethodIdByName(const char *name, bool getVirtual = true) const = 0;
virtual int GetMethodIdByDecl(const char *decl, bool getVirtual = true) const = 0;
virtual asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual = true) const = 0;
virtual asIScriptFunction *GetMethodByName(const char *name, bool getVirtual = true) const = 0;
virtual asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual = true) const = 0;
#ifdef AS_DEPRECATED
// deprecated since 2011-10-03
virtual asIScriptFunction *GetMethodDescriptorByIndex(asUINT index, bool getVirtual = true) const = 0;
#endif
// Properties
virtual asUINT GetPropertyCount() const = 0;
virtual int GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, int *offset = 0, bool *isReference = 0) const = 0;
virtual const char *GetPropertyDeclaration(asUINT index) const = 0;
// Behaviours
virtual asUINT GetBehaviourCount() const = 0;
virtual int GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const = 0;
// User data
virtual void *SetUserData(void *data) = 0;
virtual void *GetUserData() const = 0;
protected:
virtual ~asIObjectType() {}
};
class asIScriptFunction
{
public:
virtual asIScriptEngine *GetEngine() const = 0;
// Memory management
virtual int AddRef() const = 0;
virtual int Release() const = 0;
virtual int GetId() const = 0;
virtual asEFuncType GetFuncType() const = 0;
virtual const char *GetModuleName() const = 0;
virtual const char *GetScriptSectionName() const = 0;
virtual const char *GetConfigGroup() const = 0;
virtual asIObjectType *GetObjectType() const = 0;
virtual const char *GetObjectName() const = 0;
virtual const char *GetName() const = 0;
virtual const char *GetDeclaration(bool includeObjectName = true) const = 0;
virtual bool IsReadOnly() const = 0;
virtual bool IsPrivate() const = 0;
virtual asUINT GetParamCount() const = 0;
virtual int GetParamTypeId(asUINT index, asDWORD *flags = 0) const = 0;
virtual int GetReturnTypeId() const = 0;
// Debug information
virtual asUINT GetVarCount() const = 0;
virtual int GetVar(asUINT index, const char **name, int *typeId = 0) const = 0;
virtual const char * GetVarDecl(asUINT index) const = 0;
virtual int FindNextLineWithCode(int line) const = 0;
// For JIT compilation
virtual asDWORD *GetByteCode(asUINT *length = 0) = 0;
// User data
virtual void *SetUserData(void *userData) = 0;
virtual void *GetUserData() const = 0;
protected:
virtual ~asIScriptFunction() {};
};
class asIBinaryStream
{
public:
virtual void Read(void *ptr, asUINT size) = 0;
virtual void Write(const void *ptr, asUINT size) = 0;
public:
virtual ~asIBinaryStream() {}
};
//-----------------------------------------------------------------
// Function pointers
// Use our own memset() and memcpy() implementations for better portability
inline void asMemClear(void *_p, size_t size)
{
char *p = (char *)_p;
const char *e = p + size;
for( ; p < e; p++ )
*p = 0;
}
inline void asMemCopy(void *_d, const void *_s, size_t size)
{
char *d = (char *)_d;
const char *s = (const char *)_s;
const char *e = s + size;
for( ; s < e; d++, s++ )
*d = *s;
}
// Template function to capture all global functions,
// except the ones using the generic calling convention
template <class T>
inline asSFuncPtr asFunctionPtr(T func)
{
asSFuncPtr p;
asMemClear(&p, sizeof(p));
p.ptr.f.func = (asFUNCTION_t)(size_t)func;
// Mark this as a global function
p.flag = 2;
return p;
}
// Specialization for functions using the generic calling convention
template<>
inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
{
asSFuncPtr p;
asMemClear(&p, sizeof(p));
p.ptr.f.func = (asFUNCTION_t)func;
// Mark this as a generic function
p.flag = 1;
return p;
}
#ifndef AS_NO_CLASS_METHODS
// Method pointers
// Declare a dummy class so that we can determine the size of a simple method pointer
class asCSimpleDummy {};
typedef void (asCSimpleDummy::*asSIMPLEMETHOD_t)();
const int SINGLE_PTR_SIZE = sizeof(asSIMPLEMETHOD_t);