ScummVM API documentation
angelscript.h
1 /*
2  AngelCode Scripting Library
3  Copyright (c) 2003-2020 Andreas Jonsson
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any
7  damages arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any
10  purpose, including commercial applications, and to alter it and
11  redistribute it freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you
14  must not claim that you wrote the original software. If you use
15  this software in a product, an acknowledgment in the product
16  documentation would be appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and
19  must not be misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22  distribution.
23 
24  The original version of this library can be located at:
25  http://www.angelcode.com/angelscript/
26 
27  Andreas Jonsson
28  andreas@angelcode.com
29 */
30 
31 
32 //
33 // angelscript.h
34 //
35 // The script engine interface
36 //
37 
38 
39 #ifndef ANGELSCRIPT_H
40 #define ANGELSCRIPT_H
41 
42 #include <stddef.h>
43 #ifndef _MSC_VER
44 #include <stdint.h>
45 #endif
46 
47 #ifdef AS_USE_NAMESPACE
48 #define BEGIN_AS_NAMESPACE namespace AngelScript {
49 #define END_AS_NAMESPACE }
50 #define AS_NAMESPACE_QUALIFIER AngelScript::
51 #else
52 #define BEGIN_AS_NAMESPACE
53 #define END_AS_NAMESPACE
54 #define AS_NAMESPACE_QUALIFIER ::
55 #endif
56 
57 BEGIN_AS_NAMESPACE
58 
59 // AngelScript version
60 
61 #define ANGELSCRIPT_VERSION 23500
62 #define ANGELSCRIPT_VERSION_STRING "2.35.0"
63 
64 // Data types
65 
66 class asIScriptEngine;
67 class asIScriptModule;
68 class asIScriptContext;
69 class asIScriptGeneric;
70 class asIScriptObject;
71 class asITypeInfo;
72 class asIScriptFunction;
73 class asIBinaryStream;
74 class asIJITCompiler;
75 class asIThreadManager;
77 class asIStringFactory;
78 
79 // Enumerations and constants
80 
81 // Return codes
82 enum asERetCodes {
83  asSUCCESS = 0,
84  asERROR = -1,
85  asCONTEXT_ACTIVE = -2,
86  asCONTEXT_NOT_FINISHED = -3,
87  asCONTEXT_NOT_PREPARED = -4,
88  asINVALID_ARG = -5,
89  asNO_FUNCTION = -6,
90  asNOT_SUPPORTED = -7,
91  asINVALID_NAME = -8,
92  asNAME_TAKEN = -9,
93  asINVALID_DECLARATION = -10,
94  asINVALID_OBJECT = -11,
95  asINVALID_TYPE = -12,
96  asALREADY_REGISTERED = -13,
97  asMULTIPLE_FUNCTIONS = -14,
98  asNO_MODULE = -15,
99  asNO_GLOBAL_VAR = -16,
100  asINVALID_CONFIGURATION = -17,
101  asINVALID_INTERFACE = -18,
102  asCANT_BIND_ALL_FUNCTIONS = -19,
103  asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20,
104  asWRONG_CONFIG_GROUP = -21,
105  asCONFIG_GROUP_IS_IN_USE = -22,
106  asILLEGAL_BEHAVIOUR_FOR_TYPE = -23,
107  asWRONG_CALLING_CONV = -24,
108  asBUILD_IN_PROGRESS = -25,
109  asINIT_GLOBAL_VARS_FAILED = -26,
110  asOUT_OF_MEMORY = -27,
111  asMODULE_IS_IN_USE = -28
112 };
113 
114 // Engine properties
115 enum asEEngineProp {
116  asEP_ALLOW_UNSAFE_REFERENCES = 1,
117  asEP_OPTIMIZE_BYTECODE = 2,
118  asEP_COPY_SCRIPT_SECTIONS = 3,
119  asEP_MAX_STACK_SIZE = 4,
120  asEP_USE_CHARACTER_LITERALS = 5,
121  asEP_ALLOW_MULTILINE_STRINGS = 6,
122  asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7,
123  asEP_BUILD_WITHOUT_LINE_CUES = 8,
124  asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9,
125  asEP_REQUIRE_ENUM_SCOPE = 10,
126  asEP_SCRIPT_SCANNER = 11,
127  asEP_INCLUDE_JIT_INSTRUCTIONS = 12,
128  asEP_STRING_ENCODING = 13,
129  asEP_PROPERTY_ACCESSOR_MODE = 14,
130  asEP_EXPAND_DEF_ARRAY_TO_TMPL = 15,
131  asEP_AUTO_GARBAGE_COLLECT = 16,
132  asEP_DISALLOW_GLOBAL_VARS = 17,
133  asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT = 18,
134  asEP_COMPILER_WARNINGS = 19,
135  asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE = 20,
136  asEP_ALTER_SYNTAX_NAMED_ARGS = 21,
137  asEP_DISABLE_INTEGER_DIVISION = 22,
138  asEP_DISALLOW_EMPTY_LIST_ELEMENTS = 23,
139  asEP_PRIVATE_PROP_AS_PROTECTED = 24,
140  asEP_ALLOW_UNICODE_IDENTIFIERS = 25,
141  asEP_HEREDOC_TRIM_MODE = 26,
142  asEP_MAX_NESTED_CALLS = 27,
143  asEP_GENERIC_CALL_MODE = 28,
144  asEP_INIT_STACK_SIZE = 29,
145  asEP_INIT_CALL_STACK_SIZE = 30,
146  asEP_MAX_CALL_STACK_SIZE = 31,
147 
148  asEP_LAST_PROPERTY
149 };
150 
151 // Calling conventions
152 enum asECallConvTypes {
153  asCALL_CDECL = 0,
154  asCALL_STDCALL = 1,
155  asCALL_THISCALL_ASGLOBAL = 2,
156  asCALL_THISCALL = 3,
157  asCALL_CDECL_OBJLAST = 4,
158  asCALL_CDECL_OBJFIRST = 5,
159  asCALL_GENERIC = 6,
160  asCALL_THISCALL_OBJLAST = 7,
161  asCALL_THISCALL_OBJFIRST = 8
162 };
163 
164 // Object type flags
165 enum asEObjTypeFlags : unsigned int {
166  asOBJ_NULL = 0,
167  asOBJ_REF = (1 << 0),
168  asOBJ_VALUE = (1 << 1),
169  asOBJ_GC = (1 << 2),
170  asOBJ_POD = (1 << 3),
171  asOBJ_NOHANDLE = (1 << 4),
172  asOBJ_SCOPED = (1 << 5),
173  asOBJ_TEMPLATE = (1 << 6),
174  asOBJ_ASHANDLE = (1 << 7),
175  asOBJ_APP_CLASS = (1 << 8),
176  asOBJ_APP_CLASS_CONSTRUCTOR = (1 << 9),
177  asOBJ_APP_CLASS_DESTRUCTOR = (1 << 10),
178  asOBJ_APP_CLASS_ASSIGNMENT = (1 << 11),
179  asOBJ_APP_CLASS_COPY_CONSTRUCTOR = (1 << 12),
180  asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR),
181  asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR),
182  asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
183  asOBJ_APP_CLASS_CK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
184  asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
185  asOBJ_APP_CLASS_CDK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
186  asOBJ_APP_CLASS_CAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
187  asOBJ_APP_CLASS_CDAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
188  asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR),
189  asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
190  asOBJ_APP_CLASS_DK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
191  asOBJ_APP_CLASS_DAK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
192  asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT),
193  asOBJ_APP_CLASS_AK = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
194  asOBJ_APP_CLASS_K = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_COPY_CONSTRUCTOR),
195  asOBJ_APP_CLASS_MORE_CONSTRUCTORS = (1u << 31),
196  asOBJ_APP_PRIMITIVE = (1 << 13),
197  asOBJ_APP_FLOAT = (1 << 14),
198  asOBJ_APP_ARRAY = (1 << 15),
199  asOBJ_APP_CLASS_ALLINTS = (1 << 16),
200  asOBJ_APP_CLASS_ALLFLOATS = (1 << 17),
201  asOBJ_NOCOUNT = (1 << 18),
202  asOBJ_APP_CLASS_ALIGN8 = (1 << 19),
203  asOBJ_IMPLICIT_HANDLE = (1 << 20),
204  asOBJ_MASK_VALID_FLAGS = 0x801FFFFFu,
205  // Internal flags
206  asOBJ_SCRIPT_OBJECT = (1 << 21),
207  asOBJ_SHARED = (1 << 22),
208  asOBJ_NOINHERIT = (1 << 23),
209  asOBJ_FUNCDEF = (1 << 24),
210  asOBJ_LIST_PATTERN = (1 << 25),
211  asOBJ_ENUM = (1 << 26),
212  asOBJ_TEMPLATE_SUBTYPE = (1 << 27),
213  asOBJ_TYPEDEF = (1 << 28),
214  asOBJ_ABSTRACT = (1 << 29),
215  asOBJ_APP_ALIGN16 = (1 << 30)
216 };
217 
218 // Behaviours
219 enum asEBehaviours {
220  // Value object memory management
221  asBEHAVE_CONSTRUCT,
222  asBEHAVE_LIST_CONSTRUCT,
223  asBEHAVE_DESTRUCT,
224 
225  // Reference object memory management
226  asBEHAVE_FACTORY,
227  asBEHAVE_LIST_FACTORY,
228  asBEHAVE_ADDREF,
229  asBEHAVE_RELEASE,
230  asBEHAVE_GET_WEAKREF_FLAG,
231 
232  // Object operators
233  asBEHAVE_TEMPLATE_CALLBACK,
234 
235  // Garbage collection behaviours
236  asBEHAVE_FIRST_GC,
237  asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC,
238  asBEHAVE_SETGCFLAG,
239  asBEHAVE_GETGCFLAG,
240  asBEHAVE_ENUMREFS,
241  asBEHAVE_RELEASEREFS,
242  asBEHAVE_LAST_GC = asBEHAVE_RELEASEREFS,
243 
244  asBEHAVE_MAX
245 };
246 
247 // Context states
248 enum asEContextState {
249  asEXECUTION_FINISHED = 0,
250  asEXECUTION_SUSPENDED = 1,
251  asEXECUTION_ABORTED = 2,
252  asEXECUTION_EXCEPTION = 3,
253  asEXECUTION_PREPARED = 4,
254  asEXECUTION_UNINITIALIZED = 5,
255  asEXECUTION_ACTIVE = 6,
256  asEXECUTION_ERROR = 7
257 };
258 
259 // Message types
260 enum asEMsgType {
261  asMSGTYPE_ERROR = 0,
262  asMSGTYPE_WARNING = 1,
263  asMSGTYPE_INFORMATION = 2
264 };
265 
266 // Garbage collector flags
267 enum asEGCFlags {
268  asGC_FULL_CYCLE = 1,
269  asGC_ONE_STEP = 2,
270  asGC_DESTROY_GARBAGE = 4,
271  asGC_DETECT_GARBAGE = 8
272 };
273 
274 // Token classes
275 enum asETokenClass {
276  asTC_UNKNOWN = 0,
277  asTC_KEYWORD = 1,
278  asTC_VALUE = 2,
279  asTC_IDENTIFIER = 3,
280  asTC_COMMENT = 4,
281  asTC_WHITESPACE = 5
282 };
283 
284 // Type id flags
285 enum asETypeIdFlags {
286  asTYPEID_VOID = 0,
287  asTYPEID_BOOL = 1,
288  asTYPEID_INT8 = 2,
289  asTYPEID_INT16 = 3,
290  asTYPEID_INT32 = 4,
291  asTYPEID_INT64 = 5,
292  asTYPEID_UINT8 = 6,
293  asTYPEID_UINT16 = 7,
294  asTYPEID_UINT32 = 8,
295  asTYPEID_UINT64 = 9,
296  asTYPEID_FLOAT = 10,
297  asTYPEID_DOUBLE = 11,
298  asTYPEID_OBJHANDLE = 0x40000000,
299  asTYPEID_HANDLETOCONST = 0x20000000,
300  asTYPEID_MASK_OBJECT = 0x1C000000,
301  asTYPEID_APPOBJECT = 0x04000000,
302  asTYPEID_SCRIPTOBJECT = 0x08000000,
303  asTYPEID_TEMPLATE = 0x10000000,
304  asTYPEID_MASK_SEQNBR = 0x03FFFFFF
305 };
306 
307 // Type modifiers
308 enum asETypeModifiers {
309  asTM_NONE = 0,
310  asTM_INREF = 1,
311  asTM_OUTREF = 2,
312  asTM_INOUTREF = 3,
313  asTM_CONST = 4
314 };
315 
316 // GetModule flags
317 enum asEGMFlags {
318  asGM_ONLY_IF_EXISTS = 0,
319  asGM_CREATE_IF_NOT_EXISTS = 1,
320  asGM_ALWAYS_CREATE = 2
321 };
322 
323 // Compile flags
324 enum asECompileFlags {
325  asCOMP_ADD_TO_MODULE = 1
326 };
327 
328 // Function types
329 enum asEFuncType {
330  asFUNC_DUMMY = -1,
331  asFUNC_SYSTEM = 0,
332  asFUNC_SCRIPT = 1,
333  asFUNC_INTERFACE = 2,
334  asFUNC_VIRTUAL = 3,
335  asFUNC_FUNCDEF = 4,
336  asFUNC_IMPORTED = 5,
337  asFUNC_DELEGATE = 6
338 };
339 
340 //
341 // asBYTE = 8 bits
342 // asWORD = 16 bits
343 // asDWORD = 32 bits
344 // asQWORD = 64 bits
345 // asPWORD = size of pointer
346 //
347 typedef signed char asINT8;
348 typedef signed short asINT16;
349 typedef unsigned char asBYTE;
350 typedef unsigned short asWORD;
351 typedef unsigned int asUINT;
352 #if (defined(_MSC_VER) && _MSC_VER <= 1200) || defined(__S3E__) || (defined(_MSC_VER) && defined(__clang__))
353 // size_t is not really correct, since it only guaranteed to be large enough to hold the segment size.
354 // For example, on 16bit systems the size_t may be 16bits only even if pointers are 32bit. But nobody
355 // is likely to use MSVC6 to compile for 16bit systems anymore, so this should be ok.
356 typedef size_t asPWORD;
357 #else
358 typedef uintptr_t asPWORD;
359 #endif
360 #ifdef __LP64__
361 typedef unsigned int asDWORD;
362 typedef unsigned long asQWORD;
363 typedef long asINT64;
364 #else
365 typedef unsigned long asDWORD;
366 #if !defined(_MSC_VER) && (defined(__GNUC__) || defined(__MWERKS__) || defined(__SUNPRO_CC) || defined(__psp2__))
367 typedef uint64_t asQWORD;
368 typedef int64_t asINT64;
369 #else
370 typedef unsigned __int64 asQWORD;
371 typedef __int64 asINT64;
372 #endif
373 #endif
374 
375 // Is the target a 64bit system?
376 #if defined(__LP64__) || defined(__amd64__) || defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64)
377 #ifndef AS_64BIT_PTR
378 #define AS_64BIT_PTR
379 #endif
380 #endif
381 
382 typedef void (*asFUNCTION_t)();
383 typedef void (*asGENFUNC_t)(asIScriptGeneric *);
384 typedef void *(*asALLOCFUNC_t)(size_t);
385 typedef void (*asFREEFUNC_t)(void *);
386 typedef void (*asCLEANENGINEFUNC_t)(asIScriptEngine *);
387 typedef void (*asCLEANMODULEFUNC_t)(asIScriptModule *);
388 typedef void (*asCLEANCONTEXTFUNC_t)(asIScriptContext *);
389 typedef void (*asCLEANFUNCTIONFUNC_t)(asIScriptFunction *);
390 typedef void (*asCLEANTYPEINFOFUNC_t)(asITypeInfo *);
391 typedef void (*asCLEANSCRIPTOBJECTFUNC_t)(asIScriptObject *);
392 typedef asIScriptContext *(*asREQUESTCONTEXTFUNC_t)(asIScriptEngine *, void *);
393 typedef void (*asRETURNCONTEXTFUNC_t)(asIScriptEngine *, asIScriptContext *, void *);
394 typedef void (*asCIRCULARREFFUNC_t)(asITypeInfo *, const void *, void *);
395 
396 #if 0 // diasbled for compatibility
397 // Check if the compiler can use C++11 features
398 #if !defined(_MSC_VER) || _MSC_VER >= 1700 // MSVC 2012
399 #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) // gnuc 4.7 or clang
400 #if !(defined(__GNUC__) && defined(__cplusplus) && __cplusplus < 201103L) // gnuc and clang require compiler flag -std=c++11
401 #if !defined(__SUNPRO_CC) // Oracle Solaris Studio
402 #define AS_CAN_USE_CPP11 1
403 #endif
404 #endif
405 #endif
406 #endif
407 #endif
408 
409 // This macro does basically the same thing as offsetof defined in stddef.h, but
410 // GNUC should not complain about the usage as I'm not using 0 as the base pointer.
411 #define asOFFSET(s,m) ((int)(size_t)(&reinterpret_cast<s*>(100000)->m)-100000)
412 
413 #define asFUNCTION(f) asFunctionPtr(f)
414 #if (defined(_MSC_VER) && _MSC_VER <= 1200) || (defined(__BORLANDC__) && __BORLANDC__ < 0x590)
415 // MSVC 6 has a bug that prevents it from properly compiling using the correct asFUNCTIONPR with operator >
416 // so we need to use ordinary C style cast instead of static_cast. The drawback is that the compiler can't
417 // check that the cast is really valid.
418 // BCC v5.8 (C++Builder 2006) and earlier have a similar bug which forces us to fall back to a C-style cast.
419 #define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())((r (*)p)(f)))
420 #else
421 #define asFUNCTIONPR(f,p,r) asFunctionPtr(reinterpret_cast<void (*)()>(static_cast<r (*)p>(f)))
422 #endif
423 
424 #ifndef AS_NO_CLASS_METHODS
425 
426 class asCUnknownClass;
427 typedef void (asCUnknownClass::*asMETHOD_t)();
428 
429 struct asSFuncPtr {
430  asSFuncPtr(asBYTE f = 0) {
431  for (size_t n = 0; n < sizeof(ptr.dummy); n++)
432  ptr.dummy[n] = 0;
433  flag = f;
434  }
435 
436  void CopyMethodPtr(const void *mthdPtr, size_t size) {
437  for (size_t n = 0; n < size; n++)
438  ptr.dummy[n] = reinterpret_cast<const char *>(mthdPtr)[n];
439  }
440 
441  union {
442  // The largest known method point is 20 bytes (MSVC 64bit),
443  // but with 8byte alignment this becomes 24 bytes. So we need
444  // to be able to store at least that much.
445  char dummy[25];
446  struct {
447  asMETHOD_t mthd;
448  char dummy[25 - sizeof(asMETHOD_t)];
449  } m;
450  struct {
451  asFUNCTION_t func;
452  char dummy[25 - sizeof(asFUNCTION_t)];
453  } f;
454  } ptr;
455  asBYTE flag; // 1 = generic, 2 = global func, 3 = method
456 };
457 
458 #if defined(__BORLANDC__)
459 // A bug in BCC (QC #85374) makes it impossible to distinguish const/non-const method overloads
460 // with static_cast<>. The workaround is to use an _implicit_cast instead.
461 
462 #if __BORLANDC__ < 0x590
463 // BCC v5.8 (C++Builder 2006) and earlier have an even more annoying bug which causes
464 // the "pretty" workaround below (with _implicit_cast<>) to fail. For these compilers
465 // we need to use a traditional C-style cast.
466 #define AS_METHOD_AMBIGUITY_CAST(t) (t)
467 #else
468 template <typename T>
469 T _implicit_cast(T val) {
470  return val;
471 }
472 #define AS_METHOD_AMBIGUITY_CAST(t) AS_NAMESPACE_QUALIFIER _implicit_cast<t >
473 #endif
474 #else
475 #define AS_METHOD_AMBIGUITY_CAST(t) static_cast<t >
476 #endif
477 
478 #define asMETHOD(c,m) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)())(&c::m))
479 #define asMETHODPR(c,m,p,r) asSMethodPtr<sizeof(void (c::*)())>::Convert(AS_METHOD_AMBIGUITY_CAST(r (c::*)p)(&c::m))
480 
481 #else // Class methods are disabled
482 
483 struct asSFuncPtr {
484  asSFuncPtr(asBYTE f) {
485  for (size_t n = 0; n < sizeof(ptr.dummy); n++)
486  ptr.dummy[n] = 0;
487  flag = f;
488  }
489 
490  union {
491  char dummy[25]; // largest known class method pointer
492  struct {
493  asFUNCTION_t func;
494  char dummy[25 - sizeof(asFUNCTION_t)];
495  } f;
496  } ptr;
497  asBYTE flag; // 1 = generic, 2 = global func
498 };
499 
500 #endif
501 
503  const char *section;
504  int row;
505  int col;
506  asEMsgType type;
507  const char *message;
508 };
509 
510 
511 // API functions
512 
513 // ANGELSCRIPT_EXPORT is defined when compiling the dll or lib
514 // ANGELSCRIPT_DLL_LIBRARY_IMPORT is defined when dynamically linking to the
515 // dll through the link lib automatically generated by MSVC++
516 // ANGELSCRIPT_DLL_MANUAL_IMPORT is defined when manually loading the dll
517 // Don't define anything when linking statically to the lib
518 
519 #if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
520 #if defined(ANGELSCRIPT_EXPORT)
521 #define AS_API __declspec(dllexport)
522 #elif defined(ANGELSCRIPT_DLL_LIBRARY_IMPORT)
523 #define AS_API __declspec(dllimport)
524 #else // statically linked library
525 #define AS_API
526 #endif
527 #elif defined(__GNUC__)
528 #if defined(ANGELSCRIPT_EXPORT)
529 #define AS_API __attribute__((visibility ("default")))
530 #else
531 #define AS_API
532 #endif
533 #else
534 #define AS_API
535 #endif
536 
537 #ifndef ANGELSCRIPT_DLL_MANUAL_IMPORT
538 extern "C"
539 {
540  // Engine
541  AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version = ANGELSCRIPT_VERSION);
542  AS_API const char *asGetLibraryVersion();
543  AS_API const char *asGetLibraryOptions();
544 
545  // Context
546  AS_API asIScriptContext *asGetActiveContext();
547 
548  // Thread support
549  AS_API int asPrepareMultithread(asIThreadManager *externalMgr = 0);
550  AS_API void asUnprepareMultithread();
551  AS_API asIThreadManager *asGetThreadManager();
552  AS_API void asAcquireExclusiveLock();
553  AS_API void asReleaseExclusiveLock();
554  AS_API void asAcquireSharedLock();
555  AS_API void asReleaseSharedLock();
556  AS_API int asAtomicInc(int &value);
557  AS_API int asAtomicDec(int &value);
558  AS_API int asThreadCleanup();
559 
560  // Memory management
561  AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);
562  AS_API int asResetGlobalMemoryFunctions();
563  AS_API void *asAllocMem(size_t size);
564  AS_API void asFreeMem(void *mem);
565 
566  // Auxiliary
567  AS_API asILockableSharedBool *asCreateLockableSharedBool();
568 }
569 #endif // ANGELSCRIPT_DLL_MANUAL_IMPORT
570 
571 // Determine traits of a type for registration of value types
572 // Relies on C++11 features so it can not be used with non-compliant compilers
573 #ifdef AS_CAN_USE_CPP11
574 
575 END_AS_NAMESPACE
576 #include <type_traits>
577 BEGIN_AS_NAMESPACE
578 
579 template<typename T>
580 asUINT asGetTypeTraits() {
581 #if defined(_MSC_VER) || defined(_LIBCPP_TYPE_TRAITS) || (__GNUC__ >= 5) || defined(__clang__)
582  // MSVC, XCode/Clang, and gnuc 5+
583  // C++11 compliant code
584  bool hasConstructor = std::is_default_constructible<T>::value && !std::is_trivially_default_constructible<T>::value;
585  bool hasDestructor = std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value;
586  bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::is_trivially_copy_assignable<T>::value;
587  bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::is_trivially_copy_constructible<T>::value;
588 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
589  // gnuc 4.8 is using a mix of C++11 standard and pre-standard templates
590  bool hasConstructor = std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
591  bool hasDestructor = std::is_destructible<T>::value && !std::is_trivially_destructible<T>::value;
592  bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
593  bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
594 #else
595  // All other compilers and versions are assumed to use non C++11 compliant code until proven otherwise
596  // Not fully C++11 compliant. The has_trivial checks were used while the standard was still
597  // being elaborated, but were then removed in favor of the above is_trivially checks
598  // http://stackoverflow.com/questions/12702103/writing-code-that-works-when-has-trivial-destructor-is-defined-instead-of-is
599  // https://github.com/mozart/mozart2/issues/51
600  bool hasConstructor = std::is_default_constructible<T>::value && !std::has_trivial_default_constructor<T>::value;
601  bool hasDestructor = std::is_destructible<T>::value && !std::has_trivial_destructor<T>::value;
602  bool hasAssignmentOperator = std::is_copy_assignable<T>::value && !std::has_trivial_copy_assign<T>::value;
603  bool hasCopyConstructor = std::is_copy_constructible<T>::value && !std::has_trivial_copy_constructor<T>::value;
604 #endif
605  bool isFloat = std::is_floating_point<T>::value;
606  bool isPrimitive = std::is_integral<T>::value || std::is_pointer<T>::value || std::is_enum<T>::value;
607  bool isClass = std::is_class<T>::value;
608  bool isArray = std::is_array<T>::value;
609 
610  if (isFloat)
611  return asOBJ_APP_FLOAT;
612  if (isPrimitive)
613  return asOBJ_APP_PRIMITIVE;
614 
615  if (isClass) {
616  asDWORD flags = asOBJ_APP_CLASS;
617  if (hasConstructor)
618  flags |= asOBJ_APP_CLASS_CONSTRUCTOR;
619  if (hasDestructor)
620  flags |= asOBJ_APP_CLASS_DESTRUCTOR;
621  if (hasAssignmentOperator)
622  flags |= asOBJ_APP_CLASS_ASSIGNMENT;
623  if (hasCopyConstructor)
624  flags |= asOBJ_APP_CLASS_COPY_CONSTRUCTOR;
625  return flags;
626  }
627 
628  if (isArray)
629  return asOBJ_APP_ARRAY;
630 
631  // Unknown type traits
632  return 0;
633 }
634 
635 #endif // c++11
636 
637 // Interface declarations
638 
639 class asIScriptEngine {
640 public:
641  // Memory management
642  virtual int AddRef() const = 0;
643  virtual int Release() const = 0;
644  virtual int ShutDownAndRelease() = 0;
645 
646  // Engine properties
647  virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0;
648  virtual asPWORD GetEngineProperty(asEEngineProp property) const = 0;
649 
650  // Compiler messages
651  virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) = 0;
652  virtual int ClearMessageCallback() = 0;
653  virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message) = 0;
654 
655  // JIT Compiler
656  virtual int SetJITCompiler(asIJITCompiler *compiler) = 0;
657  virtual asIJITCompiler *GetJITCompiler() const = 0;
658 
659  // Global functions
660  virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0) = 0;
661  virtual asUINT GetGlobalFunctionCount() const = 0;
662  virtual asIScriptFunction *GetGlobalFunctionByIndex(asUINT index) const = 0;
663  virtual asIScriptFunction *GetGlobalFunctionByDecl(const char *declaration) const = 0;
664 
665  // Global properties
666  virtual int RegisterGlobalProperty(const char *declaration, void *pointer) = 0;
667  virtual asUINT GetGlobalPropertyCount() const = 0;
668  virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0, asDWORD *accessMask = 0) const = 0;
669  virtual int GetGlobalPropertyIndexByName(const char *name) const = 0;
670  virtual int GetGlobalPropertyIndexByDecl(const char *decl) const = 0;
671 
672  // Object types
673  virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags) = 0;
674  virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset = 0, bool isCompositeIndirect = false) = 0;
675  virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false) = 0;
676  virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false) = 0;
677  virtual int RegisterInterface(const char *name) = 0;
678  virtual int RegisterInterfaceMethod(const char *intf, const char *declaration) = 0;
679  virtual asUINT GetObjectTypeCount() const = 0;
680  virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const = 0;
681 
682  // String factory
683  virtual int RegisterStringFactory(const char *datatype, asIStringFactory *factory) = 0;
684  virtual int GetStringFactoryReturnTypeId(asDWORD *flags = 0) const = 0;
685 
686  // Default array type
687  virtual int RegisterDefaultArrayType(const char *type) = 0;
688  virtual int GetDefaultArrayTypeId() const = 0;
689 
690  // Enums
691  virtual int RegisterEnum(const char *type) = 0;
692  virtual int RegisterEnumValue(const char *type, const char *name, int value) = 0;
693  virtual asUINT GetEnumCount() const = 0;
694  virtual asITypeInfo *GetEnumByIndex(asUINT index) const = 0;
695 
696  // Funcdefs
697  virtual int RegisterFuncdef(const char *decl) = 0;
698  virtual asUINT GetFuncdefCount() const = 0;
699  virtual asITypeInfo *GetFuncdefByIndex(asUINT index) const = 0;
700 
701  // Typedefs
702  virtual int RegisterTypedef(const char *type, const char *decl) = 0;
703  virtual asUINT GetTypedefCount() const = 0;
704  virtual asITypeInfo *GetTypedefByIndex(asUINT index) const = 0;
705 
706  // Configuration groups
707  virtual int BeginConfigGroup(const char *groupName) = 0;
708  virtual int EndConfigGroup() = 0;
709  virtual int RemoveConfigGroup(const char *groupName) = 0;
710  virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask) = 0;
711  virtual int SetDefaultNamespace(const char *nameSpace) = 0;
712  virtual const char *GetDefaultNamespace() const = 0;
713 
714  // Script modules
715  virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0;
716  virtual int DiscardModule(const char *module) = 0;
717  virtual asUINT GetModuleCount() const = 0;
718  virtual asIScriptModule *GetModuleByIndex(asUINT index) const = 0;
719 
720  // Script functions
721  virtual asIScriptFunction *GetFunctionById(int funcId) const = 0;
722 
723  // Type identification
724  virtual int GetTypeIdByDecl(const char *decl) const = 0;
725  virtual const char *GetTypeDeclaration(int typeId, bool includeNamespace = false) const = 0;
726  virtual int GetSizeOfPrimitiveType(int typeId) const = 0;
727  virtual asITypeInfo *GetTypeInfoById(int typeId) const = 0;
728  virtual asITypeInfo *GetTypeInfoByName(const char *name) const = 0;
729  virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const = 0;
730 
731  // Script execution
732  virtual asIScriptContext *CreateContext() = 0;
733  virtual void *CreateScriptObject(const asITypeInfo *type) = 0;
734  virtual void *CreateScriptObjectCopy(void *obj, const asITypeInfo *type) = 0;
735  virtual void *CreateUninitializedScriptObject(const asITypeInfo *type) = 0;
736  virtual asIScriptFunction *CreateDelegate(asIScriptFunction *func, void *obj) = 0;
737  virtual int AssignScriptObject(void *dstObj, void *srcObj, const asITypeInfo *type) = 0;
738  virtual void ReleaseScriptObject(void *obj, const asITypeInfo *type) = 0;
739  virtual void AddRefScriptObject(void *obj, const asITypeInfo *type) = 0;
740  virtual int RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo *toType, void **newPtr, bool useOnlyImplicitCast = false) = 0;
741  virtual asILockableSharedBool *GetWeakRefFlagOfScriptObject(void *obj, const asITypeInfo *type) const = 0;
742 
743  // Context pooling
744  virtual asIScriptContext *RequestContext() = 0;
745  virtual void ReturnContext(asIScriptContext *ctx) = 0;
746  virtual int SetContextCallbacks(asREQUESTCONTEXTFUNC_t requestCtx, asRETURNCONTEXTFUNC_t returnCtx, void *param = 0) = 0;
747 
748  // String interpretation
749  virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, asUINT *tokenLength = 0) const = 0;
750 
751  // Garbage collection
752  virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE, asUINT numIterations = 1) = 0;
753  virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0, asUINT *newObjects = 0, asUINT *totalNewDestroyed = 0) const = 0;
754  virtual int NotifyGarbageCollectorOfNewObject(void *obj, asITypeInfo *type) = 0;
755  virtual int GetObjectInGC(asUINT idx, asUINT *seqNbr = 0, void **obj = 0, asITypeInfo **type = 0) = 0;
756  virtual void GCEnumCallback(void *reference) = 0;
757  virtual void ForwardGCEnumReferences(void *ref, asITypeInfo *type) = 0;
758  virtual void ForwardGCReleaseReferences(void *ref, asITypeInfo *type) = 0;
759  virtual void SetCircularRefDetectedCallback(asCIRCULARREFFUNC_t callback, void *param = 0) = 0;
760 
761  // User data
762  virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
763  virtual void *GetUserData(asPWORD type = 0) const = 0;
764  virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback, asPWORD type = 0) = 0;
765  virtual void SetModuleUserDataCleanupCallback(asCLEANMODULEFUNC_t callback, asPWORD type = 0) = 0;
766  virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback, asPWORD type = 0) = 0;
767  virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback, asPWORD type = 0) = 0;
768  virtual void SetTypeInfoUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type = 0) = 0;
769  virtual void SetScriptObjectUserDataCleanupCallback(asCLEANSCRIPTOBJECTFUNC_t callback, asPWORD type = 0) = 0;
770 
771  // Exception handling
772  virtual int SetTranslateAppExceptionCallback(asSFuncPtr callback, void *param, int callConv) = 0;
773 
774 protected:
775  virtual ~asIScriptEngine() {}
776 };
777 
779 public:
780  virtual const void *GetStringConstant(const char *data, asUINT length) = 0;
781  virtual int ReleaseStringConstant(const void *str) = 0;
782  virtual int GetRawStringData(const void *str, char *data, asUINT *length) const = 0;
783 
784 protected:
785  virtual ~asIStringFactory() {}
786 };
787 
789 protected:
790  virtual ~asIThreadManager() {}
791 };
792 
794 public:
795  virtual asIScriptEngine *GetEngine() const = 0;
796  virtual void SetName(const char *name) = 0;
797  virtual const char *GetName() const = 0;
798  virtual void Discard() = 0;
799 
800  // Compilation
801  virtual int AddScriptSection(const char *name, const char *code, size_t codeLength = 0, int lineOffset = 0) = 0;
802  virtual int Build() = 0;
803  virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) = 0;
804  virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset) = 0;
805  virtual asDWORD SetAccessMask(asDWORD accessMask) = 0;
806  virtual int SetDefaultNamespace(const char *nameSpace) = 0;
807  virtual const char *GetDefaultNamespace() const = 0;
808 
809  // Functions
810  virtual asUINT GetFunctionCount() const = 0;
811  virtual asIScriptFunction *GetFunctionByIndex(asUINT index) const = 0;
812  virtual asIScriptFunction *GetFunctionByDecl(const char *decl) const = 0;
813  virtual asIScriptFunction *GetFunctionByName(const char *name) const = 0;
814  virtual int RemoveFunction(asIScriptFunction *func) = 0;
815 
816  // Global variables
817  virtual int ResetGlobalVars(asIScriptContext *ctx = 0) = 0;
818  virtual asUINT GetGlobalVarCount() const = 0;
819  virtual int GetGlobalVarIndexByName(const char *name) const = 0;
820  virtual int GetGlobalVarIndexByDecl(const char *decl) const = 0;
821  virtual const char *GetGlobalVarDeclaration(asUINT index, bool includeNamespace = false) const = 0;
822  virtual int GetGlobalVar(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0) const = 0;
823  virtual void *GetAddressOfGlobalVar(asUINT index) = 0;
824  virtual int RemoveGlobalVar(asUINT index) = 0;
825 
826  // Type identification
827  virtual asUINT GetObjectTypeCount() const = 0;
828  virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const = 0;
829  virtual int GetTypeIdByDecl(const char *decl) const = 0;
830  virtual asITypeInfo *GetTypeInfoByName(const char *name) const = 0;
831  virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const = 0;
832 
833  // Enums
834  virtual asUINT GetEnumCount() const = 0;
835  virtual asITypeInfo *GetEnumByIndex(asUINT index) const = 0;
836 
837  // Typedefs
838  virtual asUINT GetTypedefCount() const = 0;
839  virtual asITypeInfo *GetTypedefByIndex(asUINT index) const = 0;
840 
841  // Dynamic binding between modules
842  virtual asUINT GetImportedFunctionCount() const = 0;
843  virtual int GetImportedFunctionIndexByDecl(const char *decl) const = 0;
844  virtual const char *GetImportedFunctionDeclaration(asUINT importIndex) const = 0;
845  virtual const char *GetImportedFunctionSourceModule(asUINT importIndex) const = 0;
846  virtual int BindImportedFunction(asUINT importIndex, asIScriptFunction *func) = 0;
847  virtual int UnbindImportedFunction(asUINT importIndex) = 0;
848  virtual int BindAllImportedFunctions() = 0;
849  virtual int UnbindAllImportedFunctions() = 0;
850 
851  // Byte code saving and loading
852  virtual int SaveByteCode(asIBinaryStream *out, bool stripDebugInfo = false) const = 0;
853  virtual int LoadByteCode(asIBinaryStream *in, bool *wasDebugInfoStripped = 0) = 0;
854 
855  // User data
856  virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
857  virtual void *GetUserData(asPWORD type = 0) const = 0;
858 
859 protected:
860  virtual ~asIScriptModule() {}
861 };
862 
863 class asIScriptContext {
864 public:
865  // Memory management
866  virtual int AddRef() const = 0;
867  virtual int Release() const = 0;
868 
869  // Miscellaneous
870  virtual asIScriptEngine *GetEngine() const = 0;
871 
872  // Execution
873  virtual int Prepare(asIScriptFunction *func) = 0;
874  virtual int Unprepare() = 0;
875  virtual int Execute() = 0;
876  virtual int Abort() = 0;
877  virtual int Suspend() = 0;
878  virtual asEContextState GetState() const = 0;
879  virtual int PushState() = 0;
880  virtual int PopState() = 0;
881  virtual bool IsNested(asUINT *nestCount = 0) const = 0;
882 
883  // Object pointer for calling class methods
884  virtual int SetObject(void *obj) = 0;
885 
886  // Arguments
887  virtual int SetArgByte(asUINT arg, asBYTE value) = 0;
888  virtual int SetArgWord(asUINT arg, asWORD value) = 0;
889  virtual int SetArgDWord(asUINT arg, asDWORD value) = 0;
890  virtual int SetArgQWord(asUINT arg, asQWORD value) = 0;
891  virtual int SetArgFloat(asUINT arg, float value) = 0;
892  virtual int SetArgDouble(asUINT arg, double value) = 0;
893  virtual int SetArgAddress(asUINT arg, void *addr) = 0;
894  virtual int SetArgObject(asUINT arg, void *obj) = 0;
895  virtual int SetArgVarType(asUINT arg, void *ptr, int typeId) = 0;
896  virtual void *GetAddressOfArg(asUINT arg) = 0;
897 
898  // Return value
899  virtual asBYTE GetReturnByte() = 0;
900  virtual asWORD GetReturnWord() = 0;
901  virtual asDWORD GetReturnDWord() = 0;
902  virtual asQWORD GetReturnQWord() = 0;
903  virtual float GetReturnFloat() = 0;
904  virtual double GetReturnDouble() = 0;
905  virtual void *GetReturnAddress() = 0;
906  virtual void *GetReturnObject() = 0;
907  virtual void *GetAddressOfReturnValue() = 0;
908 
909  // Exception handling
910  virtual int SetException(const char *info, bool allowCatch = true) = 0;
911  virtual int GetExceptionLineNumber(int *column = 0, const char **sectionName = 0) = 0;
912  virtual asIScriptFunction *GetExceptionFunction() = 0;
913  virtual const char *GetExceptionString() = 0;
914  virtual bool WillExceptionBeCaught() = 0;
915  virtual int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
916  virtual void ClearExceptionCallback() = 0;
917 
918  // Debugging
919  virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
920  virtual void ClearLineCallback() = 0;
921  virtual asUINT GetCallstackSize() const = 0;
922  virtual asIScriptFunction *GetFunction(asUINT stackLevel = 0) = 0;
923  virtual int GetLineNumber(asUINT stackLevel = 0, int *column = 0, const char **sectionName = 0) = 0;
924  virtual int GetVarCount(asUINT stackLevel = 0) = 0;
925  virtual const char *GetVarName(asUINT varIndex, asUINT stackLevel = 0) = 0;
926  virtual const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel = 0, bool includeNamespace = false) = 0;
927  virtual int GetVarTypeId(asUINT varIndex, asUINT stackLevel = 0) = 0;
928  virtual void *GetAddressOfVar(asUINT varIndex, asUINT stackLevel = 0) = 0;
929  virtual bool IsVarInScope(asUINT varIndex, asUINT stackLevel = 0) = 0;
930  virtual int GetThisTypeId(asUINT stackLevel = 0) = 0;
931  virtual void *GetThisPointer(asUINT stackLevel = 0) = 0;
932  virtual asIScriptFunction *GetSystemFunction() = 0;
933 
934  // User data
935  virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
936  virtual void *GetUserData(asPWORD type = 0) const = 0;
937 
938 protected:
939  virtual ~asIScriptContext() {}
940 };
941 
943 public:
944  // Miscellaneous
945  virtual asIScriptEngine *GetEngine() const = 0;
946  virtual asIScriptFunction *GetFunction() const = 0;
947  virtual void *GetAuxiliary() const = 0;
948 
949  // Object
950  virtual void *GetObject() = 0;
951  virtual int GetObjectTypeId() const = 0;
952 
953  // Arguments
954  virtual int GetArgCount() const = 0;
955  virtual int GetArgTypeId(asUINT arg, asDWORD *flags = 0) const = 0;
956  virtual asBYTE GetArgByte(asUINT arg) = 0;
957  virtual asWORD GetArgWord(asUINT arg) = 0;
958  virtual asDWORD GetArgDWord(asUINT arg) = 0;
959  virtual asQWORD GetArgQWord(asUINT arg) = 0;
960  virtual float GetArgFloat(asUINT arg) = 0;
961  virtual double GetArgDouble(asUINT arg) = 0;
962  virtual void *GetArgAddress(asUINT arg) = 0;
963  virtual void *GetArgObject(asUINT arg) = 0;
964  virtual void *GetAddressOfArg(asUINT arg) = 0;
965 
966  // Return value
967  virtual int GetReturnTypeId(asDWORD *flags = 0) const = 0;
968  virtual int SetReturnByte(asBYTE val) = 0;
969  virtual int SetReturnWord(asWORD val) = 0;
970  virtual int SetReturnDWord(asDWORD val) = 0;
971  virtual int SetReturnQWord(asQWORD val) = 0;
972  virtual int SetReturnFloat(float val) = 0;
973  virtual int SetReturnDouble(double val) = 0;
974  virtual int SetReturnAddress(void *addr) = 0;
975  virtual int SetReturnObject(void *obj) = 0;
976  virtual void *GetAddressOfReturnLocation() = 0;
977 
978 protected:
979  virtual ~asIScriptGeneric() {}
980 };
981 
983 public:
984  // Memory management
985  virtual int AddRef() const = 0;
986  virtual int Release() const = 0;
987  virtual asILockableSharedBool *GetWeakRefFlag() const = 0;
988 
989  // Type info
990  virtual int GetTypeId() const = 0;
991  virtual asITypeInfo *GetObjectType() const = 0;
992 
993  // Class properties
994  virtual asUINT GetPropertyCount() const = 0;
995  virtual int GetPropertyTypeId(asUINT prop) const = 0;
996  virtual const char *GetPropertyName(asUINT prop) const = 0;
997  virtual void *GetAddressOfProperty(asUINT prop) = 0;
998 
999  // Miscellaneous
1000  virtual asIScriptEngine *GetEngine() const = 0;
1001  virtual int CopyFrom(const asIScriptObject *other) = 0;
1002 
1003  // User data
1004  virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
1005  virtual void *GetUserData(asPWORD type = 0) const = 0;
1006 
1007 protected:
1008  virtual ~asIScriptObject() {}
1009 };
1010 
1011 class asITypeInfo {
1012 public:
1013  // Miscellaneous
1014  virtual asIScriptEngine *GetEngine() const = 0;
1015  virtual const char *GetConfigGroup() const = 0;
1016  virtual asDWORD GetAccessMask() const = 0;
1017  virtual asIScriptModule *GetModule() const = 0;
1018 
1019  // Memory management
1020  virtual int AddRef() const = 0;
1021  virtual int Release() const = 0;
1022 
1023  // Type info
1024  virtual const char *GetName() const = 0;
1025  virtual const char *GetNamespace() const = 0;
1026  virtual asITypeInfo *GetBaseType() const = 0;
1027  virtual bool DerivesFrom(const asITypeInfo *objType) const = 0;
1028  virtual asDWORD GetFlags() const = 0;
1029  virtual asUINT GetSize() const = 0;
1030  virtual int GetTypeId() const = 0;
1031  virtual int GetSubTypeId(asUINT subTypeIndex = 0) const = 0;
1032  virtual asITypeInfo *GetSubType(asUINT subTypeIndex = 0) const = 0;
1033  virtual asUINT GetSubTypeCount() const = 0;
1034 
1035  // Interfaces
1036  virtual asUINT GetInterfaceCount() const = 0;
1037  virtual asITypeInfo *GetInterface(asUINT index) const = 0;
1038  virtual bool Implements(const asITypeInfo *objType) const = 0;
1039 
1040  // Factories
1041  virtual asUINT GetFactoryCount() const = 0;
1042  virtual asIScriptFunction *GetFactoryByIndex(asUINT index) const = 0;
1043  virtual asIScriptFunction *GetFactoryByDecl(const char *decl) const = 0;
1044 
1045  // Methods
1046  virtual asUINT GetMethodCount() const = 0;
1047  virtual asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual = true) const = 0;
1048  virtual asIScriptFunction *GetMethodByName(const char *name, bool getVirtual = true) const = 0;
1049  virtual asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual = true) const = 0;
1050 
1051  // Properties
1052  virtual asUINT GetPropertyCount() const = 0;
1053  virtual int GetProperty(asUINT index, const char **name, int *typeId = 0, bool *isPrivate = 0, bool *isProtected = 0, int *offset = 0, bool *isReference = 0, asDWORD *accessMask = 0, int *compositeOffset = 0, bool *isCompositeIndirect = 0) const = 0;
1054  virtual const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const = 0;
1055 
1056  // Behaviours
1057  virtual asUINT GetBehaviourCount() const = 0;
1058  virtual asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const = 0;
1059 
1060  // Child types
1061  virtual asUINT GetChildFuncdefCount() const = 0;
1062  virtual asITypeInfo *GetChildFuncdef(asUINT index) const = 0;
1063  virtual asITypeInfo *GetParentType() const = 0;
1064 
1065  // Enums
1066  virtual asUINT GetEnumValueCount() const = 0;
1067  virtual const char *GetEnumValueByIndex(asUINT index, int *outValue) const = 0;
1068 
1069  // Typedef
1070  virtual int GetTypedefTypeId() const = 0;
1071 
1072  // Funcdef
1073  virtual asIScriptFunction *GetFuncdefSignature() const = 0;
1074 
1075  // User data
1076  virtual void *SetUserData(void *data, asPWORD type = 0) = 0;
1077  virtual void *GetUserData(asPWORD type = 0) const = 0;
1078 
1079 protected:
1080  virtual ~asITypeInfo() {}
1081 };
1082 
1084 public:
1085  virtual asIScriptEngine *GetEngine() const = 0;
1086 
1087  // Memory management
1088  virtual int AddRef() const = 0;
1089  virtual int Release() const = 0;
1090 
1091  // Miscellaneous
1092  virtual int GetId() const = 0;
1093  virtual asEFuncType GetFuncType() const = 0;
1094  virtual const char *GetModuleName() const = 0;
1095  virtual asIScriptModule *GetModule() const = 0;
1096  virtual const char *GetScriptSectionName() const = 0;
1097  virtual const char *GetConfigGroup() const = 0;
1098  virtual asDWORD GetAccessMask() const = 0;
1099  virtual void *GetAuxiliary() const = 0;
1100 
1101  // Function signature
1102  virtual asITypeInfo *GetObjectType() const = 0;
1103  virtual const char *GetObjectName() const = 0;
1104  virtual const char *GetName() const = 0;
1105  virtual const char *GetNamespace() const = 0;
1106  virtual const char *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false, bool includeParamNames = false) const = 0;
1107  virtual bool IsReadOnly() const = 0;
1108  virtual bool IsPrivate() const = 0;
1109  virtual bool IsProtected() const = 0;
1110  virtual bool IsFinal() const = 0;
1111  virtual bool IsOverride() const = 0;
1112  virtual bool IsShared() const = 0;
1113  virtual bool IsExplicit() const = 0;
1114  virtual bool IsProperty() const = 0;
1115  virtual asUINT GetParamCount() const = 0;
1116  virtual int GetParam(asUINT index, int *typeId, asDWORD *flags = 0, const char **name = 0, const char **defaultArg = 0) const = 0;
1117  virtual int GetReturnTypeId(asDWORD *flags = 0) const = 0;
1118 
1119  // Type id for function pointers
1120  virtual int GetTypeId() const = 0;
1121  virtual bool IsCompatibleWithTypeId(int typeId) const = 0;
1122 
1123  // Delegates
1124  virtual void *GetDelegateObject() const = 0;
1125  virtual asITypeInfo *GetDelegateObjectType() const = 0;
1126  virtual asIScriptFunction *GetDelegateFunction() const = 0;
1127 
1128  // Debug information
1129  virtual asUINT GetVarCount() const = 0;
1130  virtual int GetVar(asUINT index, const char **name, int *typeId = 0) const = 0;
1131  virtual const char *GetVarDecl(asUINT index, bool includeNamespace = false) const = 0;
1132  virtual int FindNextLineWithCode(int line) const = 0;
1133 
1134  // For JIT compilation
1135  virtual asDWORD *GetByteCode(asUINT *length = 0) = 0;
1136 
1137  // User data
1138  virtual void *SetUserData(void *userData, asPWORD type = 0) = 0;
1139  virtual void *GetUserData(asPWORD type = 0) const = 0;
1140 
1141 protected:
1142  virtual ~asIScriptFunction() {};
1143 };
1144 
1146 public:
1147  virtual int Read(void *ptr, asUINT size) = 0;
1148  virtual int Write(const void *ptr, asUINT size) = 0;
1149 
1150 public:
1151  virtual ~asIBinaryStream() {}
1152 };
1153 
1155 public:
1156  // Memory management
1157  virtual int AddRef() const = 0;
1158  virtual int Release() const = 0;
1159 
1160  // Value
1161  virtual bool Get() const = 0;
1162  virtual void Set(bool val) = 0;
1163 
1164  // Thread management
1165  virtual void Lock() const = 0;
1166  virtual void Unlock() const = 0;
1167 
1168 protected:
1169  virtual ~asILockableSharedBool() {}
1170 };
1171 
1172 //-----------------------------------------------------------------
1173 // Function pointers
1174 
1175 // Template function to capture all global functions,
1176 // except the ones using the generic calling convention
1177 template <class T>
1178 inline asSFuncPtr asFunctionPtr(T func) {
1179  // Mark this as a global function
1180  asSFuncPtr p(2);
1181 
1182 #ifdef AS_64BIT_PTR
1183  // The size_t cast is to avoid a compiler warning with asFUNCTION(0)
1184  // on 64bit, as 0 is interpreted as a 32bit int value
1185  p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(size_t(func));
1186 #else
1187  // MSVC6 doesn't like the size_t cast above so I
1188  // solved this with a separate code for 32bit.
1189  p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);
1190 #endif
1191 
1192  return p;
1193 }
1194 
1195 // Specialization for functions using the generic calling convention
1196 template<>
1197 inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func) {
1198  // Mark this as a generic function
1199  asSFuncPtr p(1);
1200  p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);
1201  return p;
1202 }
1203 
1204 #ifndef AS_NO_CLASS_METHODS
1205 
1206 // Method pointers
1207 
1208 // Declare a dummy class so that we can determine the size of a simple method pointer
1210 typedef void (asCSimpleDummy::*asSIMPLEMETHOD_t)();
1211 const int SINGLE_PTR_SIZE = sizeof(asSIMPLEMETHOD_t);
1212 
1213 // Define template
1214 template <int N>
1216  template<class M>
1217  static asSFuncPtr Convert(M Mthd) {
1218  // This version of the function should never be executed, nor compiled,
1219  // as it would mean that the size of the method pointer cannot be determined.
1220 
1221  int ERROR_UnsupportedMethodPtr[N - 100];
1222 
1223  asSFuncPtr p(0);
1224  return p;
1225  }
1226 };
1227 
1228 // Template specialization
1229 template <>
1230 struct asSMethodPtr<SINGLE_PTR_SIZE> {
1231  template<class M>
1232  static asSFuncPtr Convert(M Mthd) {
1233  // Mark this as a class method
1234  asSFuncPtr p(3);
1235  p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE);
1236  return p;
1237  }
1238 };
1239 
1240 #if defined(_MSC_VER) && !defined(__MWERKS__)
1241 
1242 // MSVC and Intel uses different sizes for different class method pointers
1243 template <>
1244 struct asSMethodPtr < SINGLE_PTR_SIZE + 1 * sizeof(int) > {
1245  template <class M>
1246  static asSFuncPtr Convert(M Mthd) {
1247  // Mark this as a class method
1248  asSFuncPtr p(3);
1249  p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + sizeof(int));
1250  return p;
1251  }
1252 };
1253 
1254 template <>
1255 struct asSMethodPtr < SINGLE_PTR_SIZE + 2 * sizeof(int) > {
1256  template <class M>
1257  static asSFuncPtr Convert(M Mthd) {
1258  // On 32bit platforms with is where a class with virtual inheritance falls.
1259  // On 64bit platforms we can also fall here if 8byte data alignments is used.
1260 
1261  // Mark this as a class method
1262  asSFuncPtr p(3);
1263  p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + 2 * sizeof(int));
1264 
1265  // Microsoft has a terrible optimization on class methods with virtual inheritance.
1266  // They are hardcoding an important offset, which is not coming in the method pointer.
1267 
1268 #if defined(_MSC_VER) && !defined(AS_64BIT_PTR)
1269  // Method pointers for virtual inheritance is not supported,
1270  // as it requires the location of the vbase table, which is
1271  // only available to the C++ compiler, but not in the method
1272  // pointer.
1273 
1274  // You can get around this by forward declaring the class and
1275  // storing the sizeof its method pointer in a constant. Example:
1276 
1277  // class ClassWithVirtualInheritance;
1278  // const int ClassWithVirtualInheritance_workaround = sizeof(void ClassWithVirtualInheritance::*());
1279 
1280  // This will force the compiler to use the unknown type
1281  // for the class, which falls under the next case
1282 
1283 
1284  // Copy the virtual table index to the 4th dword so that AngelScript
1285  // can properly detect and deny the use of methods with virtual inheritance.
1286  *(reinterpret_cast<asDWORD *>(&p) + 3) = *(reinterpret_cast<asDWORD *>(&p) + 2);
1287 #endif
1288 
1289  return p;
1290  }
1291 };
1292 
1293 template <>
1294 struct asSMethodPtr < SINGLE_PTR_SIZE + 3 * sizeof(int) > {
1295  template <class M>
1296  static asSFuncPtr Convert(M Mthd) {
1297  // Mark this as a class method
1298  asSFuncPtr p(3);
1299  p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + 3 * sizeof(int));
1300  return p;
1301  }
1302 };
1303 
1304 template <>
1305 struct asSMethodPtr < SINGLE_PTR_SIZE + 4 * sizeof(int) > {
1306  template <class M>
1307  static asSFuncPtr Convert(M Mthd) {
1308  // On 64bit platforms with 8byte data alignment
1309  // the unknown class method pointers will come here.
1310 
1311  // Mark this as a class method
1312  asSFuncPtr p(3);
1313  p.CopyMethodPtr(&Mthd, SINGLE_PTR_SIZE + 4 * sizeof(int));
1314  return p;
1315  }
1316 };
1317 
1318 #endif
1319 
1320 #endif // AS_NO_CLASS_METHODS
1321 
1322 //----------------------------------------------------------------
1323 // JIT compiler
1324 
1326  asDWORD *programPointer; // points to current bytecode instruction
1327  asDWORD *stackFramePointer; // function stack frame
1328  asDWORD *stackPointer; // top of stack (grows downward)
1329  asQWORD valueRegister; // temp register for primitives
1330  void *objectRegister; // temp register for objects and handles
1331  asITypeInfo *objectType; // type of object held in object register
1332  bool doProcessSuspend; // whether or not the JIT should break out when it encounters a suspend instruction
1333  asIScriptContext *ctx; // the active context
1334 };
1335 
1336 typedef void (*asJITFunction)(asSVMRegisters *registers, asPWORD jitArg);
1337 
1339 public:
1340  virtual int CompileFunction(asIScriptFunction *function, asJITFunction *output) = 0;
1341  virtual void ReleaseJITFunction(asJITFunction func) = 0;
1342 public:
1343  virtual ~asIJITCompiler() {}
1344 };
1345 
1346 // Byte code instructions
1347 enum asEBCInstr {
1348  asBC_PopPtr = 0,
1349  asBC_PshGPtr = 1,
1350  asBC_PshC4 = 2,
1351  asBC_PshV4 = 3,
1352  asBC_PSF = 4,
1353  asBC_SwapPtr = 5,
1354  asBC_NOT = 6,
1355  asBC_PshG4 = 7,
1356  asBC_LdGRdR4 = 8,
1357  asBC_CALL = 9,
1358  asBC_RET = 10,
1359  asBC_JMP = 11,
1360  asBC_JZ = 12,
1361  asBC_JNZ = 13,
1362  asBC_JS = 14,
1363  asBC_JNS = 15,
1364  asBC_JP = 16,
1365  asBC_JNP = 17,
1366  asBC_TZ = 18,
1367  asBC_TNZ = 19,
1368  asBC_TS = 20,
1369  asBC_TNS = 21,
1370  asBC_TP = 22,
1371  asBC_TNP = 23,
1372  asBC_NEGi = 24,
1373  asBC_NEGf = 25,
1374  asBC_NEGd = 26,
1375  asBC_INCi16 = 27,
1376  asBC_INCi8 = 28,
1377  asBC_DECi16 = 29,
1378  asBC_DECi8 = 30,
1379  asBC_INCi = 31,
1380  asBC_DECi = 32,
1381  asBC_INCf = 33,
1382  asBC_DECf = 34,
1383  asBC_INCd = 35,
1384  asBC_DECd = 36,
1385  asBC_IncVi = 37,
1386  asBC_DecVi = 38,
1387  asBC_BNOT = 39,
1388  asBC_BAND = 40,
1389  asBC_BOR = 41,
1390  asBC_BXOR = 42,
1391  asBC_BSLL = 43,
1392  asBC_BSRL = 44,
1393  asBC_BSRA = 45,
1394  asBC_COPY = 46,
1395  asBC_PshC8 = 47,
1396  asBC_PshVPtr = 48,
1397  asBC_RDSPtr = 49,
1398  asBC_CMPd = 50,
1399  asBC_CMPu = 51,
1400  asBC_CMPf = 52,
1401  asBC_CMPi = 53,
1402  asBC_CMPIi = 54,
1403  asBC_CMPIf = 55,
1404  asBC_CMPIu = 56,
1405  asBC_JMPP = 57,
1406  asBC_PopRPtr = 58,
1407  asBC_PshRPtr = 59,
1408  asBC_STR = 60,
1409  asBC_CALLSYS = 61,
1410  asBC_CALLBND = 62,
1411  asBC_SUSPEND = 63,
1412  asBC_ALLOC = 64,
1413  asBC_FREE = 65,
1414  asBC_LOADOBJ = 66,
1415  asBC_STOREOBJ = 67,
1416  asBC_GETOBJ = 68,
1417  asBC_REFCPY = 69,
1418  asBC_CHKREF = 70,
1419  asBC_GETOBJREF = 71,
1420  asBC_GETREF = 72,
1421  asBC_PshNull = 73,
1422  asBC_ClrVPtr = 74,
1423  asBC_OBJTYPE = 75,
1424  asBC_TYPEID = 76,
1425  asBC_SetV4 = 77,
1426  asBC_SetV8 = 78,
1427  asBC_ADDSi = 79,
1428  asBC_CpyVtoV4 = 80,
1429  asBC_CpyVtoV8 = 81,
1430  asBC_CpyVtoR4 = 82,
1431  asBC_CpyVtoR8 = 83,
1432  asBC_CpyVtoG4 = 84,
1433  asBC_CpyRtoV4 = 85,
1434  asBC_CpyRtoV8 = 86,
1435  asBC_CpyGtoV4 = 87,
1436  asBC_WRTV1 = 88,
1437  asBC_WRTV2 = 89,
1438  asBC_WRTV4 = 90,
1439  asBC_WRTV8 = 91,
1440  asBC_RDR1 = 92,
1441  asBC_RDR2 = 93,
1442  asBC_RDR4 = 94,
1443  asBC_RDR8 = 95,
1444  asBC_LDG = 96,
1445  asBC_LDV = 97,
1446  asBC_PGA = 98,
1447  asBC_CmpPtr = 99,
1448  asBC_VAR = 100,
1449  asBC_iTOf = 101,
1450  asBC_fTOi = 102,
1451  asBC_uTOf = 103,
1452  asBC_fTOu = 104,
1453  asBC_sbTOi = 105,
1454  asBC_swTOi = 106,
1455  asBC_ubTOi = 107,
1456  asBC_uwTOi = 108,
1457  asBC_dTOi = 109,
1458  asBC_dTOu = 110,
1459  asBC_dTOf = 111,
1460  asBC_iTOd = 112,
1461  asBC_uTOd = 113,
1462  asBC_fTOd = 114,
1463  asBC_ADDi = 115,
1464  asBC_SUBi = 116,
1465  asBC_MULi = 117,
1466  asBC_DIVi = 118,
1467  asBC_MODi = 119,
1468  asBC_ADDf = 120,
1469  asBC_SUBf = 121,
1470  asBC_MULf = 122,
1471  asBC_DIVf = 123,
1472  asBC_MODf = 124,
1473  asBC_ADDd = 125,
1474  asBC_SUBd = 126,
1475  asBC_MULd = 127,
1476  asBC_DIVd = 128,
1477  asBC_MODd = 129,
1478  asBC_ADDIi = 130,
1479  asBC_SUBIi = 131,
1480  asBC_MULIi = 132,
1481  asBC_ADDIf = 133,
1482  asBC_SUBIf = 134,
1483  asBC_MULIf = 135,
1484  asBC_SetG4 = 136,
1485  asBC_ChkRefS = 137,
1486  asBC_ChkNullV = 138,
1487  asBC_CALLINTF = 139,
1488  asBC_iTOb = 140,
1489  asBC_iTOw = 141,
1490  asBC_SetV1 = 142,
1491  asBC_SetV2 = 143,
1492  asBC_Cast = 144,
1493  asBC_i64TOi = 145,
1494  asBC_uTOi64 = 146,
1495  asBC_iTOi64 = 147,
1496  asBC_fTOi64 = 148,
1497  asBC_dTOi64 = 149,
1498  asBC_fTOu64 = 150,
1499  asBC_dTOu64 = 151,
1500  asBC_i64TOf = 152,
1501  asBC_u64TOf = 153,
1502  asBC_i64TOd = 154,
1503  asBC_u64TOd = 155,
1504  asBC_NEGi64 = 156,
1505  asBC_INCi64 = 157,
1506  asBC_DECi64 = 158,
1507  asBC_BNOT64 = 159,
1508  asBC_ADDi64 = 160,
1509  asBC_SUBi64 = 161,
1510  asBC_MULi64 = 162,
1511  asBC_DIVi64 = 163,
1512  asBC_MODi64 = 164,
1513  asBC_BAND64 = 165,
1514  asBC_BOR64 = 166,
1515  asBC_BXOR64 = 167,
1516  asBC_BSLL64 = 168,
1517  asBC_BSRL64 = 169,
1518  asBC_BSRA64 = 170,
1519  asBC_CMPi64 = 171,
1520  asBC_CMPu64 = 172,
1521  asBC_ChkNullS = 173,
1522  asBC_ClrHi = 174,
1523  asBC_JitEntry = 175,
1524  asBC_CallPtr = 176,
1525  asBC_FuncPtr = 177,
1526  asBC_LoadThisR = 178,
1527  asBC_PshV8 = 179,
1528  asBC_DIVu = 180,
1529  asBC_MODu = 181,
1530  asBC_DIVu64 = 182,
1531  asBC_MODu64 = 183,
1532  asBC_LoadRObjR = 184,
1533  asBC_LoadVObjR = 185,
1534  asBC_RefCpyV = 186,
1535  asBC_JLowZ = 187,
1536  asBC_JLowNZ = 188,
1537  asBC_AllocMem = 189,
1538  asBC_SetListSize = 190,
1539  asBC_PshListElmnt = 191,
1540  asBC_SetListType = 192,
1541  asBC_POWi = 193,
1542  asBC_POWu = 194,
1543  asBC_POWf = 195,
1544  asBC_POWd = 196,
1545  asBC_POWdi = 197,
1546  asBC_POWi64 = 198,
1547  asBC_POWu64 = 199,
1548  asBC_Thiscall1 = 200,
1549  asBC_MAXBYTECODE = 201,
1550 
1551  // Temporary tokens. Can't be output to the final program
1552  asBC_TryBlock = 250,
1553  asBC_VarDecl = 251,
1554  asBC_Block = 252,
1555  asBC_ObjInfo = 253,
1556  asBC_LINE = 254,
1557  asBC_LABEL = 255
1558 };
1559 
1560 // Instruction types
1561 enum asEBCType {
1562  asBCTYPE_INFO = 0,
1563  asBCTYPE_NO_ARG = 1,
1564  asBCTYPE_W_ARG = 2,
1565  asBCTYPE_wW_ARG = 3,
1566  asBCTYPE_DW_ARG = 4,
1567  asBCTYPE_rW_DW_ARG = 5,
1568  asBCTYPE_QW_ARG = 6,
1569  asBCTYPE_DW_DW_ARG = 7,
1570  asBCTYPE_wW_rW_rW_ARG = 8,
1571  asBCTYPE_wW_QW_ARG = 9,
1572  asBCTYPE_wW_rW_ARG = 10,
1573  asBCTYPE_rW_ARG = 11,
1574  asBCTYPE_wW_DW_ARG = 12,
1575  asBCTYPE_wW_rW_DW_ARG = 13,
1576  asBCTYPE_rW_rW_ARG = 14,
1577  asBCTYPE_wW_W_ARG = 15,
1578  asBCTYPE_QW_DW_ARG = 16,
1579  asBCTYPE_rW_QW_ARG = 17,
1580  asBCTYPE_W_DW_ARG = 18,
1581  asBCTYPE_rW_W_DW_ARG = 19,
1582  asBCTYPE_rW_DW_DW_ARG = 20
1583 };
1584 
1585 // Instruction type sizes
1586 const int asBCTypeSize[21] = {
1587  0, // asBCTYPE_INFO
1588  1, // asBCTYPE_NO_ARG
1589  1, // asBCTYPE_W_ARG
1590  1, // asBCTYPE_wW_ARG
1591  2, // asBCTYPE_DW_ARG
1592  2, // asBCTYPE_rW_DW_ARG
1593  3, // asBCTYPE_QW_ARG
1594  3, // asBCTYPE_DW_DW_ARG
1595  2, // asBCTYPE_wW_rW_rW_ARG
1596  3, // asBCTYPE_wW_QW_ARG
1597  2, // asBCTYPE_wW_rW_ARG
1598  1, // asBCTYPE_rW_ARG
1599  2, // asBCTYPE_wW_DW_ARG
1600  3, // asBCTYPE_wW_rW_DW_ARG
1601  2, // asBCTYPE_rW_rW_ARG
1602  2, // asBCTYPE_wW_W_ARG
1603  4, // asBCTYPE_QW_DW_ARG
1604  3, // asBCTYPE_rW_QW_ARG
1605  2, // asBCTYPE_W_DW_ARG
1606  3, // asBCTYPE_rW_W_DW_ARG
1607  3 // asBCTYPE_rW_DW_DW_ARG
1608 };
1609 
1610 // Instruction info
1611 struct asSBCInfo {
1612  asEBCInstr bc;
1613  asEBCType type;
1614  int stackInc;
1615  const char *name;
1616 };
1617 
1618 #ifndef AS_64BIT_PTR
1619 #define asBCTYPE_PTR_ARG asBCTYPE_DW_ARG
1620 #define asBCTYPE_PTR_DW_ARG asBCTYPE_DW_DW_ARG
1621 #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_DW_ARG
1622 #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_DW_ARG
1623 #ifndef AS_PTR_SIZE
1624 #define AS_PTR_SIZE 1
1625 #endif
1626 #else
1627 #define asBCTYPE_PTR_ARG asBCTYPE_QW_ARG
1628 #define asBCTYPE_PTR_DW_ARG asBCTYPE_QW_DW_ARG
1629 #define asBCTYPE_wW_PTR_ARG asBCTYPE_wW_QW_ARG
1630 #define asBCTYPE_rW_PTR_ARG asBCTYPE_rW_QW_ARG
1631 #ifndef AS_PTR_SIZE
1632 #define AS_PTR_SIZE 2
1633 #endif
1634 #endif
1635 
1636 #define asBCINFO(b,t,s) {asBC_##b, asBCTYPE_##t, s, #b}
1637 #define asBCINFO_DUMMY(b) {asBC_MAXBYTECODE, asBCTYPE_INFO, 0, "BC_" #b}
1638 
1639 const asSBCInfo asBCInfo[256] = {
1640  asBCINFO(PopPtr, NO_ARG, -AS_PTR_SIZE),
1641  asBCINFO(PshGPtr, PTR_ARG, AS_PTR_SIZE),
1642  asBCINFO(PshC4, DW_ARG, 1),
1643  asBCINFO(PshV4, rW_ARG, 1),
1644  asBCINFO(PSF, rW_ARG, AS_PTR_SIZE),
1645  asBCINFO(SwapPtr, NO_ARG, 0),
1646  asBCINFO(NOT, rW_ARG, 0),
1647  asBCINFO(PshG4, PTR_ARG, 1),
1648  asBCINFO(LdGRdR4, wW_PTR_ARG, 0),
1649  asBCINFO(CALL, DW_ARG, 0xFFFF),
1650  asBCINFO(RET, W_ARG, 0xFFFF),
1651  asBCINFO(JMP, DW_ARG, 0),
1652  asBCINFO(JZ, DW_ARG, 0),
1653  asBCINFO(JNZ, DW_ARG, 0),
1654  asBCINFO(JS, DW_ARG, 0),
1655  asBCINFO(JNS, DW_ARG, 0),
1656  asBCINFO(JP, DW_ARG, 0),
1657  asBCINFO(JNP, DW_ARG, 0),
1658  asBCINFO(TZ, NO_ARG, 0),
1659  asBCINFO(TNZ, NO_ARG, 0),
1660  asBCINFO(TS, NO_ARG, 0),
1661  asBCINFO(TNS, NO_ARG, 0),
1662  asBCINFO(TP, NO_ARG, 0),
1663  asBCINFO(TNP, NO_ARG, 0),
1664  asBCINFO(NEGi, rW_ARG, 0),
1665  asBCINFO(NEGf, rW_ARG, 0),
1666  asBCINFO(NEGd, rW_ARG, 0),
1667  asBCINFO(INCi16, NO_ARG, 0),
1668  asBCINFO(INCi8, NO_ARG, 0),
1669  asBCINFO(DECi16, NO_ARG, 0),
1670  asBCINFO(DECi8, NO_ARG, 0),
1671  asBCINFO(INCi, NO_ARG, 0),
1672  asBCINFO(DECi, NO_ARG, 0),
1673  asBCINFO(INCf, NO_ARG, 0),
1674  asBCINFO(DECf, NO_ARG, 0),
1675  asBCINFO(INCd, NO_ARG, 0),
1676  asBCINFO(DECd, NO_ARG, 0),
1677  asBCINFO(IncVi, rW_ARG, 0),
1678  asBCINFO(DecVi, rW_ARG, 0),
1679  asBCINFO(BNOT, rW_ARG, 0),
1680  asBCINFO(BAND, wW_rW_rW_ARG, 0),
1681  asBCINFO(BOR, wW_rW_rW_ARG, 0),
1682  asBCINFO(BXOR, wW_rW_rW_ARG, 0),
1683  asBCINFO(BSLL, wW_rW_rW_ARG, 0),
1684  asBCINFO(BSRL, wW_rW_rW_ARG, 0),
1685  asBCINFO(BSRA, wW_rW_rW_ARG, 0),
1686  asBCINFO(COPY, W_DW_ARG, -AS_PTR_SIZE),
1687  asBCINFO(PshC8, QW_ARG, 2),
1688  asBCINFO(PshVPtr, rW_ARG, AS_PTR_SIZE),
1689  asBCINFO(RDSPtr, NO_ARG, 0),
1690  asBCINFO(CMPd, rW_rW_ARG, 0),
1691  asBCINFO(CMPu, rW_rW_ARG, 0),
1692  asBCINFO(CMPf, rW_rW_ARG, 0),
1693  asBCINFO(CMPi, rW_rW_ARG, 0),
1694  asBCINFO(CMPIi, rW_DW_ARG, 0),
1695  asBCINFO(CMPIf, rW_DW_ARG, 0),
1696  asBCINFO(CMPIu, rW_DW_ARG, 0),
1697  asBCINFO(JMPP, rW_ARG, 0),
1698  asBCINFO(PopRPtr, NO_ARG, -AS_PTR_SIZE),
1699  asBCINFO(PshRPtr, NO_ARG, AS_PTR_SIZE),
1700  asBCINFO(STR, W_ARG, 1 + AS_PTR_SIZE),
1701  asBCINFO(CALLSYS, DW_ARG, 0xFFFF),
1702  asBCINFO(CALLBND, DW_ARG, 0xFFFF),
1703  asBCINFO(SUSPEND, NO_ARG, 0),
1704  asBCINFO(ALLOC, PTR_DW_ARG, 0xFFFF),
1705  asBCINFO(FREE, wW_PTR_ARG, 0),
1706  asBCINFO(LOADOBJ, rW_ARG, 0),
1707  asBCINFO(STOREOBJ, wW_ARG, 0),
1708  asBCINFO(GETOBJ, W_ARG, 0),
1709  asBCINFO(REFCPY, PTR_ARG, -AS_PTR_SIZE),
1710  asBCINFO(CHKREF, NO_ARG, 0),
1711  asBCINFO(GETOBJREF, W_ARG, 0),
1712  asBCINFO(GETREF, W_ARG, 0),
1713  asBCINFO(PshNull, NO_ARG, AS_PTR_SIZE),
1714  asBCINFO(ClrVPtr, wW_ARG, 0),
1715  asBCINFO(OBJTYPE, PTR_ARG, AS_PTR_SIZE),
1716  asBCINFO(TYPEID, DW_ARG, 1),
1717  asBCINFO(SetV4, wW_DW_ARG, 0),
1718  asBCINFO(SetV8, wW_QW_ARG, 0),
1719  asBCINFO(ADDSi, W_DW_ARG, 0),
1720  asBCINFO(CpyVtoV4, wW_rW_ARG, 0),
1721  asBCINFO(CpyVtoV8, wW_rW_ARG, 0),
1722  asBCINFO(CpyVtoR4, rW_ARG, 0),
1723  asBCINFO(CpyVtoR8, rW_ARG, 0),
1724  asBCINFO(CpyVtoG4, rW_PTR_ARG, 0),
1725  asBCINFO(CpyRtoV4, wW_ARG, 0),
1726  asBCINFO(CpyRtoV8, wW_ARG, 0),
1727  asBCINFO(CpyGtoV4, wW_PTR_ARG, 0),
1728  asBCINFO(WRTV1, rW_ARG, 0),
1729  asBCINFO(WRTV2, rW_ARG, 0),
1730  asBCINFO(WRTV4, rW_ARG, 0),
1731  asBCINFO(WRTV8, rW_ARG, 0),
1732  asBCINFO(RDR1, wW_ARG, 0),
1733  asBCINFO(RDR2, wW_ARG, 0),
1734  asBCINFO(RDR4, wW_ARG, 0),
1735  asBCINFO(RDR8, wW_ARG, 0),
1736  asBCINFO(LDG, PTR_ARG, 0),
1737  asBCINFO(LDV, rW_ARG, 0),
1738  asBCINFO(PGA, PTR_ARG, AS_PTR_SIZE),
1739  asBCINFO(CmpPtr, rW_rW_ARG, 0),
1740  asBCINFO(VAR, rW_ARG, AS_PTR_SIZE),
1741  asBCINFO(iTOf, rW_ARG, 0),
1742  asBCINFO(fTOi, rW_ARG, 0),
1743  asBCINFO(uTOf, rW_ARG, 0),
1744  asBCINFO(fTOu, rW_ARG, 0),
1745  asBCINFO(sbTOi, rW_ARG, 0),
1746  asBCINFO(swTOi, rW_ARG, 0),
1747  asBCINFO(ubTOi, rW_ARG, 0),
1748  asBCINFO(uwTOi, rW_ARG, 0),
1749  asBCINFO(dTOi, wW_rW_ARG, 0),
1750  asBCINFO(dTOu, wW_rW_ARG, 0),
1751  asBCINFO(dTOf, wW_rW_ARG, 0),
1752  asBCINFO(iTOd, wW_rW_ARG, 0),
1753  asBCINFO(uTOd, wW_rW_ARG, 0),
1754  asBCINFO(fTOd, wW_rW_ARG, 0),
1755  asBCINFO(ADDi, wW_rW_rW_ARG, 0),
1756  asBCINFO(SUBi, wW_rW_rW_ARG, 0),
1757  asBCINFO(MULi, wW_rW_rW_ARG, 0),
1758  asBCINFO(DIVi, wW_rW_rW_ARG, 0),
1759  asBCINFO(MODi, wW_rW_rW_ARG, 0),
1760  asBCINFO(ADDf, wW_rW_rW_ARG, 0),
1761  asBCINFO(SUBf, wW_rW_rW_ARG, 0),
1762  asBCINFO(MULf, wW_rW_rW_ARG, 0),
1763  asBCINFO(DIVf, wW_rW_rW_ARG, 0),
1764  asBCINFO(MODf, wW_rW_rW_ARG, 0),
1765  asBCINFO(ADDd, wW_rW_rW_ARG, 0),
1766  asBCINFO(SUBd, wW_rW_rW_ARG, 0),
1767  asBCINFO(MULd, wW_rW_rW_ARG, 0),
1768  asBCINFO(DIVd, wW_rW_rW_ARG, 0),
1769  asBCINFO(MODd, wW_rW_rW_ARG, 0),
1770  asBCINFO(ADDIi, wW_rW_DW_ARG, 0),
1771  asBCINFO(SUBIi, wW_rW_DW_ARG, 0),
1772  asBCINFO(MULIi, wW_rW_DW_ARG, 0),
1773  asBCINFO(ADDIf, wW_rW_DW_ARG, 0),
1774  asBCINFO(SUBIf, wW_rW_DW_ARG, 0),
1775  asBCINFO(MULIf, wW_rW_DW_ARG, 0),
1776  asBCINFO(SetG4, PTR_DW_ARG, 0),
1777  asBCINFO(ChkRefS, NO_ARG, 0),
1778  asBCINFO(ChkNullV, rW_ARG, 0),
1779  asBCINFO(CALLINTF, DW_ARG, 0xFFFF),
1780  asBCINFO(iTOb, rW_ARG, 0),
1781  asBCINFO(iTOw, rW_ARG, 0),
1782  asBCINFO(SetV1, wW_DW_ARG, 0),
1783  asBCINFO(SetV2, wW_DW_ARG, 0),
1784  asBCINFO(Cast, DW_ARG, -AS_PTR_SIZE),
1785  asBCINFO(i64TOi, wW_rW_ARG, 0),
1786  asBCINFO(uTOi64, wW_rW_ARG, 0),
1787  asBCINFO(iTOi64, wW_rW_ARG, 0),
1788  asBCINFO(fTOi64, wW_rW_ARG, 0),
1789  asBCINFO(dTOi64, rW_ARG, 0),
1790  asBCINFO(fTOu64, wW_rW_ARG, 0),
1791  asBCINFO(dTOu64, rW_ARG, 0),
1792  asBCINFO(i64TOf, wW_rW_ARG, 0),
1793  asBCINFO(u64TOf, wW_rW_ARG, 0),
1794  asBCINFO(i64TOd, rW_ARG, 0),
1795  asBCINFO(u64TOd, rW_ARG, 0),
1796  asBCINFO(NEGi64, rW_ARG, 0),
1797  asBCINFO(INCi64, NO_ARG, 0),
1798  asBCINFO(DECi64, NO_ARG, 0),
1799  asBCINFO(BNOT64, rW_ARG, 0),
1800  asBCINFO(ADDi64, wW_rW_rW_ARG, 0),
1801  asBCINFO(SUBi64, wW_rW_rW_ARG, 0),
1802  asBCINFO(MULi64, wW_rW_rW_ARG, 0),
1803  asBCINFO(DIVi64, wW_rW_rW_ARG, 0),
1804  asBCINFO(MODi64, wW_rW_rW_ARG, 0),
1805  asBCINFO(BAND64, wW_rW_rW_ARG, 0),
1806  asBCINFO(BOR64, wW_rW_rW_ARG, 0),
1807  asBCINFO(BXOR64, wW_rW_rW_ARG, 0),
1808  asBCINFO(BSLL64, wW_rW_rW_ARG, 0),
1809  asBCINFO(BSRL64, wW_rW_rW_ARG, 0),
1810  asBCINFO(BSRA64, wW_rW_rW_ARG, 0),
1811  asBCINFO(CMPi64, rW_rW_ARG, 0),
1812  asBCINFO(CMPu64, rW_rW_ARG, 0),
1813  asBCINFO(ChkNullS, W_ARG, 0),
1814  asBCINFO(ClrHi, NO_ARG, 0),
1815  asBCINFO(JitEntry, PTR_ARG, 0),
1816  asBCINFO(CallPtr, rW_ARG, 0xFFFF),
1817  asBCINFO(FuncPtr, PTR_ARG, AS_PTR_SIZE),
1818  asBCINFO(LoadThisR, W_DW_ARG, 0),
1819  asBCINFO(PshV8, rW_ARG, 2),
1820  asBCINFO(DIVu, wW_rW_rW_ARG, 0),
1821  asBCINFO(MODu, wW_rW_rW_ARG, 0),
1822  asBCINFO(DIVu64, wW_rW_rW_ARG, 0),
1823  asBCINFO(MODu64, wW_rW_rW_ARG, 0),
1824  asBCINFO(LoadRObjR, rW_W_DW_ARG, 0),
1825  asBCINFO(LoadVObjR, rW_W_DW_ARG, 0),
1826  asBCINFO(RefCpyV, wW_PTR_ARG, 0),
1827  asBCINFO(JLowZ, DW_ARG, 0),
1828  asBCINFO(JLowNZ, DW_ARG, 0),
1829  asBCINFO(AllocMem, wW_DW_ARG, 0),
1830  asBCINFO(SetListSize, rW_DW_DW_ARG, 0),
1831  asBCINFO(PshListElmnt, rW_DW_ARG, AS_PTR_SIZE),
1832  asBCINFO(SetListType, rW_DW_DW_ARG, 0),
1833  asBCINFO(POWi, wW_rW_rW_ARG, 0),
1834  asBCINFO(POWu, wW_rW_rW_ARG, 0),
1835  asBCINFO(POWf, wW_rW_rW_ARG, 0),
1836  asBCINFO(POWd, wW_rW_rW_ARG, 0),
1837  asBCINFO(POWdi, wW_rW_rW_ARG, 0),
1838  asBCINFO(POWi64, wW_rW_rW_ARG, 0),
1839  asBCINFO(POWu64, wW_rW_rW_ARG, 0),
1840  asBCINFO(Thiscall1, DW_ARG, -AS_PTR_SIZE - 1),
1841 
1842  asBCINFO_DUMMY(201),
1843  asBCINFO_DUMMY(202),
1844  asBCINFO_DUMMY(203),
1845  asBCINFO_DUMMY(204),
1846  asBCINFO_DUMMY(205),
1847  asBCINFO_DUMMY(206),
1848  asBCINFO_DUMMY(207),
1849  asBCINFO_DUMMY(208),
1850  asBCINFO_DUMMY(209),
1851  asBCINFO_DUMMY(210),
1852  asBCINFO_DUMMY(211),
1853  asBCINFO_DUMMY(212),
1854  asBCINFO_DUMMY(213),
1855  asBCINFO_DUMMY(214),
1856  asBCINFO_DUMMY(215),
1857  asBCINFO_DUMMY(216),
1858  asBCINFO_DUMMY(217),
1859  asBCINFO_DUMMY(218),
1860  asBCINFO_DUMMY(219),
1861  asBCINFO_DUMMY(220),
1862  asBCINFO_DUMMY(221),
1863  asBCINFO_DUMMY(222),
1864  asBCINFO_DUMMY(223),
1865  asBCINFO_DUMMY(224),
1866  asBCINFO_DUMMY(225),
1867  asBCINFO_DUMMY(226),
1868  asBCINFO_DUMMY(227),
1869  asBCINFO_DUMMY(228),
1870  asBCINFO_DUMMY(229),
1871  asBCINFO_DUMMY(230),
1872  asBCINFO_DUMMY(231),
1873  asBCINFO_DUMMY(232),
1874  asBCINFO_DUMMY(233),
1875  asBCINFO_DUMMY(234),
1876  asBCINFO_DUMMY(235),
1877  asBCINFO_DUMMY(236),
1878  asBCINFO_DUMMY(237),
1879  asBCINFO_DUMMY(238),
1880  asBCINFO_DUMMY(239),
1881  asBCINFO_DUMMY(240),
1882  asBCINFO_DUMMY(241),
1883  asBCINFO_DUMMY(242),
1884  asBCINFO_DUMMY(243),
1885  asBCINFO_DUMMY(244),
1886  asBCINFO_DUMMY(245),
1887  asBCINFO_DUMMY(246),
1888  asBCINFO_DUMMY(247),
1889  asBCINFO_DUMMY(248),
1890  asBCINFO_DUMMY(249),
1891 
1892  asBCINFO(TryBlock, DW_ARG, 0),
1893  asBCINFO(VarDecl, W_ARG, 0),
1894  asBCINFO(Block, INFO, 0),
1895  asBCINFO(ObjInfo, rW_DW_ARG, 0),
1896  asBCINFO(LINE, INFO, 0),
1897  asBCINFO(LABEL, INFO, 0)
1898 };
1899 
1900 // Macros to access bytecode instruction arguments
1901 #define asBC_DWORDARG(x) (*(((asDWORD*)x)+1))
1902 #define asBC_INTARG(x) (*(int*)(((asDWORD*)x)+1))
1903 #define asBC_QWORDARG(x) (*(asQWORD*)(((asDWORD*)x)+1))
1904 #define asBC_FLOATARG(x) (*(float*)(((asDWORD*)x)+1))
1905 #define asBC_PTRARG(x) (*(asPWORD*)(((asDWORD*)x)+1))
1906 #define asBC_WORDARG0(x) (*(((asWORD*)x)+1))
1907 #define asBC_WORDARG1(x) (*(((asWORD*)x)+2))
1908 #define asBC_SWORDARG0(x) (*(((short*)x)+1))
1909 #define asBC_SWORDARG1(x) (*(((short*)x)+2))
1910 #define asBC_SWORDARG2(x) (*(((short*)x)+3))
1911 
1912 
1913 END_AS_NAMESPACE
1914 
1915 #endif
Definition: angelscript.h:1325
Definition: angelscript.h:1083
Definition: angelscript.h:1611
Definition: angelscript.h:793
Definition: angelscript.h:942
Definition: angelscript.h:1215
Definition: angelscript.h:1154
Definition: angelscript.h:1209
Definition: angelscript.h:863
Definition: angelscript.h:788
Definition: angelscript.h:778
Definition: angelscript.h:1338
Definition: angelscript.h:1145
Definition: angelscript.h:982
Definition: angelscript.h:429
Definition: angelscript.h:502
Definition: angelscript.h:639
Definition: angelscript.h:1011