PageRenderTime 107ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/xbmc/visualizations/Vortex/angelscript/docs/doxygen/source/angelscript.h

http://github.com/xbmc/xbmc
C++ Header | 3862 lines | 1244 code | 265 blank | 2353 comment | 5 complexity | 41f23e90b623c1f5a6974d5bb9d8929e MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-3.0, LGPL-2.0, 0BSD, Unlicense, GPL-2.0, AGPL-1.0, BSD-3-Clause, LGPL-2.1, LGPL-3.0
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2009 Andreas Jonsson
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any
  6. damages arising from the use of this software.
  7. Permission is granted to anyone to use this software for any
  8. purpose, including commercial applications, and to alter it and
  9. redistribute it freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you
  11. must not claim that you wrote the original software. If you use
  12. this software in a product, an acknowledgment in the product
  13. documentation would be appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and
  15. must not be misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. The original version of this library can be located at:
  19. http://www.angelcode.com/angelscript/
  20. Andreas Jonsson
  21. andreas@angelcode.com
  22. */
  23. //
  24. // angelscript.h
  25. //
  26. // The script engine interface
  27. //
  28. //! \file angelscript.h
  29. //! \brief The API definition for AngelScript.
  30. //!
  31. //! This header file describes the complete application programming interface for AngelScript.
  32. #ifndef ANGELSCRIPT_H
  33. #define ANGELSCRIPT_H
  34. #include <stddef.h>
  35. #ifdef AS_USE_NAMESPACE
  36. #define BEGIN_AS_NAMESPACE namespace AngelScript {
  37. #define END_AS_NAMESPACE }
  38. #else
  39. #define BEGIN_AS_NAMESPACE
  40. #define END_AS_NAMESPACE
  41. #endif
  42. BEGIN_AS_NAMESPACE
  43. // AngelScript version
  44. //! \details Version 2.18.0
  45. #define ANGELSCRIPT_VERSION 21800
  46. #define ANGELSCRIPT_VERSION_STRING "2.18.0"
  47. // Data types
  48. class asIScriptEngine;
  49. class asIScriptModule;
  50. class asIScriptContext;
  51. class asIScriptGeneric;
  52. class asIScriptObject;
  53. class asIScriptArray;
  54. class asIObjectType;
  55. class asIScriptFunction;
  56. class asIBinaryStream;
  57. class asIJITCompiler;
  58. // Enumerations and constants
  59. // Engine properties
  60. //! Engine properties
  61. enum asEEngineProp
  62. {
  63. //! Allow unsafe references. Default: false.
  64. asEP_ALLOW_UNSAFE_REFERENCES = 1,
  65. //! Optimize byte code. Default: true.
  66. asEP_OPTIMIZE_BYTECODE = 2,
  67. //! Copy script section memory. Default: true.
  68. asEP_COPY_SCRIPT_SECTIONS = 3,
  69. //! Maximum stack size for script contexts. Default: 0 (no limit).
  70. asEP_MAX_STACK_SIZE = 4,
  71. //! Interpret single quoted strings as character literals. Default: false.
  72. asEP_USE_CHARACTER_LITERALS = 5,
  73. //! Allow linebreaks in string constants. Default: false.
  74. asEP_ALLOW_MULTILINE_STRINGS = 6,
  75. //! Allow script to declare implicit handle types. Default: false.
  76. asEP_ALLOW_IMPLICIT_HANDLE_TYPES = 7,
  77. //! Remove SUSPEND instructions between each statement. Default: false.
  78. asEP_BUILD_WITHOUT_LINE_CUES = 8,
  79. //! Initialize global variables after a build. Default: true.
  80. asEP_INIT_GLOBAL_VARS_AFTER_BUILD = 9,
  81. //! When set the enum values must be prefixed with the enum type. Default: false.
  82. asEP_REQUIRE_ENUM_SCOPE = 10,
  83. //! Select scanning method: 0 - ASCII, 1 - UTF8. Default: 1 (UTF8).
  84. asEP_SCRIPT_SCANNER = 11,
  85. //! When set extra bytecode instructions needed for JIT compiled funcions will be included. Default: false.
  86. asEP_INCLUDE_JIT_INSTRUCTIONS = 12,
  87. //! Select string encoding for literals: 0 - UTF8/ASCII, 1 - UTF16. Default: 0 (UTF8)
  88. asEP_STRING_ENCODING = 13
  89. };
  90. // Calling conventions
  91. //! Calling conventions
  92. enum asECallConvTypes
  93. {
  94. //! A cdecl function.
  95. asCALL_CDECL = 0,
  96. //! A stdcall function.
  97. asCALL_STDCALL = 1,
  98. //! A thiscall class method.
  99. asCALL_THISCALL = 2,
  100. //! A cdecl function that takes the object pointer as the last parameter.
  101. asCALL_CDECL_OBJLAST = 3,
  102. //! A cdecl function that takes the object pointer as the first parameter.
  103. asCALL_CDECL_OBJFIRST = 4,
  104. //! A function using the generic calling convention.
  105. asCALL_GENERIC = 5
  106. };
  107. // Object type flags
  108. //! Object type flags
  109. enum asEObjTypeFlags
  110. {
  111. //! A reference type.
  112. asOBJ_REF = 0x01,
  113. //! A value type.
  114. asOBJ_VALUE = 0x02,
  115. //! A garbage collected type. Only valid for reference types.
  116. asOBJ_GC = 0x04,
  117. //! A plain-old-data type. Only valid for value types.
  118. asOBJ_POD = 0x08,
  119. //! This reference type doesn't allow handles to be held. Only valid for reference types.
  120. asOBJ_NOHANDLE = 0x10,
  121. //! The life time of objects of this type are controlled by the scope of the variable. Only valid for reference types.
  122. asOBJ_SCOPED = 0x20,
  123. //! A template type.
  124. asOBJ_TEMPLATE = 0x40,
  125. //! The C++ type is a class type. Only valid for value types.
  126. asOBJ_APP_CLASS = 0x100,
  127. //! The C++ class has an explicit constructor. Only valid for value types.
  128. asOBJ_APP_CLASS_CONSTRUCTOR = 0x200,
  129. //! The C++ class has an explicit destructor. Only valid for value types.
  130. asOBJ_APP_CLASS_DESTRUCTOR = 0x400,
  131. //! The C++ class has an explicit assignment operator. Only valid for value types.
  132. asOBJ_APP_CLASS_ASSIGNMENT = 0x800,
  133. //! The C++ type is a class with a constructor, but no destructor or assignment operator.
  134. asOBJ_APP_CLASS_C = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR),
  135. //! The C++ type is a class with a constructor and destructor, but no assignment operator.
  136. asOBJ_APP_CLASS_CD = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR),
  137. //! The C++ type is a class with a constructor and assignment operator, but no destructor.
  138. asOBJ_APP_CLASS_CA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  139. //! The C++ type is a class with a constructor, destructor, and assignment operator.
  140. asOBJ_APP_CLASS_CDA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_CONSTRUCTOR + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  141. //! The C++ type is a class with a destructor, but no constructor or assignment operator.
  142. asOBJ_APP_CLASS_D = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR),
  143. //! The C++ type is a class with an assignment operator, but no constructor or destructor.
  144. asOBJ_APP_CLASS_A = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_ASSIGNMENT),
  145. //! The C++ type is a class with a destructor and assignment operator, but no constructor.
  146. asOBJ_APP_CLASS_DA = (asOBJ_APP_CLASS + asOBJ_APP_CLASS_DESTRUCTOR + asOBJ_APP_CLASS_ASSIGNMENT),
  147. //! The C++ type is a primitive type. Only valid for value types.
  148. asOBJ_APP_PRIMITIVE = 0x1000,
  149. //! The C++ type is a float or double. Only valid for value types.
  150. asOBJ_APP_FLOAT = 0x2000,
  151. asOBJ_MASK_VALID_FLAGS = 0x3F7F,
  152. //! The object is a script class or an interface.
  153. asOBJ_SCRIPT_OBJECT = 0x10000
  154. };
  155. // Behaviours
  156. //! Behaviours
  157. enum asEBehaviours
  158. {
  159. // Value object memory management
  160. //! \brief Constructor
  161. asBEHAVE_CONSTRUCT,
  162. //! \brief Destructor
  163. asBEHAVE_DESTRUCT,
  164. // Reference object memory management
  165. //! \brief Factory
  166. asBEHAVE_FACTORY,
  167. //! \brief AddRef
  168. asBEHAVE_ADDREF,
  169. //! \brief Release
  170. asBEHAVE_RELEASE,
  171. // Object operators
  172. //! \brief Explicit value cast operator
  173. asBEHAVE_VALUE_CAST,
  174. //! \brief Implicit value cast operator
  175. asBEHAVE_IMPLICIT_VALUE_CAST,
  176. //! \brief Explicit reference cast operator
  177. asBEHAVE_REF_CAST,
  178. //! \brief Implicit reference cast operator
  179. asBEHAVE_IMPLICIT_REF_CAST,
  180. //! \brief operator []
  181. asBEHAVE_INDEX,
  182. //! \brief Callback for validating template instances
  183. asBEHAVE_TEMPLATE_CALLBACK,
  184. // Garbage collection behaviours
  185. asBEHAVE_FIRST_GC,
  186. //! \brief (GC) Get reference count
  187. asBEHAVE_GETREFCOUNT = asBEHAVE_FIRST_GC,
  188. //! \brief (GC) Set GC flag
  189. asBEHAVE_SETGCFLAG,
  190. //! \brief (GC) Get GC flag
  191. asBEHAVE_GETGCFLAG,
  192. //! \brief (GC) Enumerate held references
  193. asBEHAVE_ENUMREFS,
  194. //! \brief (GC) Release all references
  195. asBEHAVE_RELEASEREFS,
  196. asBEHAVE_LAST_GC = asBEHAVE_RELEASEREFS,
  197. asBEHAVE_MAX
  198. };
  199. // Return codes
  200. //! Return codes
  201. enum asERetCodes
  202. {
  203. //! Success
  204. asSUCCESS = 0,
  205. //! Failure
  206. asERROR = -1,
  207. //! The context is active
  208. asCONTEXT_ACTIVE = -2,
  209. //! The context is not finished
  210. asCONTEXT_NOT_FINISHED = -3,
  211. //! The context is not prepared
  212. asCONTEXT_NOT_PREPARED = -4,
  213. //! Invalid argument
  214. asINVALID_ARG = -5,
  215. //! The function was not found
  216. asNO_FUNCTION = -6,
  217. //! Not supported
  218. asNOT_SUPPORTED = -7,
  219. //! Invalid name
  220. asINVALID_NAME = -8,
  221. //! The name is already taken
  222. asNAME_TAKEN = -9,
  223. //! Invalid declaration
  224. asINVALID_DECLARATION = -10,
  225. //! Invalid object
  226. asINVALID_OBJECT = -11,
  227. //! Invalid type
  228. asINVALID_TYPE = -12,
  229. //! Already registered
  230. asALREADY_REGISTERED = -13,
  231. //! Multiple matching functions
  232. asMULTIPLE_FUNCTIONS = -14,
  233. //! The module was not found
  234. asNO_MODULE = -15,
  235. //! The global variable was not found
  236. asNO_GLOBAL_VAR = -16,
  237. //! Invalid configuration
  238. asINVALID_CONFIGURATION = -17,
  239. //! Invalid interface
  240. asINVALID_INTERFACE = -18,
  241. //! All imported functions couldn't be bound
  242. asCANT_BIND_ALL_FUNCTIONS = -19,
  243. //! The array sub type has not been registered yet
  244. asLOWER_ARRAY_DIMENSION_NOT_REGISTERED = -20,
  245. //! Wrong configuration group
  246. asWRONG_CONFIG_GROUP = -21,
  247. //! The configuration group is in use
  248. asCONFIG_GROUP_IS_IN_USE = -22,
  249. //! Illegal behaviour for the type
  250. asILLEGAL_BEHAVIOUR_FOR_TYPE = -23,
  251. //! The specified calling convention doesn't match the function/method pointer
  252. asWRONG_CALLING_CONV = -24,
  253. //! A build is currently in progress
  254. asBUILD_IN_PROGRESS = -25,
  255. //! The initialization of global variables failed
  256. asINIT_GLOBAL_VARS_FAILED = -26
  257. };
  258. // Context states
  259. //! \brief Context states.
  260. enum asEContextState
  261. {
  262. //! The context has successfully completed the execution.
  263. asEXECUTION_FINISHED = 0,
  264. //! The execution is suspended and can be resumed.
  265. asEXECUTION_SUSPENDED = 1,
  266. //! The execution was aborted by the application.
  267. asEXECUTION_ABORTED = 2,
  268. //! The execution was terminated by an unhandled script exception.
  269. asEXECUTION_EXCEPTION = 3,
  270. //! The context has been prepared for a new execution.
  271. asEXECUTION_PREPARED = 4,
  272. //! The context is not initialized.
  273. asEXECUTION_UNINITIALIZED = 5,
  274. //! The context is currently executing a function call.
  275. asEXECUTION_ACTIVE = 6,
  276. //! The context has encountered an error and must be reinitialized.
  277. asEXECUTION_ERROR = 7
  278. };
  279. #ifdef AS_DEPRECATED
  280. // Deprecated since 2.18.0, 2009-12-08
  281. // ExecuteString flags
  282. //! \brief ExecuteString flags.
  283. //! \deprecated since 2.18.0
  284. enum asEExecStrFlags
  285. {
  286. //! Only prepare the context
  287. asEXECSTRING_ONLY_PREPARE = 1,
  288. //! Use the pre-allocated context
  289. asEXECSTRING_USE_MY_CONTEXT = 2
  290. };
  291. #endif
  292. // Message types
  293. //! \brief Compiler message types.
  294. enum asEMsgType
  295. {
  296. //! The message is an error.
  297. asMSGTYPE_ERROR = 0,
  298. //! The message is a warning.
  299. asMSGTYPE_WARNING = 1,
  300. //! The message is informational only.
  301. asMSGTYPE_INFORMATION = 2
  302. };
  303. // Garbage collector flags
  304. //! \brief Garbage collector flags.
  305. enum asEGCFlags
  306. {
  307. //! Execute a full cycle.
  308. asGC_FULL_CYCLE = 1,
  309. //! Execute only one step
  310. asGC_ONE_STEP = 2,
  311. //! Destroy known garbage
  312. asGC_DESTROY_GARBAGE = 4,
  313. //! Detect garbage with circular references
  314. asGC_DETECT_GARBAGE = 8
  315. };
  316. // Token classes
  317. //! \brief Token classes.
  318. enum asETokenClass
  319. {
  320. //! Unknown token.
  321. asTC_UNKNOWN = 0,
  322. //! Keyword token.
  323. asTC_KEYWORD = 1,
  324. //! Literal value token.
  325. asTC_VALUE = 2,
  326. //! Identifier token.
  327. asTC_IDENTIFIER = 3,
  328. //! Comment token.
  329. asTC_COMMENT = 4,
  330. //! White space token.
  331. asTC_WHITESPACE = 5
  332. };
  333. // Prepare flags
  334. const int asPREPARE_PREVIOUS = -1;
  335. // Config groups
  336. const char * const asALL_MODULES = (const char * const)-1;
  337. // Type id flags
  338. //! \brief Type id flags
  339. enum asETypeIdFlags
  340. {
  341. //! The type id for void
  342. asTYPEID_VOID = 0,
  343. //! The type id for bool
  344. asTYPEID_BOOL = 1,
  345. //! The type id for int8
  346. asTYPEID_INT8 = 2,
  347. //! The type id for int16
  348. asTYPEID_INT16 = 3,
  349. //! The type id for int
  350. asTYPEID_INT32 = 4,
  351. //! The type id for int64
  352. asTYPEID_INT64 = 5,
  353. //! The type id for uint8
  354. asTYPEID_UINT8 = 6,
  355. //! The type id for uint16
  356. asTYPEID_UINT16 = 7,
  357. //! The type id for uint
  358. asTYPEID_UINT32 = 8,
  359. //! The type id for uint64
  360. asTYPEID_UINT64 = 9,
  361. //! The type id for float
  362. asTYPEID_FLOAT = 10,
  363. //! The type id for double
  364. asTYPEID_DOUBLE = 11,
  365. //! The bit that shows if the type is a handle
  366. asTYPEID_OBJHANDLE = 0x40000000,
  367. //! The bit that shows if the type is a handle to a const
  368. asTYPEID_HANDLETOCONST = 0x20000000,
  369. //! If any of these bits are set, then the type is an object
  370. asTYPEID_MASK_OBJECT = 0x1C000000,
  371. //! The bit that shows if the type is an application registered type
  372. asTYPEID_APPOBJECT = 0x04000000,
  373. //! The bit that shows if the type is a script class
  374. asTYPEID_SCRIPTOBJECT = 0x08000000,
  375. //! The bit that shows if the type is a script array
  376. asTYPEID_SCRIPTARRAY = 0x10000000,
  377. //! The mask for the type id sequence number
  378. asTYPEID_MASK_SEQNBR = 0x03FFFFFF
  379. };
  380. // Type modifiers
  381. //! \brief Type modifiers
  382. enum asETypeModifiers
  383. {
  384. //! No modification
  385. asTM_NONE = 0,
  386. //! Input reference
  387. asTM_INREF = 1,
  388. //! Output reference
  389. asTM_OUTREF = 2,
  390. //! In/out reference
  391. asTM_INOUTREF = 3
  392. };
  393. // GetModule flags
  394. //! \brief Flags for GetModule.
  395. enum asEGMFlags
  396. {
  397. //! \brief Don't return any module if it is not found.
  398. asGM_ONLY_IF_EXISTS = 0,
  399. //! \brief Create the module if it doesn't exist.
  400. asGM_CREATE_IF_NOT_EXISTS = 1,
  401. //! \brief Always create a new module, discarding the existing one.
  402. asGM_ALWAYS_CREATE = 2
  403. };
  404. // Compile flags
  405. //! \brief Flags for compilation
  406. enum asECompileFlags
  407. {
  408. //! \brief The compiled function should be added to the scope of the module.
  409. asCOMP_ADD_TO_MODULE = 1
  410. };
  411. //! \typedef asBYTE
  412. //! \brief 8 bit unsigned integer
  413. //! \typedef asWORD
  414. //! \brief 16 bit unsigned integer
  415. //! \typedef asDWORD
  416. //! \brief 32 bit unsigned integer
  417. //! \typedef asQWORD
  418. //! \brief 64 bit unsigned integer
  419. //! \typedef asUINT
  420. //! \brief 32 bit unsigned integer
  421. //! \typedef asINT64
  422. //! \brief 64 bit integer
  423. //! \typedef asPWORD
  424. //! \brief Unsigned integer with the size of a pointer.
  425. //
  426. // asBYTE = 8 bits
  427. // asWORD = 16 bits
  428. // asDWORD = 32 bits
  429. // asQWORD = 64 bits
  430. // asPWORD = size of pointer
  431. //
  432. typedef unsigned char asBYTE;
  433. typedef unsigned short asWORD;
  434. typedef unsigned int asUINT;
  435. typedef size_t asPWORD;
  436. #ifdef __LP64__
  437. typedef unsigned int asDWORD;
  438. typedef unsigned long asQWORD;
  439. typedef long asINT64;
  440. #else
  441. typedef unsigned long asDWORD;
  442. #if defined(__GNUC__) || defined(__MWERKS__)
  443. typedef unsigned long long asQWORD;
  444. typedef long long asINT64;
  445. #else
  446. typedef unsigned __int64 asQWORD;
  447. typedef __int64 asINT64;
  448. #endif
  449. #endif
  450. typedef void (*asFUNCTION_t)();
  451. typedef void (*asGENFUNC_t)(asIScriptGeneric *);
  452. //! The function signature for the custom memory allocation function
  453. typedef void *(*asALLOCFUNC_t)(size_t);
  454. //! The function signature for the custom memory deallocation function
  455. typedef void (*asFREEFUNC_t)(void *);
  456. //! \ingroup funcs
  457. //! \brief Returns an asSFuncPtr representing the function specified by the name
  458. #define asFUNCTION(f) asFunctionPtr(f)
  459. //! \ingroup funcs
  460. //! \brief Returns an asSFuncPtr representing the function specified by the name, parameter list, and return type
  461. #if defined(_MSC_VER) && _MSC_VER <= 1200
  462. // MSVC 6 has a bug that prevents it from properly compiling using the correct asFUNCTIONPR with operator >
  463. // so we need to use ordinary C style cast instead of static_cast. The drawback is that the compiler can't
  464. // check that the cast is really valid.
  465. #define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())((r (*)p)(f)))
  466. #else
  467. #define asFUNCTIONPR(f,p,r) asFunctionPtr((void (*)())(static_cast<r (*)p>(f)))
  468. #endif
  469. #ifndef AS_NO_CLASS_METHODS
  470. class asCUnknownClass;
  471. typedef void (asCUnknownClass::*asMETHOD_t)();
  472. //! \brief Represents a function or method pointer.
  473. struct asSFuncPtr
  474. {
  475. union
  476. {
  477. // The largest known method point is 20 bytes (MSVC 64bit),
  478. // but with 8byte alignment this becomes 24 bytes. So we need
  479. // to be able to store at least that much.
  480. char dummy[25];
  481. struct {asMETHOD_t mthd; char dummy[25-sizeof(asMETHOD_t)];} m;
  482. struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
  483. } ptr;
  484. asBYTE flag; // 1 = generic, 2 = global func, 3 = method
  485. };
  486. //! \ingroup funcs
  487. //! \brief Returns an asSFuncPtr representing the class method specified by class and method name.
  488. #define asMETHOD(c,m) asSMethodPtr<sizeof(void (c::*)())>::Convert((void (c::*)())(&c::m))
  489. //! \ingroup funcs
  490. //! \brief Returns an asSFuncPtr representing the class method specified by class, method name, parameter list, return type.
  491. #define asMETHODPR(c,m,p,r) asSMethodPtr<sizeof(void (c::*)())>::Convert(static_cast<r (c::*)p>(&c::m))
  492. #else // Class methods are disabled
  493. struct asSFuncPtr
  494. {
  495. union
  496. {
  497. char dummy[25]; // largest known class method pointer
  498. struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
  499. } ptr;
  500. asBYTE flag; // 1 = generic, 2 = global func
  501. };
  502. #endif
  503. //! \brief Represents a compiler message
  504. struct asSMessageInfo
  505. {
  506. //! The script section where the message is raised
  507. const char *section;
  508. //! The row number
  509. int row;
  510. //! The column
  511. int col;
  512. //! The type of message
  513. asEMsgType type;
  514. //! The message text
  515. const char *message;
  516. };
  517. // API functions
  518. // ANGELSCRIPT_EXPORT is defined when compiling the dll or lib
  519. // ANGELSCRIPT_DLL_LIBRARY_IMPORT is defined when dynamically linking to the
  520. // dll through the link lib automatically generated by MSVC++
  521. // ANGELSCRIPT_DLL_MANUAL_IMPORT is defined when manually loading the dll
  522. // Don't define anything when linking statically to the lib
  523. //! \def AS_API
  524. //! \brief A define that specifies how the function should be imported
  525. #ifdef WIN32
  526. #ifdef ANGELSCRIPT_EXPORT
  527. #define AS_API __declspec(dllexport)
  528. #elif defined ANGELSCRIPT_DLL_LIBRARY_IMPORT
  529. #define AS_API __declspec(dllimport)
  530. #else // statically linked library
  531. #define AS_API
  532. #endif
  533. #else
  534. #define AS_API
  535. #endif
  536. #ifndef ANGELSCRIPT_DLL_MANUAL_IMPORT
  537. extern "C"
  538. {
  539. // Engine
  540. //! \brief Creates the script engine.
  541. //!
  542. //! \param[in] version The library version. Should always be \ref ANGELSCRIPT_VERSION.
  543. //! \return A pointer to the script engine interface.
  544. //!
  545. //! Call this function to create a new script engine. When you're done with the
  546. //! script engine, i.e. after you've executed all your scripts, you should call
  547. //! \ref asIScriptEngine::Release "Release" on the pointer to free the engine object.
  548. AS_API asIScriptEngine * asCreateScriptEngine(asDWORD version);
  549. //! \brief Returns the version of the compiled library.
  550. //!
  551. //! \return A null terminated string with the library version.
  552. //!
  553. //! The returned string can be used for presenting the library version in a log file, or in the GUI.
  554. AS_API const char * asGetLibraryVersion();
  555. //! \brief Returns the options used to compile the library.
  556. //!
  557. //! \return A null terminated string with indicators that identify the options
  558. //! used to compile the script library.
  559. //!
  560. //! This can be used to identify at run-time different ways to configure the engine.
  561. //! For example, if the returned string contain the identifier AS_MAX_PORTABILITY then
  562. //! functions and methods must be registered with the \ref asCALL_GENERIC calling convention.
  563. AS_API const char * asGetLibraryOptions();
  564. // Context
  565. //! \brief Returns the currently active context.
  566. //!
  567. //! \return A pointer to the currently executing context, or null if no context is executing.
  568. //!
  569. //! This function is most useful for registered functions, as it will allow them to obtain
  570. //! a pointer to the context that is calling the function, and through that get the engine,
  571. //! or custom user data.
  572. //!
  573. //! If the script library is compiled with multithread support, this function will return
  574. //! the context that is currently active in the thread that is being executed. It will thus
  575. //! work even if there are multiple threads executing scripts at the same time.
  576. AS_API asIScriptContext * asGetActiveContext();
  577. // Thread support
  578. //! \brief Cleans up memory allocated for the current thread.
  579. //!
  580. //! \return A negative value on error.
  581. //! \retval asCONTEXT_ACTIVE A context is still active.
  582. //!
  583. //! Call this method before terminating a thread that has
  584. //! accessed the engine to clean up memory allocated for that thread.
  585. //!
  586. //! It's not necessary to call this if only a single thread accesses the engine.
  587. AS_API int asThreadCleanup();
  588. // Memory management
  589. //! \brief Set the memory management functions that AngelScript should use.
  590. //!
  591. //! \param[in] allocFunc The function that will be used to allocate memory.
  592. //! \param[in] freeFunc The function that will be used to free the memory.
  593. //! \return A negative value on error.
  594. //!
  595. //! Call this method to register the global memory allocation and deallocation
  596. //! functions that AngelScript should use for memory management. This function
  597. //! Should be called before \ref asCreateScriptEngine.
  598. //!
  599. //! If not called, AngelScript will use the malloc and free functions from the
  600. //! standard C library.
  601. AS_API int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc);
  602. //! \brief Remove previously registered memory management functions.
  603. //!
  604. //! \return A negative value on error.
  605. //!
  606. //! Call this method to restore the default memory management functions.
  607. AS_API int asResetGlobalMemoryFunctions();
  608. }
  609. #endif // ANGELSCRIPT_DLL_MANUAL_IMPORT
  610. // Interface declarations
  611. //! \brief The engine interface
  612. class asIScriptEngine
  613. {
  614. public:
  615. // Memory management
  616. //! \name Memory management
  617. //! \{
  618. //! \brief Increase reference counter.
  619. //!
  620. //! \return The number of references to this object.
  621. //!
  622. //! Call this method when storing an additional reference to the object.
  623. //! Remember that the first reference that is received from \ref asCreateScriptEngine
  624. //! is already accounted for.
  625. virtual int AddRef() = 0;
  626. //! \brief Decrease reference counter.
  627. //!
  628. //! \return The number of references to this object.
  629. //!
  630. //! Call this method when you will no longer use the references that you own.
  631. virtual int Release() = 0;
  632. //! \}
  633. // Engine properties
  634. //! \name Engine properties
  635. //! \{
  636. //! \brief Dynamically change some engine properties.
  637. //!
  638. //! \param[in] property One of the \ref asEEngineProp values.
  639. //! \param[in] value The new value of the property.
  640. //! \return Negative value on error.
  641. //! \retval asINVALID_ARG Invalid property.
  642. //!
  643. //! With this method you can change the way the script engine works in some regards.
  644. virtual int SetEngineProperty(asEEngineProp property, asPWORD value) = 0;
  645. //! \brief Retrieve current engine property settings.
  646. //!
  647. //! \param[in] property One of the \ref asEEngineProp values.
  648. //! \return The value of the property, or 0 if it is an invalid property.
  649. //!
  650. //! Calling this method lets you determine the current value of the engine properties.
  651. virtual asPWORD GetEngineProperty(asEEngineProp property) = 0;
  652. //! \}
  653. // Compiler messages
  654. //! \name Compiler messages
  655. //! \{
  656. //! \brief Sets a message callback that will receive compiler messages.
  657. //!
  658. //! \param[in] callback A function or class method pointer.
  659. //! \param[in] obj The object for methods, or an optional parameter for functions.
  660. //! \param[in] callConv The calling convention.
  661. //! \return A negative value for an error.
  662. //! \retval asINVALID_ARG One of the arguments is incorrect, e.g. obj is null for a class method.
  663. //! \retval asNOT_SUPPORTED The arguments are not supported, e.g. asCALL_GENERIC.
  664. //!
  665. //! This method sets the callback routine that will receive compiler messages.
  666. //! The callback routine can be either a class method, e.g:
  667. //! \code
  668. //! void MyClass::MessageCallback(const asSMessageInfo *msg);
  669. //! r = engine->SetMessageCallback(asMETHOD(MyClass,MessageCallback), &obj, asCALL_THISCALL);
  670. //! \endcode
  671. //! or a global function, e.g:
  672. //! \code
  673. //! void MessageCallback(const asSMessageInfo *msg, void *param);
  674. //! r = engine->SetMessageCallback(asFUNCTION(MessageCallback), param, asCALL_CDECL);
  675. //! \endcode
  676. //! It is recommended to register the message callback routine right after creating the engine,
  677. //! as some of the registration functions can provide useful information to better explain errors.
  678. virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) = 0;
  679. //! \brief Clears the registered message callback routine.
  680. //!
  681. //! \return A negative value on error.
  682. //!
  683. //! Call this method to remove the message callback.
  684. virtual int ClearMessageCallback() = 0;
  685. //! \brief Writes a message to the message callback.
  686. //!
  687. //! \param[in] section The name of the script section.
  688. //! \param[in] row The row number.
  689. //! \param[in] col The column number.
  690. //! \param[in] type The message type.
  691. //! \param[in] message The message text.
  692. //! \return A negative value on error.
  693. //! \retval asINVALID_ARG The section or message is null.
  694. //!
  695. //! This method can be used by the application to write messages
  696. //! to the same message callback that the script compiler uses. This
  697. //! is useful for example if a preprocessor is used.
  698. virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message) = 0;
  699. //! \}
  700. // JIT Compiler
  701. //! \name JIT compiler
  702. //! \{
  703. //! \brief Sets the JIT compiler
  704. virtual int SetJITCompiler(asIJITCompiler *compiler) = 0;
  705. //! \brief Returns the JIT compiler
  706. virtual asIJITCompiler *GetJITCompiler() = 0;
  707. //! \}
  708. // Global functions
  709. //! \name Global functions
  710. //! \{
  711. //! \brief Registers a global function.
  712. //!
  713. //! \param[in] declaration The declaration of the global function in script syntax.
  714. //! \param[in] funcPointer The function pointer.
  715. //! \param[in] callConv The calling convention for the function.
  716. //! \return A negative value on error, or the function id if successful.
  717. //! \retval asNOT_SUPPORTED The calling convention is not supported.
  718. //! \retval asWRONG_CALLING_CONV The function's calling convention doesn't match \a callConv.
  719. //! \retval asINVALID_DECLARATION The function declaration is invalid.
  720. //! \retval asNAME_TAKEN The function name is already used elsewhere.
  721. //!
  722. //! This method registers system functions that the scripts may use to communicate with the host application.
  723. //!
  724. //! \see \ref doc_register_func
  725. virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
  726. //! \brief Returns the number of registered functions.
  727. //! \return The number of registered functions.
  728. virtual int GetGlobalFunctionCount() = 0;
  729. //! \brief Returns the function id of the registered function.
  730. //! \param[in] index The index of the registered global function.
  731. //! \return The id of the function, or a negative value on error.
  732. //! \retval asINVALID_ARG \a index is too large.
  733. virtual int GetGlobalFunctionIdByIndex(asUINT index) = 0;
  734. //! \}
  735. // Global properties
  736. //! \name Global properties
  737. //! \{
  738. //! \brief Registers a global property.
  739. //!
  740. //! \param[in] declaration The declaration of the global property in script syntax.
  741. //! \param[in] pointer The address of the property that will be used to access the property value.
  742. //! \return A negative value on error.
  743. //! \retval asINVALID_DECLARATION The declaration has invalid syntax.
  744. //! \retval asINVALID_TYPE The declaration is a reference.
  745. //! \retval asNAME_TAKEN The name is already taken.
  746. //!
  747. //! Use this method to register a global property that the scripts will be
  748. //! able to access as global variables. The property may optionally be registered
  749. //! as const, if the scripts shouldn't be allowed to modify it.
  750. //!
  751. //! When registering the property, the application must pass the address to
  752. //! the actual value. The application must also make sure that this address
  753. //! remains valid throughout the life time of this registration, i.e. until
  754. //! the engine is released or the dynamic configuration group is removed.
  755. virtual int RegisterGlobalProperty(const char *declaration, void *pointer) = 0;
  756. //! \brief Returns the number of registered global properties.
  757. //! \return The number of registered global properties.
  758. virtual int GetGlobalPropertyCount() = 0;
  759. //! \brief Returns the detail on the registered global property.
  760. //! \param[in] index The index of the global variable.
  761. //! \param[out] name Receives the name of the property.
  762. //! \param[out] typeId Receives the typeId of the property.
  763. //! \param[out] isConst Receives the constness indicator of the property.
  764. //! \param[out] configGroup Receives the config group in which the property was registered.
  765. //! \param[out] pointer Receives the pointer of the property.
  766. //! \return A negative value on error.
  767. //! \retval asINVALID_ARG \a index is too large.
  768. virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0) = 0;
  769. //! \}
  770. // Object types
  771. //! \name Object types
  772. //! \{
  773. //! \brief Registers a new object type.
  774. //!
  775. //! \param[in] obj The name of the type.
  776. //! \param[in] byteSize The size of the type in bytes. Only necessary for value types.
  777. //! \param[in] flags One or more of the asEObjTypeFlags.
  778. //! \return A negative value on error.
  779. //! \retval asINVALID_ARG The flags are invalid.
  780. //! \retval asINVALID_NAME The name is invalid.
  781. //! \retval asALREADY_REGISTERED Another type of the same name already exists.
  782. //! \retval asNAME_TAKEN The name conflicts with other symbol names.
  783. //! \retval asLOWER_ARRAY_DIMENSION_NOT_REGISTERED When registering an array type the array element must be a primitive or a registered type.
  784. //! \retval asINVALID_TYPE The array type was not properly formed.
  785. //! \retval asNOT_SUPPORTED The array type is not supported, or already in use preventing it from being overloaded.
  786. //!
  787. //! Use this method to register new types that should be available to the scripts.
  788. //! Reference types, which have their memory managed by the application, should be registered with \ref asOBJ_REF.
  789. //! Value types, which have their memory managed by the engine, should be registered with \ref asOBJ_VALUE.
  790. //!
  791. //! \see \ref doc_register_type
  792. virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags) = 0;
  793. //! \brief Registers a property for the object type.
  794. //!
  795. //! \param[in] obj The name of the type.
  796. //! \param[in] declaration The property declaration in script syntax.
  797. //! \param[in] byteOffset The offset into the memory block where this property is found.
  798. //! \return A negative value on error.
  799. //! \retval asWRONG_CONFIG_GROUP The object type was registered in a different configuration group.
  800. //! \retval asINVALID_OBJECT The \a obj does not specify an object type.
  801. //! \retval asINVALID_TYPE The \a obj parameter has invalid syntax.
  802. //! \retval asINVALID_DECLARATION The \a declaration is invalid.
  803. //! \retval asNAME_TAKEN The name conflicts with other members.
  804. //!
  805. //! Use this method to register a member property of a class. The property must
  806. //! be local to the object, i.e. not a global variable or a static member. The
  807. //! easiest way to get the offset of the property is to use the offsetof macro
  808. //! from stddef.h.
  809. //!
  810. //! \code
  811. //! struct MyType {float prop;};
  812. //! r = engine->RegisterObjectProperty("MyType", "float prop", offsetof(MyType, prop)));
  813. //! \endcode
  814. virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset) = 0;
  815. //! \brief Registers a method for the object type.
  816. //!
  817. //! \param[in] obj The name of the type.
  818. //! \param[in] declaration The declaration of the method in script syntax.
  819. //! \param[in] funcPointer The method or function pointer.
  820. //! \param[in] callConv The calling convention for the method or function.
  821. //! \return A negative value on error, or the function id if successful.
  822. //! \retval asWRONG_CONFIG_GROUP The object type was registered in a different configuration group.
  823. //! \retval asNOT_SUPPORTED The calling convention is not supported.
  824. //! \retval asINVALID_TYPE The \a obj parameter is not a valid object name.
  825. //! \retval asINVALID_DECLARATION The \a declaration is invalid.
  826. //! \retval asNAME_TAKEN The name conflicts with other members.
  827. //! \retval asWRONG_CALLING_CONV The function's calling convention isn't compatible with \a callConv.
  828. //!
  829. //! Use this method to register a member method for the type. The method
  830. //! that is registered may be an actual class method, or a global function
  831. //! that takes the object pointer as either the first or last parameter. Or
  832. //! it may be a global function implemented with the generic calling convention.
  833. //!
  834. //! \see \ref doc_register_func
  835. virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
  836. //! \brief Registers a behaviour for the object type.
  837. //!
  838. //! \param[in] obj The name of the type.
  839. //! \param[in] behaviour One of the object behaviours from \ref asEBehaviours.
  840. //! \param[in] declaration The declaration of the method in script syntax.
  841. //! \param[in] funcPointer The method or function pointer.
  842. //! \param[in] callConv The calling convention for the method or function.
  843. //! \return A negative value on error, or the function id is successful.
  844. //! \retval asWRONG_CONFIG_GROUP The object type was registered in a different configuration group.
  845. //! \retval asINVALID_ARG \a obj is not set, or a global behaviour is given in \a behaviour.
  846. //! \retval asWRONG_CALLING_CONV The function's calling convention isn't compatible with \a callConv.
  847. //! \retval asNOT_SUPPORTED The calling convention or the behaviour signature is not supported.
  848. //! \retval asINVALID_TYPE The \a obj parameter is not a valid object name.
  849. //! \retval asINVALID_DECLARATION The \a declaration is invalid.
  850. //! \retval asILLEGAL_BEHAVIOUR_FOR_TYPE The \a behaviour is not allowed for this type.
  851. //! \retval asALREADY_REGISTERED The behaviour is already registered with the same signature.
  852. //!
  853. //! Use this method to register behaviour functions that will be called by
  854. //! the virtual machine to perform certain operations, such as memory management,
  855. //! math operations, comparisons, etc.
  856. //!
  857. //! \see \ref doc_register_func, \ref doc_reg_opbeh
  858. virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv) = 0;
  859. //! \brief Registers an interface.
  860. //!
  861. //! \param[in] name The name of the interface.
  862. //! \return A negative value on error.
  863. //! \retval asINVALID_NAME The \a name is null, or a reserved keyword.
  864. //! \retval asALREADY_REGISTERED An object type with this name already exists.
  865. //! \retval asERROR The \a name is not a proper identifier.
  866. //! \retval asNAME_TAKEN The \a name is already used elsewhere.
  867. //!
  868. //! This registers an interface that script classes can implement. By doing this the application
  869. //! can register functions and methods that receives an \ref asIScriptObject and still be sure that the
  870. //! class implements certain methods needed by the application.
  871. virtual int RegisterInterface(const char *name) = 0;
  872. //! \brief Registers an interface method.
  873. //!
  874. //! \param[in] intf The name of the interface.
  875. //! \param[in] declaration The method declaration.
  876. //! \return A negative value on error.
  877. //! \retval asWRONG_CONFIG_GROUP The interface was registered in another configuration group.
  878. //! \retval asINVALID_TYPE \a intf is not an interface type.
  879. //! \retval asINVALID_DECLARATION The \a declaration is invalid.
  880. //! \retval asNAME_TAKEN The method name is already taken.
  881. //!
  882. //! This registers a method that the class that implements the interface must have.
  883. virtual int RegisterInterfaceMethod(const char *intf, const char *declaration) = 0;
  884. //! \brief Returns the number of registered object types.
  885. //! \return The number of object types registered by the application.
  886. virtual int GetObjectTypeCount() = 0;
  887. //! \brief Returns the object type interface by index.
  888. //! \param[in] index The index of the type.
  889. //! \return The registered object type interface for the type, or null if not found.
  890. virtual asIObjectType *GetObjectTypeByIndex(asUINT index) = 0;
  891. //! \}
  892. // String factory
  893. //! \name String factory
  894. //! \{
  895. //! \brief Registers the string factory.
  896. //!
  897. //! \param[in] datatype The datatype that the string factory returns
  898. //! \param[in] factoryFunc The pointer to the factory function
  899. //! \param[in] callConv The calling convention of the factory function
  900. //! \return A negative value on error, or the function id if successful.
  901. //! \retval asNOT_SUPPORTED The calling convention is not supported.
  902. //! \retval asWRONG_CALLING_CONV The function's calling convention doesn't match \a callConv.
  903. //! \retval asINVALID_TYPE The \a datatype is not a valid type.
  904. //!
  905. //! Use this function to register a string factory that will be called when the
  906. //! virtual machine finds a string constant in an expression. The string factory
  907. //! function will receive two parameters, the length of the string constant in bytes and a
  908. //! pointer to the character data. The factory should return a value to a previously
  909. //! registered type that will represent the string. Example:
  910. //!
  911. //! \code
  912. //! // Our string factory implementation
  913. //! std::string StringFactory(unsigned int byteLength, const char *s)
  914. //! {
  915. //! return std::string(s, byteLength);
  916. //! }
  917. //!
  918. //! // Registering the string factory
  919. //! int r = engine->RegisterStringFactory("string", asFUNCTION(StringFactory), asCALL_CDECL); assert( r >= 0 );
  920. //! \endcode
  921. //!
  922. //! The example assumes that the std::string type has been registered as the string type, with \ref RegisterObjectType.
  923. virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv) = 0;
  924. //! \brief Returns the type id of the type that the string factory returns.
  925. //! \return The type id of the type that the string type returns, or a negative value on error.
  926. //! \retval asNO_FUNCTION The string factory has not been registered.
  927. virtual int GetStringFactoryReturnTypeId() = 0;
  928. //! \}
  929. // Enums
  930. //! \name Enums
  931. //! \{
  932. //! \brief Registers an enum type.
  933. //!
  934. //! \param[in] type The name of the enum type.
  935. //! \return A negative value on error.
  936. //! \retval asINVALID_NAME \a type is null.
  937. //! \retval asALREADY_REGISTERED Another type with this name already exists.
  938. //! \retval asERROR The \a type couldn't be parsed.
  939. //! \retval asINVALID_NAME The \a type is not an identifier, or it is a reserved keyword.
  940. //! \retval asNAME_TAKEN The type name is already taken.
  941. //!
  942. //! This method registers an enum type in the engine. The enum values should then be registered
  943. //! with \ref RegisterEnumValue.
  944. virtual int RegisterEnum(const char *type) = 0;
  945. //! \brief Registers an enum value.
  946. //!
  947. //! \param[in] type The name of the enum type.
  948. //! \param[in] name The name of the enum value.
  949. //! \param[in] value The integer value of the enum value.
  950. //! \return A negative value on error.
  951. //! \retval asWRONG_CONFIG_GROUP The enum \a type was registered in a different configuration group.
  952. //! \retval asINVALID_TYPE The \a type is invalid.
  953. //! \retval asALREADY_REGISTERED The \a name is already registered for this enum.
  954. //!
  955. //! This method registers an enum value for a previously registered enum type.
  956. virtual int RegisterEnumValue(const char *type, const char *name, int value) = 0;
  957. //! \brief Returns the number of registered enum types.
  958. //! \return The number of registered enum types.
  959. virtual int GetEnumCount() = 0;
  960. //! \brief Returns the registered enum type.
  961. //! \param[in] index The index of the enum type.
  962. //! \param[out] enumTypeId Receives the type if of the enum type.
  963. //! \param[out] configGroup Receives the config group in which the enum was registered.
  964. //! \return The name of the registered enum type, or null on error.
  965. virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId, const char **configGroup = 0) = 0;
  966. //! \brief Returns the number of enum values for the enum type.
  967. //! \param[in] enumTypeId The type id of the enum type.
  968. //! \return The number of enum values for the enum type.
  969. virtual int GetEnumValueCount(int enumTypeId) = 0;
  970. //! \brief Returns the name and value of the enum value for the enum type.
  971. //! \param[in] enumTypeId The type id of the enum type.
  972. //! \param[in] index The index of the enum value.
  973. //! \param[out] outValue Receives the value of the enum value.
  974. //! \return The name of the enum value.
  975. virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) = 0;
  976. //! \}
  977. // Typedefs
  978. //! \name Typedefs
  979. //! \{
  980. //! \brief Registers a typedef.
  981. //!
  982. //! \param[in] type The name of the new typedef
  983. //! \param[in] decl The datatype that the typedef represents
  984. //! \return A negative value on error.
  985. //! \retval asINVALID_NAME The \a type is null.
  986. //! \retval asALREADY_REGISTERED A type with the same name already exists.
  987. //! \retval asINVALID_TYPE The \a decl is not a primitive type.
  988. //! \retval asINVALID_NAME The \a type is not an identifier, or it is a reserved keyword.
  989. //! \retval asNAME_TAKEN The name is already used elsewhere.
  990. //!
  991. //! This method registers an alias for a data type.
  992. //!
  993. //! Currently typedefs can only be registered for built-in primitive types.
  994. virtual int RegisterTypedef(const char *type, const char *decl) = 0;
  995. //! \brief Returns the number of registered typedefs.
  996. //! \return The number of registered typedefs.
  997. virtual int GetTypedefCount() = 0;
  998. //! \brief Returns a registered typedef.
  999. //! \param[in] index The index of the typedef.
  1000. //! \param[out] typeId The type that the typedef aliases.
  1001. //! \param[out] configGroup Receives the config group in which the type def was registered.
  1002. //! \return The name of the typedef.
  1003. virtual const char *GetTypedefByIndex(asUINT index, int *typeId, const char **configGroup = 0) = 0;
  1004. //! \}
  1005. // Configuration groups
  1006. //! \name Configuration groups
  1007. //! \{
  1008. //! \brief Starts a new dynamic configuration group.
  1009. //!
  1010. //! \param[in] groupName The name of the configuration group
  1011. //! \return A negative value on error
  1012. //! \retval asNAME_TAKEN Another group with the same name already exists.
  1013. //! \retval asNOT_SUPPORTED Nesting configuration groups is not supported.
  1014. //!
  1015. //! Starts a new dynamic configuration group. This group can be setup so that it is only
  1016. //! visible to specific modules, and it can also be removed when it is no longer used.
  1017. virtual int BeginConfigGroup(const char *groupName) = 0;
  1018. //! \brief Ends the configuration group.
  1019. //!
  1020. //! \return A negative value on error
  1021. //! \retval asNOT_SUPPORTED Can't end a group that hasn't been begun.
  1022. //!
  1023. //! Ends the current configuration group. Once finished a config group cannot be changed,
  1024. //! but it can be removed when it is no longer used.
  1025. virtual int EndConfigGroup() = 0;
  1026. //! \brief Removes a previously registered configuration group.
  1027. //!
  1028. //! \param[in] groupName The name of the configuration group
  1029. //! \return A negative value on error
  1030. //! \retval asCONFIG_GROUP_IS_IN_USE The group is in use and cannot be removed.
  1031. //!
  1032. //! Remove the configuration group. If something in the configuration group is currently in
  1033. //! use, the function will return with an error code. Examples of uses are compiled modules
  1034. //! that have function calls to functions in the group and global variables of types registered
  1035. //! in the group.
  1036. virtual int RemoveConfigGroup(const char *groupName) = 0;
  1037. //! \brief Tell AngelScript which modules have access to which configuration groups.
  1038. //!
  1039. //! \param[in] groupName The name of the configuration group
  1040. //! \param[in] module The module name
  1041. //! \param[in] hasAccess Whether the module has access or not to the group members
  1042. //! \return A negative value on error
  1043. //! \retval asWRONG_CONFIG_GROUP No group with the \a groupName was found.
  1044. //!
  1045. //! With this method the application can give modules access to individual configuration groups.
  1046. //! This is useful when exposing more than one script interface for various parts of the application,
  1047. //! e.g. one interface for GUI handling, another for in-game events, etc.
  1048. //!
  1049. //! The default module access is granted. The default for a group can be changed by specifying
  1050. //! the modulename asALL_MODULES.
  1051. virtual int SetConfigGroupModuleAccess(const char *groupName, const char *module, bool hasAccess) = 0;
  1052. //! \}
  1053. // Script modules
  1054. //! \name Script modules
  1055. //! \{
  1056. //! \brief Return an interface pointer to the module.
  1057. //!
  1058. //! \param[in] module The name of the module
  1059. //! \param[in] flag One of the \ref asEGMFlags flags
  1060. //! \return A pointer to the module interface
  1061. //!
  1062. //! Use this method to get access to the module interface, which will
  1063. //! let you build new scripts, and enumerate functions and types in
  1064. //! existing modules.
  1065. //!
  1066. //! If \ref asGM_ALWAYS_CREATE is informed as the flag the previous
  1067. //! module with the same name will be discarded, thus any pointers that
  1068. //! the engine holds to it will be invalid after the call.
  1069. virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag = asGM_ONLY_IF_EXISTS) = 0;
  1070. //! \brief Discard a module.
  1071. //!
  1072. //! \param[in] module The name of the module
  1073. //! \return A negative value on error
  1074. //! \retval asNO_MODULE The module was not found.
  1075. //!
  1076. //! Discards a module and frees its memory. Any pointers that the application holds
  1077. //! to this module will be invalid after this call.
  1078. virtual int DiscardModule(const char *module) = 0;
  1079. //! \}
  1080. // Script functions
  1081. //! \name Script functions
  1082. //! \{
  1083. //! \brief Returns the function descriptor for the script function
  1084. //! \param[in] funcId The id of the function or method.
  1085. //! \return A pointer to the function description interface, or null if not found.
  1086. virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) = 0;
  1087. //! \}
  1088. // Type identification
  1089. //! \name Type identification
  1090. //! \{
  1091. //! \brief Returns the object type interface for type.
  1092. //! \param[in] typeId The type id of the type.
  1093. //! \return The object type interface for the type, or null if not found.
  1094. virtual asIObjectType *GetObjectTypeById(int typeId) = 0;
  1095. //! \brief Returns a type id by declaration.
  1096. //! \param[in] decl The declaration of the type.
  1097. //! \return A negative value on error, or the type id of the type.
  1098. //! \retval asINVALID_TYPE \a decl is not a valid type.
  1099. //!
  1100. //! Translates a type declaration into a type id. The returned type id is valid for as long as
  1101. //! the type is valid, so you can safely store it for later use to avoid potential overhead by
  1102. //! calling this function each time. Just remember to update the type id, any time the type is
  1103. //! changed within the engine, e.g. when recompiling script declared classes, or changing the
  1104. //! engine configuration.
  1105. //!
  1106. //! The type id is based on a sequence number and depends on the order in which the type ids are
  1107. //! queried, thus is not guaranteed to always be the same for each execution of the application.
  1108. //! The \ref asETypeIdFlags can be used to obtain some information about the type directly from the id.
  1109. //!
  1110. //! A base type yields the same type id whether the declaration is const or not, however if the
  1111. //! const is for the subtype then the type id is different, e.g. string@ isn't the same as const
  1112. //! string@ but string is the same as const string.
  1113. //!
  1114. //! This method is only able to return the type id that are not specific for a script module, i.e.
  1115. //! built-in types and application registered types. Type ids for script declared types should
  1116. //! be obtained through the script module's \ref asIScriptModule::GetTypeIdByDecl "GetTypeIdByDecl".
  1117. virtual int GetTypeIdByDecl(const char *decl) = 0;
  1118. //! \brief Returns a type declaration.
  1119. //! \param[in] typeId The type id of the type.
  1120. //! \return A null terminated string with the type declaration, or null if not found.
  1121. virtual const char *GetTypeDeclaration(int typeId) = 0;
  1122. //! \brief Returns the size of a primitive type.
  1123. //! \param[in] typeId The type id of the type.
  1124. //! \return The size of the type in bytes.
  1125. virtual int GetSizeOfPrimitiveType(int typeId) = 0;
  1126. //! \}
  1127. // Script execution
  1128. //! \name Script execution
  1129. //! \{
  1130. //! \brief Creates a new script context.
  1131. //! \return A pointer to the new script context.
  1132. //!
  1133. //! This method creates a context that will be used to execute the script functions.
  1134. //! The context interface created will have its reference counter already increased.
  1135. virtual asIScriptContext *CreateContext() = 0;
  1136. //! \brief Creates a script object defined by its type id.
  1137. //! \param[in] typeId The type id of the object to create.
  1138. //! \return A pointer to the new object if successful, or null if not.
  1139. //!
  1140. //! This method is used to create a script object based on it's type id. The method will
  1141. //! allocate the memory and call the object's default constructor. Reference counted
  1142. //! objects will have their reference counter set to 1 so the application needs to
  1143. //! release the pointer when it will no longer use it.
  1144. //!
  1145. //! This only works for objects, for primitive types and object handles the method
  1146. //! doesn't do anything and returns a null pointer.
  1147. virtual void *CreateScriptObject(int typeId) = 0;
  1148. //! \brief Creates a copy of a script object.
  1149. //! \param[in] obj A pointer to the source object.
  1150. //! \param[in] typeId The type id of the object.
  1151. //! \return A pointer to the new object if successful, or null if not.
  1152. //!
  1153. //! This method is used to create a copy of an existing object.
  1154. //!
  1155. //! This only works for objects, for primitive types and object handles the method
  1156. //! doesn't do anything and returns a null pointer.
  1157. virtual void *CreateScriptObjectCopy(void *obj, int typeId) = 0;
  1158. //! \brief Copy one script object to another.
  1159. //! \param[in] dstObj A pointer to the destination object.
  1160. //! \param[in] srcObj A pointer to the source object.
  1161. //! \param[in] typeId The type id of the objects.
  1162. //!
  1163. //! This calls the assignment operator to copy the object from one to the other.
  1164. //!
  1165. //! This only works for objects.
  1166. virtual void CopyScriptObject(void *dstObj, void *srcObj, int typeId) = 0;
  1167. //! \brief Release the script object pointer.
  1168. //! \param[in] obj A pointer to the object.
  1169. //! \param[in] typeId The type id of the object.
  1170. //!
  1171. //! This calls the release method of the object to release the reference.
  1172. //!
  1173. //! This only works for objects.
  1174. virtual void ReleaseScriptObject(void *obj, int typeId) = 0;
  1175. //! \brief Increase the reference counter for the script object.
  1176. //! \param[in] obj A pointer to the object.
  1177. //! \param[in] typeId The type id of the object.
  1178. //!
  1179. //! This calls the add ref method of the object to increase the reference count.
  1180. //!
  1181. //! This only works for objects.
  1182. virtual void AddRefScriptObject(void *obj, int typeId) = 0;
  1183. //! \brief Returns true if the object referenced by a handle compatible with the specified type.
  1184. //! \param[in] obj A pointer to the object.
  1185. //! \param[in] objTypeId The type id of the object.
  1186. //! \param[in] handleTypeId The type id of the handle.
  1187. //! \return Returns true if the handle type is compatible with the object type.
  1188. //!
  1189. //! This method can be used to determine if a handle of a certain type is
  1190. //! compatible with an object of another type. This is useful if you have a pointer
  1191. //! to a object, but only knows that it implements a certain interface and now you
  1192. //! want to determine if it implements another interface.
  1193. virtual bool IsHandleCompatibleWithObject(void *obj, int objTypeId, int handleTypeId) = 0;
  1194. //! \}
  1195. // String interpretation
  1196. //! \name String interpretation
  1197. //! \{
  1198. //! \brief Returns the class and length of the first token in the string.
  1199. //! \param[in] string The string to parse.
  1200. //! \param[in] stringLength The length of the string. Can be 0 if the string is null terminated.
  1201. //! \param[out] tokenLength Gives the length of the identified token.
  1202. //! \return One of the \ref asETokenClass values.
  1203. //!
  1204. //! This function is useful for those applications that want to tokenize strings into
  1205. //! tokens that the script language uses, e.g. IDEs providing syntax highlighting, or intellisense.
  1206. //! It can also be used to parse the meta data strings that may be declared for script entities.
  1207. virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, int *tokenLength = 0) = 0;
  1208. //! \}
  1209. // Garbage collection
  1210. //! \name Garbage collection
  1211. //! \{
  1212. //! \brief Perform garbage collection.
  1213. //! \param[in] flags Set to a combination of the \ref asEGCFlags.
  1214. //! \return 1 if the cycle wasn't completed, 0 if it was.
  1215. //!
  1216. //! This method will free script objects that can no longer be reached. When the engine
  1217. //! is released the garbage collector will automatically do a full cycle to release all
  1218. //! objects still alive. If the engine is long living it is important to call this method
  1219. //! every once in a while to free up memory allocated by the scripts. If a script does a
  1220. //! lot of allocations before returning it may be necessary to implement a line callback
  1221. //! function that calls the garbage collector during execution of the script.
  1222. //!
  1223. //! It is not necessary to do a full cycle with every call. This makes it possible to spread
  1224. //! out the garbage collection time over a large period, thus not impacting the responsiveness
  1225. //! of the application.
  1226. //!
  1227. //! \see \ref doc_gc
  1228. virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE) = 0;
  1229. //! \brief Obtain statistics from the garbage collector.
  1230. //! \param[out] currentSize The current number of objects known to the garbage collector.
  1231. //! \param[out] totalDestroyed The total number of objects destroyed by the garbage collector.
  1232. //! \param[out] totalDetected The total number of objects detected as garbage with circular references.
  1233. //!
  1234. //! This method can be used to query the number of objects that the garbage collector is
  1235. //! keeping track of. If the number is very large then it is probably time to call the
  1236. //! \ref GarbageCollect method so that some of the objects ca be freed.
  1237. //!
  1238. //! \see \ref doc_gc
  1239. virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed = 0, asUINT *totalDetected = 0) = 0;
  1240. //! \brief Notify the garbage collector of a new object that needs to be managed.
  1241. //! \param[in] obj A pointer to the newly created object.
  1242. //! \param[in] typeId The type id of the object.
  1243. //!
  1244. //! This method should be called when a new garbage collected object is created.
  1245. //! The GC will then store a reference to the object so that it can automatically
  1246. //! detect whether the object is involved in any circular references that should be released.
  1247. //!
  1248. //! \see \ref doc_gc_object
  1249. virtual void NotifyGarbageCollectorOfNewObject(void *obj, int typeId) = 0;
  1250. //! \brief Used by the garbage collector to enumerate all references held by an object.
  1251. //! \param[in] reference A pointer to the referenced object.
  1252. //!
  1253. //! When processing the EnumReferences call the called object should call GCEnumCallback
  1254. //! for each of the references it holds to other objects.
  1255. //!
  1256. //! \see \ref doc_gc_object
  1257. virtual void GCEnumCallback(void *reference) = 0;
  1258. //! \}
  1259. // User data
  1260. //! \name User data
  1261. //! \{
  1262. //! \brief Register the memory address of some user data.
  1263. //! \param[in] data A pointer to the user data.
  1264. //! \return The previous pointer stored in the engine.
  1265. //!
  1266. //! This method allows the application to associate a value, e.g. a pointer, with the engine instance.
  1267. virtual void *SetUserData(void *data) = 0;
  1268. //! \brief Returns the address of the previously registered user data.
  1269. //! \return The pointer to the user data.
  1270. virtual void *GetUserData() = 0;
  1271. //! \}
  1272. #ifdef AS_DEPRECATED
  1273. //! \name Deprecated
  1274. //! \{
  1275. // deprecated since 2009-12-08, 2.18.0
  1276. //! \deprecated Since 2.18.0. Use the \ref doc_addon_helpers "ExecuteString" helper function instead.
  1277. virtual int ExecuteString(const char *module, const char *script, asIScriptContext **ctx = 0, asDWORD flags = 0) = 0;
  1278. //! \}
  1279. #endif
  1280. protected:
  1281. virtual ~asIScriptEngine() {}
  1282. };
  1283. //! \brief The interface to the script modules
  1284. class asIScriptModule
  1285. {
  1286. public:
  1287. //! \name Miscellaneous
  1288. //! \{
  1289. //! \brief Returns a pointer to the engine.
  1290. //! \return A pointer to the engine.
  1291. virtual asIScriptEngine *GetEngine() = 0;
  1292. //! \brief Sets the name of the module.
  1293. //! \param[in] name The new name.
  1294. //!
  1295. //! Sets the name of the script module.
  1296. virtual void SetName(const char *name) = 0;
  1297. //! \brief Gets the name of the module.
  1298. //! \return The name of the module.
  1299. virtual const char *GetName() = 0;
  1300. //! \}
  1301. // Compilation
  1302. //! \name Compilation
  1303. //! \{
  1304. //! \brief Add a script section for the next build.
  1305. //!
  1306. //! \param[in] name The name of the script section
  1307. //! \param[in] code The script code buffer
  1308. //! \param[in] codeLength The length of the script code
  1309. //! \param[in] lineOffset An offset that will be added to compiler message line numbers
  1310. //! \return A negative value on error.
  1311. //! \retval asMODULE_IS_IN_USE The module is currently in use.
  1312. //!
  1313. //! This adds a script section to the module. All sections added will be treated as if one
  1314. //! large script. Errors reported will give the name of the corresponding section.
  1315. //!
  1316. //! The code added is copied by the engine, so there is no need to keep the original buffer after the call.
  1317. //! Note that this can be changed by setting the engine property \ref asEP_COPY_SCRIPT_SECTIONS
  1318. //! with \ref asIScriptEngine::SetEngineProperty.
  1319. virtual int AddScriptSection(const char *name, const char *code, size_t codeLength = 0, int lineOffset = 0) = 0;
  1320. //! \brief Build the previously added script sections.
  1321. //!
  1322. //! \return A negative value on error
  1323. //! \retval asINVALID_CONFIGURATION The engine configuration is invalid.
  1324. //! \retval asERROR The script failed to build.
  1325. //! \retval asBUILD_IN_PROGRESS Another thread is currently building.
  1326. //!
  1327. //! Builds the script based on the added sections, and registered types and functions. After the
  1328. //! build is complete the script sections are removed to free memory. If the script module needs
  1329. //! to be rebuilt all of the script sections needs to be added again.
  1330. //!
  1331. //! Compiler messages are sent to the message callback function set with \ref asIScriptEngine::SetMessageCallback.
  1332. //! If there are no errors or warnings, no messages will be sent to the callback function.
  1333. //!
  1334. //! Any global variables found in the script will be initialized by the
  1335. //! compiler if the engine property \ref asEP_INIT_GLOBAL_VARS_AFTER_BUILD is set.
  1336. virtual int Build() = 0;
  1337. //! \brief Compile a single function.
  1338. //!
  1339. //! \param[in] sectionName The name of the script section
  1340. //! \param[in] code The script code buffer
  1341. //! \param[in] lineOffset An offset that will be added to compiler message line numbers
  1342. //! \param[in] compileFlags One of \ref asECompileFlags values
  1343. //! \param[out] outFunc Optional parameter to receive the compiled function descriptor
  1344. //! \return A negative value on error
  1345. //! \retval asINVALID_ARG One or more arguments have invalid values.
  1346. //! \retval asINVALID_CONFIGURATION The engine configuration is invalid.
  1347. //! \retval asBUILD_IN_PROGRESS Another build is in progress.
  1348. //! \retval asERROR The compilation failed.
  1349. //!
  1350. //! Use this to compile a single function. The function can be optionally added to the scope of the module, in which case
  1351. //! it will be available for subsequent compilations. If not added to the module, the function can still be returned in the
  1352. //! output parameter, which will allow the application to execute it, and then discard it when it is no longer needed.
  1353. //!
  1354. //! If the output function parameter is set, remember to release the function object when you're done with it.
  1355. virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) = 0;
  1356. //! \brief Compile a single global variable and add it to the scope of the module
  1357. //!
  1358. //! \param[in] sectionName The name of the script section
  1359. //! \param[in] code The script code buffer
  1360. //! \param[in] lineOffset An offset that will be added to compiler message line numbers
  1361. //! \return A negative value on error
  1362. //! \retval asINVALID_ARG One or more arguments have invalid values.
  1363. //! \retval asINVALID_CONFIGURATION The engine configuration is invalid.
  1364. //! \retval asBUILD_IN_PROGRESS Another build is in progress.
  1365. //! \retval asERROR The compilation failed.
  1366. //!
  1367. //! Use this to add a single global variable to the scope of a module. The variable can then
  1368. //! be referred to by the application and subsequent compilations.
  1369. //!
  1370. //! The script code may contain an initialization expression, which will be executed by the
  1371. //! compiler if the engine property \ref asEP_INIT_GLOBAL_VARS_AFTER_BUILD is set.
  1372. virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset) = 0;
  1373. //! \}
  1374. // Functions
  1375. //! \name Functions
  1376. //! \{
  1377. //! \brief Returns the number of global functions in the module.
  1378. //! \return A negative value on error, or the number of global functions in this module.
  1379. //! \retval asERROR The module was not compiled successfully.
  1380. //!
  1381. //! This method retrieves the number of compiled script functions.
  1382. virtual int GetFunctionCount() = 0;
  1383. //! \brief Returns the function id by index.
  1384. //! \param[in] index The index of the function.
  1385. //! \return A negative value on error, or the function id.
  1386. //! \retval asNO_FUNCTION There is no function with that index.
  1387. //!
  1388. //! This method should be used to retrieve the id of the script function that you wish to
  1389. //! execute. The id is then sent to the context's \ref asIScriptContext::Prepare "Prepare" method.
  1390. virtual int GetFunctionIdByIndex(int index) = 0;
  1391. //! \brief Returns the function id by name.
  1392. //! \param[in] name The name of the function.
  1393. //! \return A negative value on error, or the function id.
  1394. //! \retval asERROR The module was not compiled successfully.
  1395. //! \retval asMULTIPLE_FUNCTIONS Found multiple matching functions.
  1396. //! \retval asNO_FUNCTION Didn't find any matching functions.
  1397. //!
  1398. //! This method should be used to retrieve the id of the script function that you
  1399. //! wish to execute. The id is then sent to the context's \ref asIScriptContext::Prepare "Prepare" method.
  1400. virtual int GetFunctionIdByName(const char *name) = 0;
  1401. //! \brief Returns the function id by declaration.
  1402. //! \param[in] decl The function signature.
  1403. //! \return A negative value on error, or the function id.
  1404. //! \retval asERROR The module was not compiled successfully.
  1405. //! \retval asINVALID_DECLARATION The \a decl is invalid.
  1406. //! \retval asMULTIPLE_FUNCTIONS Found multiple matching functions.
  1407. //! \retval asNO_FUNCTION Didn't find any matching functions.
  1408. //!
  1409. //! This method should be used to retrieve the id of the script function that you wish
  1410. //! to execute. The id is then sent to the context's \ref asIScriptContext::Prepare "Prepare" method.
  1411. //!
  1412. //! The method will find the script function with the exact same declaration.
  1413. virtual int GetFunctionIdByDecl(const char *decl) = 0;
  1414. //! \brief Returns the function descriptor for the script function
  1415. //! \param[in] index The index of the function.
  1416. //! \return A pointer to the function description interface, or null if not found.
  1417. virtual asIScriptFunction *GetFunctionDescriptorByIndex(int index) = 0;
  1418. //! \brief Returns the function descriptor for the script function
  1419. //! \param[in] funcId The id of the function or method.
  1420. //! \return A pointer to the function description interface, or null if not found.
  1421. virtual asIScriptFunction *GetFunctionDescriptorById(int funcId) = 0;
  1422. //! \brief Remove a single function from the scope of the module
  1423. //! \param[in] funcId The id of the function to remove.
  1424. //! \return A negative value on error.
  1425. //! \retval asNO_FUNCTION The function is not part of the scope.
  1426. //!
  1427. //! This method allows the application to remove a single function from the
  1428. //! scope of the module. The function is not destroyed immediately though,
  1429. //! only when no more references point to it.
  1430. virtual int RemoveFunction(int funcId) = 0;
  1431. //! \}
  1432. // Global variables
  1433. //! \name Global variables
  1434. //! \{
  1435. //! \brief Reset the global variables of the module.
  1436. //!
  1437. //! \return A negative value on error.
  1438. //! \retval asERROR The module was not compiled successfully.
  1439. //!
  1440. //! Resets the global variables declared in this module to their initial value.
  1441. virtual int ResetGlobalVars() = 0;
  1442. //! \brief Returns the number of global variables in the module.
  1443. //! \return A negative value on error, or the number of global variables in the module.
  1444. //! \retval asERROR The module was not compiled successfully.
  1445. //! \retval asINIT_GLOBAL_VARS_FAILED The initialization of the global variables failed.
  1446. virtual int GetGlobalVarCount() = 0;
  1447. //! \brief Returns the global variable index by name.
  1448. //! \param[in] name The name of the global variable.
  1449. //! \return A negative value on error, or the global variable index.
  1450. //! \retval asERROR The module was not built successfully.
  1451. //! \retval asNO_GLOBAL_VAR The matching global variable was found.
  1452. //!
  1453. //! This method should be used to retrieve the index of the script variable that you wish to access.
  1454. virtual int GetGlobalVarIndexByName(const char *name) = 0;
  1455. //! \brief Returns the global variable index by declaration.
  1456. //! \param[in] decl The global variable declaration.
  1457. //! \return A negative value on error, or the global variable index.
  1458. //! \retval asERROR The module was not built successfully.
  1459. //! \retval asNO_GLOBAL_VAR The matching global variable was found.
  1460. //!
  1461. //! This method should be used to retrieve the index of the script variable that you wish to access.
  1462. //!
  1463. //! The method will find the script variable with the exact same declaration.
  1464. virtual int GetGlobalVarIndexByDecl(const char *decl) = 0;
  1465. //! \brief Returns the global variable declaration.
  1466. //! \param[in] index The index of the global variable.
  1467. //! \return A null terminated string with the variable declaration, or null if not found.
  1468. //!
  1469. //! This method can be used to retrieve the variable declaration of the script variables
  1470. //! that the host application will access. Verifying the declaration is important because,
  1471. //! even though the script may compile correctly the user may not have used the variable
  1472. //! types as intended.
  1473. virtual const char *GetGlobalVarDeclaration(int index) = 0;
  1474. //! \brief Returns the global variable name.
  1475. //! \param[in] index The index of the global variable.
  1476. //! \return A null terminated string with the variable name, or null if not found.
  1477. virtual const char *GetGlobalVarName(int index) = 0;
  1478. //! \brief Returns the type id for the global variable.
  1479. //! \param[in] index The index of the global variable.
  1480. //! \param[out] isConst Receives the constness indicator of the variable.
  1481. //! \return The type id of the global variable, or a negative value on error.
  1482. //! \retval asINVALID_ARG The index is out of range.
  1483. virtual int GetGlobalVarTypeId(int index, bool *isConst = 0) = 0;
  1484. //! \brief Returns the pointer to the global variable.
  1485. //! \param[in] index The index of the global variable.
  1486. //! \return A pointer to the global variable, or null if not found.
  1487. //!
  1488. //! This method should be used to retrieve the pointer of a variable that you wish to access.
  1489. virtual void *GetAddressOfGlobalVar(int index) = 0;
  1490. //! \brief Remove the global variable from the scope of the module.
  1491. //! \param[in] index The index of the global variable.
  1492. //! \return A negative value on error.
  1493. //! \retval asINVALID_ARG The index is out of range.
  1494. //!
  1495. //! The global variable is removed from the scope of the module, but
  1496. //! it is not destroyed until all functions that access it are freed.
  1497. virtual int RemoveGlobalVar(int index) = 0;
  1498. //! \}
  1499. // Type identification
  1500. //! \name Type identification
  1501. //! \{
  1502. //! \brief Returns the number of object types.
  1503. //! \return The number of object types declared in the module.
  1504. virtual int GetObjectTypeCount() = 0;
  1505. //! \brief Returns the object type interface by index.
  1506. //! \param[in] index The index of the type.
  1507. //! \return The object type interface for the type, or null if not found.
  1508. virtual asIObjectType *GetObjectTypeByIndex(asUINT index) = 0;
  1509. //! \brief Returns a type id by declaration.
  1510. //! \param[in] decl The declaration of the type.
  1511. //! \return A negative value on error, or the type id of the type.
  1512. //! \retval asINVALID_TYPE \a decl is not a valid type.
  1513. //!
  1514. //! Translates a type declaration into a type id. The returned type id is valid for as long as
  1515. //! the type is valid, so you can safely store it for later use to avoid potential overhead by
  1516. //! calling this function each time. Just remember to update the type id, any time the type is
  1517. //! changed within the engine, e.g. when recompiling script declared classes, or changing the
  1518. //! engine configuration.
  1519. //!
  1520. //! The type id is based on a sequence number and depends on the order in which the type ids are
  1521. //! queried, thus is not guaranteed to always be the same for each execution of the application.
  1522. //! The \ref asETypeIdFlags can be used to obtain some information about the type directly from the id.
  1523. //!
  1524. //! A base type yields the same type id whether the declaration is const or not, however if the
  1525. //! const is for the subtype then the type id is different, e.g. string@ isn't the same as const
  1526. //! string@ but string is the same as const string.
  1527. virtual int GetTypeIdByDecl(const char *decl) = 0;
  1528. //! \}
  1529. // Enums
  1530. //! \name Enums
  1531. //! \{
  1532. //! \brief Returns the number of enum types declared in the module.
  1533. //! \return The number of enum types in the module.
  1534. virtual int GetEnumCount() = 0;
  1535. //! \brief Returns the enum type.
  1536. //! \param[in] index The index of the enum type.
  1537. //! \param[out] enumTypeId Receives the type id of the enum type.
  1538. //! \return The name of the enum type, or null on error.
  1539. virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId) = 0;
  1540. //! \brief Returns the number of values defined for the enum type.
  1541. //! \param[in] enumTypeId The type id of the enum type.
  1542. //! \return The number of enum values or a negative value on error.
  1543. //! \retval asINVALID_ARG \a enumTypeId is not an enum type.
  1544. virtual int GetEnumValueCount(int enumTypeId) = 0;
  1545. //! \brief Returns the name and value of the enum value.
  1546. //! \param[in] enumTypeId The type id of the enum type.
  1547. //! \param[in] index The index of the enum value.
  1548. //! \param[out] outValue Receives the numeric value.
  1549. //! \return The name of the enum value.
  1550. virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) = 0;
  1551. //! \}
  1552. // Typedefs
  1553. //! \name Typedefs
  1554. //! \{
  1555. //! \brief Returns the number of typedefs in the module.
  1556. //! \return The number of typedefs in the module.
  1557. virtual int GetTypedefCount() = 0;
  1558. //! \brief Returns the typedef.
  1559. //! \param[in] index The index of the typedef.
  1560. //! \param[out] typeId The type that the typedef aliases.
  1561. //! \return The name of the typedef.
  1562. virtual const char *GetTypedefByIndex(asUINT index, int *typeId) = 0;
  1563. //! \}
  1564. // Dynamic binding between modules
  1565. //! \name Dynamic binding between modules
  1566. //! \{
  1567. //! \brief Returns the number of functions declared for import.
  1568. //! \return A negative value on error, or the number of imported functions.
  1569. //! \retval asERROR The module was not built successfully.
  1570. //!
  1571. //! This function returns the number of functions that are imported in a module. These
  1572. //! functions need to be bound before they can be used, or a script exception will be thrown.
  1573. virtual int GetImportedFunctionCount() = 0;
  1574. //! \brief Returns the imported function index by declaration.
  1575. //! \param[in] decl The function declaration of the imported function.
  1576. //! \return A negative value on error, or the index of the imported function.
  1577. //! \retval asERROR The module was not built successfully.
  1578. //! \retval asMULTIPLE_FUNCTIONS Found multiple matching functions.
  1579. //! \retval asNO_FUNCTION Didn't find any matching function.
  1580. //!
  1581. //! This function is used to find a specific imported function by its declaration.
  1582. virtual int GetImportedFunctionIndexByDecl(const char *decl) = 0;
  1583. //! \brief Returns the imported function declaration.
  1584. //! \param[in] importIndex The index of the imported function.
  1585. //! \return A null terminated string with the function declaration, or null if not found.
  1586. //!
  1587. //! Use this function to get the declaration of the imported function. The returned
  1588. //! declaration can be used to find a matching function in another module that can be bound
  1589. //! to the imported function.
  1590. virtual const char *GetImportedFunctionDeclaration(int importIndex) = 0;
  1591. //! \brief Returns the declared imported function source module.
  1592. //! \param[in] importIndex The index of the imported function.
  1593. //! \return A null terminated string with the name of the source module, or null if not found.
  1594. //!
  1595. //! Use this function to get the name of the suggested module to import the function from.
  1596. virtual const char *GetImportedFunctionSourceModule(int importIndex) = 0;
  1597. //! \brief Binds an imported function to the function from another module.
  1598. //! \param[in] importIndex The index of the imported function.
  1599. //! \param[in] funcId The function id of the function that will be bound to the imported function.
  1600. //! \return A negative value on error.
  1601. //! \retval asNO_FUNCTION \a importIndex or \a fundId is incorrect.
  1602. //! \retval asINVALID_INTERFACE The signature of function doesn't match the import statement.
  1603. //!
  1604. //! The imported function is only bound if the functions have the exact same signature,
  1605. //! i.e the same return type, and parameters.
  1606. virtual int BindImportedFunction(int importIndex, int funcId) = 0;
  1607. //! \brief Unbinds an imported function.
  1608. //! \param[in] importIndex The index of the imported function.
  1609. //! \return A negative value on error.
  1610. //! \retval asINVALID_ARG The index is not valid.
  1611. //!
  1612. //! Unbinds the imported function.
  1613. virtual int UnbindImportedFunction(int importIndex) = 0;
  1614. //! \brief Binds all imported functions in a module, by searching their equivalents in the declared source modules.
  1615. //! \return A negative value on error.
  1616. //! \retval asERROR An error occurred.
  1617. //! \retval asCANT_BIND_ALL_FUNCTIONS Not all functions where bound.
  1618. //!
  1619. //! This functions tries to bind all imported functions in the module by searching for matching
  1620. //! functions in the suggested modules. If a function cannot be bound the function will give an
  1621. //! error \ref asCANT_BIND_ALL_FUNCTIONS, but it will continue binding the rest of the functions.
  1622. virtual int BindAllImportedFunctions() = 0;
  1623. //! \brief Unbinds all imported functions.
  1624. //! \return A negative value on error.
  1625. //!
  1626. //! Unbinds all imported functions in the module.
  1627. virtual int UnbindAllImportedFunctions() = 0;
  1628. //! \}
  1629. // Bytecode saving and loading
  1630. //! \name Bytecode saving and loading
  1631. //! \{
  1632. //! \brief Save compiled bytecode to a binary stream.
  1633. //! \param[in] out The output stream.
  1634. //! \return A negative value on error.
  1635. //! \retval asINVALID_ARG The stream object wasn't specified.
  1636. //!
  1637. //! This method is used to save pre-compiled byte code to disk or memory, for a later restoral.
  1638. //! The application must implement an object that inherits from \ref asIBinaryStream to provide
  1639. //! the necessary stream operations.
  1640. //!
  1641. //! The pre-compiled byte code is currently not platform independent, so you need to make
  1642. //! sure the byte code is compiled on a platform that is compatible with the one that will load it.
  1643. virtual int SaveByteCode(asIBinaryStream *out) = 0;
  1644. //! \brief Load pre-compiled bytecode from a binary stream.
  1645. //!
  1646. //! \param[in] in The input stream.
  1647. //! \return A negative value on error.
  1648. //! \retval asINVALID_ARG The stream object wasn't specified.
  1649. //! \retval asBUILD_IN_PROGRESS Another thread is currently building.
  1650. //!
  1651. //! This method is used to load pre-compiled byte code from disk or memory. The application must
  1652. //! implement an object that inherits from \ref asIBinaryStream to provide the necessary stream operations.
  1653. //!
  1654. //! It is expected that the application performs the necessary validations to make sure the
  1655. //! pre-compiled byte code is from a trusted source. The application should also make sure the
  1656. //! pre-compiled byte code is compatible with the current engine configuration, i.e. that the
  1657. //! engine has been configured in the same way as when the byte code was first compiled.
  1658. virtual int LoadByteCode(asIBinaryStream *in) = 0;
  1659. //! \}
  1660. protected:
  1661. virtual ~asIScriptModule() {}
  1662. };
  1663. //! \brief The interface to the virtual machine
  1664. class asIScriptContext
  1665. {
  1666. public:
  1667. // Memory management
  1668. //! \name Memory management
  1669. //! \{
  1670. //! \brief Increase reference counter.
  1671. //!
  1672. //! \return The number of references to this object.
  1673. //!
  1674. //! Call this method when storing an additional reference to the object.
  1675. //! Remember that the first reference that is received from \ref asIScriptEngine::CreateContext
  1676. //! is already accounted for.
  1677. virtual int AddRef() = 0;
  1678. //! \brief Decrease reference counter.
  1679. //!
  1680. //! \return The number of references to this object.
  1681. //!
  1682. //! Call this method when you will no longer use the references that you own.
  1683. virtual int Release() = 0;
  1684. //! \}
  1685. // Miscellaneous
  1686. //! \name Miscellaneous
  1687. //! \{
  1688. //! \brief Returns a pointer to the engine.
  1689. //! \return A pointer to the engine.
  1690. virtual asIScriptEngine *GetEngine() = 0;
  1691. //! \}
  1692. // Execution
  1693. //! \name Execution
  1694. //! \{
  1695. //! \brief Prepares the context for execution of the function identified by funcId.
  1696. //! \param[in] funcId The id of the function/method that will be executed.
  1697. //! \return A negative value on error.
  1698. //! \retval asCONTEXT_ACTIVE The context is still active or suspended.
  1699. //! \retval asNO_FUNCTION The function id doesn't exist.
  1700. //!
  1701. //! This method prepares the context for execution of a script function. It allocates
  1702. //! the stack space required and reserves space for return value and parameters. The
  1703. //! default value for parameters and return value is 0.
  1704. //!
  1705. //! \see \ref doc_call_script_func
  1706. virtual int Prepare(int funcId) = 0;
  1707. //! \brief Frees resources held by the context.
  1708. //! \return A negative value on error.
  1709. //! \retval asCONTEXT_ACTIVE The context is still active or suspended.
  1710. //!
  1711. //! This function frees resources held by the context. It's usually not necessary
  1712. //! to call this function as the resources are automatically freed when the context
  1713. //! is released, or reused when \ref Prepare is called again.
  1714. virtual int Unprepare() = 0;
  1715. //! \brief Sets the object for a class method call.
  1716. //! \param[in] obj A pointer to the object.
  1717. //! \return A negative value on error.
  1718. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1719. //! \retval asERROR The prepared function is not a class method.
  1720. //!
  1721. //! This method sets object pointer when calling class methods.
  1722. virtual int SetObject(void *obj) = 0;
  1723. //! \brief Executes the prepared function.
  1724. //! \return A negative value on error, or one of \ref asEContextState.
  1725. //! \retval asERROR Invalid context object, the context is not prepared, or it is not in suspended state.
  1726. //! \retval asEXECUTION_ABORTED The execution was aborted with a call to \ref Abort.
  1727. //! \retval asEXECUTION_SUSPENDED The execution was suspended with a call to \ref Suspend.
  1728. //! \retval asEXECUTION_FINISHED The execution finished successfully.
  1729. //! \retval asEXECUTION_EXCEPTION The execution ended with an exception.
  1730. //!
  1731. //! Executes the prepared function until the script returns. If the execution was previously
  1732. //! suspended the function resumes where it left of.
  1733. //!
  1734. //! Note that if the script freezes, e.g. if trapped in a never ending loop, you may call
  1735. //! \ref Abort from another thread to stop execution.
  1736. //!
  1737. //! \see \ref doc_call_script_func
  1738. virtual int Execute() = 0;
  1739. //! \brief Aborts the execution.
  1740. //! \return A negative value on error.
  1741. //! \retval asERROR Invalid context object.
  1742. //!
  1743. //! Aborts the current execution of a script.
  1744. virtual int Abort() = 0;
  1745. //! \brief Suspends the execution, which can then be resumed by calling Execute again.
  1746. //! \return A negative value on error.
  1747. //! \retval asERROR Invalid context object.
  1748. //!
  1749. //! Suspends the current execution of a script. The execution can then be resumed by calling \ref Execute again.
  1750. //!
  1751. //! \see \ref doc_call_script_func
  1752. virtual int Suspend() = 0;
  1753. //! \brief Returns the state of the context.
  1754. //! \return The current state of the context.
  1755. virtual asEContextState GetState() = 0;
  1756. //! \}
  1757. // Arguments
  1758. //! \name Arguments
  1759. //! \{
  1760. //! \brief Sets an 8-bit argument value.
  1761. //! \param[in] arg The argument index.
  1762. //! \param[in] value The value of the argument.
  1763. //! \return A negative value on error.
  1764. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1765. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1766. //! \retval asINVALID_TYPE The argument is not an 8-bit value.
  1767. //!
  1768. //! Sets a 1 byte argument.
  1769. virtual int SetArgByte(asUINT arg, asBYTE value) = 0;
  1770. //! \brief Sets a 16-bit argument value.
  1771. //! \param[in] arg The argument index.
  1772. //! \param[in] value The value of the argument.
  1773. //! \return A negative value on error.
  1774. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1775. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1776. //! \retval asINVALID_TYPE The argument is not a 16-bit value.
  1777. //!
  1778. //! Sets a 2 byte argument.
  1779. virtual int SetArgWord(asUINT arg, asWORD value) = 0;
  1780. //! \brief Sets a 32-bit integer argument value.
  1781. //! \param[in] arg The argument index.
  1782. //! \param[in] value The value of the argument.
  1783. //! \return A negative value on error.
  1784. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1785. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1786. //! \retval asINVALID_TYPE The argument is not a 32-bit value.
  1787. //!
  1788. //! Sets a 4 byte argument.
  1789. virtual int SetArgDWord(asUINT arg, asDWORD value) = 0;
  1790. //! \brief Sets a 64-bit integer argument value.
  1791. //! \param[in] arg The argument index.
  1792. //! \param[in] value The value of the argument.
  1793. //! \return A negative value on error.
  1794. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1795. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1796. //! \retval asINVALID_TYPE The argument is not a 64-bit value.
  1797. //!
  1798. //! Sets an 8 byte argument.
  1799. virtual int SetArgQWord(asUINT arg, asQWORD value) = 0;
  1800. //! \brief Sets a float argument value.
  1801. //! \param[in] arg The argument index.
  1802. //! \param[in] value The value of the argument.
  1803. //! \return A negative value on error.
  1804. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1805. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1806. //! \retval asINVALID_TYPE The argument is not a 32-bit value.
  1807. //!
  1808. //! Sets a float argument.
  1809. virtual int SetArgFloat(asUINT arg, float value) = 0;
  1810. //! \brief Sets a double argument value.
  1811. //! \param[in] arg The argument index.
  1812. //! \param[in] value The value of the argument.
  1813. //! \return A negative value on error.
  1814. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1815. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1816. //! \retval asINVALID_TYPE The argument is not a 64-bit value.
  1817. //!
  1818. //! Sets a double argument.
  1819. virtual int SetArgDouble(asUINT arg, double value) = 0;
  1820. //! \brief Sets the address of a reference or handle argument.
  1821. //! \param[in] arg The argument index.
  1822. //! \param[in] addr The address that should be passed in the argument.
  1823. //! \return A negative value on error.
  1824. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1825. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1826. //! \retval asINVALID_TYPE The argument is not a reference or an object handle.
  1827. //!
  1828. //! Sets an address argument, e.g. an object handle or a reference.
  1829. virtual int SetArgAddress(asUINT arg, void *addr) = 0;
  1830. //! \brief Sets the object argument value.
  1831. //! \param[in] arg The argument index.
  1832. //! \param[in] obj A pointer to the object.
  1833. //! \return A negative value on error.
  1834. //! \retval asCONTEXT_NOT_PREPARED The context is not in prepared state.
  1835. //! \retval asINVALID_ARG The \a arg is larger than the number of arguments in the prepared function.
  1836. //! \retval asINVALID_TYPE The argument is not an object or handle.
  1837. //!
  1838. //! Sets an object argument. If the argument is an object handle AngelScript will increment the reference
  1839. //! for the object. If the argument is an object value AngelScript will make a copy of the object.
  1840. virtual int SetArgObject(asUINT arg, void *obj) = 0;
  1841. //! \brief Returns a pointer to the argument for assignment.
  1842. //! \param[in] arg The argument index.
  1843. //! \return A pointer to the argument on the stack.
  1844. //!
  1845. //! This method returns a pointer to the argument on the stack for assignment. For object handles, you
  1846. //! should increment the reference counter. For object values, you should pass a pointer to a copy of the
  1847. //! object.
  1848. virtual void *GetAddressOfArg(asUINT arg) = 0;
  1849. //! \}
  1850. // Return value
  1851. //! \name Return value
  1852. //! \{
  1853. //! \brief Returns the 8-bit return value.
  1854. //! \return The 1 byte value returned from the script function, or 0 on error.
  1855. virtual asBYTE GetReturnByte() = 0;
  1856. //! \brief Returns the 16-bit return value.
  1857. //! \return The 2 byte value returned from the script function, or 0 on error.
  1858. virtual asWORD GetReturnWord() = 0;
  1859. //! \brief Returns the 32-bit return value.
  1860. //! \return The 4 byte value returned from the script function, or 0 on error.
  1861. virtual asDWORD GetReturnDWord() = 0;
  1862. //! \brief Returns the 64-bit return value.
  1863. //! \return The 8 byte value returned from the script function, or 0 on error.
  1864. virtual asQWORD GetReturnQWord() = 0;
  1865. //! \brief Returns the float return value.
  1866. //! \return The float value returned from the script function, or 0 on error.
  1867. virtual float GetReturnFloat() = 0;
  1868. //! \brief Returns the double return value.
  1869. //! \return The double value returned from the script function, or 0 on error.
  1870. virtual double GetReturnDouble() = 0;
  1871. //! \brief Returns the address for a reference or handle return type.
  1872. //! \return The address value returned from the script function, or 0 on error.
  1873. //!
  1874. //! The method doesn't increase the reference counter with this call, so if you store
  1875. //! the pointer of a reference counted object you need to increase the reference manually
  1876. //! otherwise the object will be released when the context is released or reused.
  1877. virtual void *GetReturnAddress() = 0;
  1878. //! \brief Return a pointer to the returned object.
  1879. //! \return A pointer to the object returned from the script function, or 0 on error.
  1880. //!
  1881. //! The method doesn't increase the reference counter with this call, so if you store
  1882. //! the pointer of a reference counted object you need to increase the reference manually
  1883. //! otherwise the object will be released when the context is released or reused.
  1884. virtual void *GetReturnObject() = 0;
  1885. //! \brief Returns the address of the returned value
  1886. //! \return A pointer to the return value returned from the script function, or 0 on error.
  1887. virtual void *GetAddressOfReturnValue() = 0;
  1888. //! \}
  1889. // Exception handling
  1890. //! \name Exception handling
  1891. //! \{
  1892. //! \brief Sets an exception, which aborts the execution.
  1893. //! \param[in] string A string that describes the exception that occurred.
  1894. //! \return A negative value on error.
  1895. //! \retval asERROR The context isn't currently calling an application registered function.
  1896. //!
  1897. //! This method sets a script exception in the context. This will only work if the
  1898. //! context is currently calling a system function, thus this method can only be
  1899. //! used for system functions.
  1900. //!
  1901. //! Note that if your system function sets an exception, it should not return any
  1902. //! object references because the engine will not release the returned reference.
  1903. virtual int SetException(const char *string) = 0;
  1904. //! \brief Returns the line number where the exception occurred.
  1905. //! \param[out] column The variable will receive the column number.
  1906. //! \return The line number where the exception occurred.
  1907. //!
  1908. //! This method returns the line number where the exception ocurred. The line number
  1909. //! is relative to the script section where the function was implemented.
  1910. virtual int GetExceptionLineNumber(int *column = 0) = 0;
  1911. //! \brief Returns the function id of the function where the exception occurred.
  1912. //! \return The function id where the exception occurred.
  1913. virtual int GetExceptionFunction() = 0;
  1914. //! \brief Returns the exception string text.
  1915. //! \return A null terminated string describing the exception that occurred.
  1916. virtual const char *GetExceptionString() = 0;
  1917. //! \brief Sets an exception callback function. The function will be called if a script exception occurs.
  1918. //! \param[in] callback The callback function/method that should be called upon an exception.
  1919. //! \param[in] obj The object pointer on which the callback is called.
  1920. //! \param[in] callConv The calling convention of the callback function/method.
  1921. //! \return A negative value on error.
  1922. //! \retval asNOT_SUPPORTED Calling convention must not be asCALL_GENERIC, or the routine's calling convention is not supported.
  1923. //! \retval asINVALID_ARG \a obj must not be null for class methods.
  1924. //! \retval asWRONG_CALLING_CONV \a callConv isn't compatible with the routines' calling convention.
  1925. //!
  1926. //! This callback function will be called by the VM when a script exception is raised, which
  1927. //! allow the application to examine the callstack and generate a detailed report before the
  1928. //! callstack is cleaned up.
  1929. //!
  1930. //! See \ref SetLineCallback for details on the calling convention.
  1931. virtual int SetExceptionCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
  1932. //! \brief Removes a previously registered callback.
  1933. //! Removes a previously registered callback.
  1934. virtual void ClearExceptionCallback() = 0;
  1935. //! \}
  1936. // Debugging
  1937. //! \name Debugging
  1938. //! \{
  1939. //! \brief Sets a line callback function. The function will be called for each executed script statement.
  1940. //! \param[in] callback The callback function/method that should be called for each script line executed.
  1941. //! \param[in] obj The object pointer on which the callback is called.
  1942. //! \param[in] callConv The calling convention of the callback function/method.
  1943. //! \return A negative value on error.
  1944. //! \retval asNOT_SUPPORTED Calling convention must not be asCALL_GENERIC, or the routine's calling convention is not supported.
  1945. //! \retval asINVALID_ARG \a obj must not be null for class methods.
  1946. //! \retval asWRONG_CALLING_CONV \a callConv isn't compatible with the routines' calling convention.
  1947. //!
  1948. //! This function sets a callback function that will be called by the VM each time the SUSPEND
  1949. //! instruction is encounted. Generally this instruction is placed before each statement. Thus by
  1950. //! setting this callback function it is possible to monitor the execution, and suspend the execution
  1951. //! at application defined locations.
  1952. //!
  1953. //! The callback function can be either a global function or a class method. For a global function
  1954. //! the VM will pass two parameters, first the context pointer and then the object pointer specified
  1955. //! by the application. For a class method, the VM will call the method using the object pointer
  1956. //! as the owner.
  1957. //!
  1958. //! \code
  1959. //! void Callback(asIScriptContext *ctx, void *obj);
  1960. //! void Object::Callback(asIScriptContext *ctx);
  1961. //! \endcode
  1962. //!
  1963. //! The global function can use either \ref asCALL_CDECL or \ref asCALL_STDCALL, and the class method can use either
  1964. //! \ref asCALL_THISCALL, \ref asCALL_CDECL_OBJLAST, or \ref asCALL_CDECL_OBJFIRST.
  1965. //!
  1966. //! \see \ref doc_debug
  1967. virtual int SetLineCallback(asSFuncPtr callback, void *obj, int callConv) = 0;
  1968. //! \brief Removes a previously registered callback.
  1969. //! Removes a previously registered callback.
  1970. virtual void ClearLineCallback() = 0;
  1971. //! \brief Get the current line number that is being executed.
  1972. //! \param[out] column The variable will receive the column number.
  1973. //! \return The current line number.
  1974. //!
  1975. //! This method returns the line number where the context is currently located.
  1976. //! The line number is relative to the script section where the function was implemented.
  1977. virtual int GetCurrentLineNumber(int *column = 0) = 0;
  1978. //! \brief Get the current function that is being executed.
  1979. //! \return The function id of the current function.
  1980. virtual int GetCurrentFunction() = 0;
  1981. //! \brief Returns the size of the callstack, i.e. the number of functions that have yet to complete.
  1982. //! \return The number of functions on the call stack.
  1983. //!
  1984. //! This methods returns the size of the callstack, i.e. how many parent functions there are
  1985. //! above the current functions being called. It can be used to enumerate the callstack in order
  1986. //! to generate a detailed report when an exception occurs, or for debugging running scripts.
  1987. virtual int GetCallstackSize() = 0;
  1988. //! \brief Returns the function id at the specified callstack level.
  1989. //! \param[in] index The index on the call stack.
  1990. //! \return The function id on the call stack referred to by the index.
  1991. virtual int GetCallstackFunction(int index) = 0;
  1992. //! \brief Returns the line number at the specified callstack level.
  1993. //! \param[in] index The index on the call stack.
  1994. //! \param[out] column The variable will receive the column number.
  1995. //! \return The line number for the call stack level referred to by the index.
  1996. virtual int GetCallstackLineNumber(int index, int *column = 0) = 0;
  1997. //! \brief Returns the number of local variables at the specified callstack level.
  1998. //! \param[in] stackLevel The index on the call stack.
  1999. //! \return The number of variables in the function on the call stack level.
  2000. //!
  2001. //! Returns the number of declared variables, including the parameters, in the function on the stack.
  2002. virtual int GetVarCount(int stackLevel = -1) = 0;
  2003. //! \brief Returns the name of local variable at the specified callstack level.
  2004. //! \param[in] varIndex The index of the variable.
  2005. //! \param[in] stackLevel The index on the call stack.
  2006. //! \return A null terminated string with the name of the variable.
  2007. virtual const char *GetVarName(int varIndex, int stackLevel = -1) = 0;
  2008. //! \brief Returns the declaration of a local variable at the specified callstack level.
  2009. //! \param[in] varIndex The index of the variable.
  2010. //! \param[in] stackLevel The index on the call stack.
  2011. //! \return A null terminated string with the declaration of the variable.
  2012. virtual const char *GetVarDeclaration(int varIndex, int stackLevel = -1) = 0;
  2013. //! \brief Returns the type id of a local variable at the specified callstack level.
  2014. //! \param[in] varIndex The index of the variable.
  2015. //! \param[in] stackLevel The index on the call stack.
  2016. //! \return The type id of the variable, or a negative value on error.
  2017. //! \retval asINVALID_ARG The index or stack level is invalid.
  2018. virtual int GetVarTypeId(int varIndex, int stackLevel = -1) = 0;
  2019. //! \brief Returns a pointer to a local variable at the specified callstack level.
  2020. //! \param[in] varIndex The index of the variable.
  2021. //! \param[in] stackLevel The index on the call stack.
  2022. //! \return A pointer to the variable.
  2023. //!
  2024. //! Returns a pointer to the variable, so that its value can be read and written. The
  2025. //! address is valid until the script function returns.
  2026. //!
  2027. //! Note that object variables may not be initalized at all moments, thus you must verify
  2028. //! if the address returned points to a null pointer, before you try to dereference it.
  2029. virtual void *GetAddressOfVar(int varIndex, int stackLevel = -1) = 0;
  2030. //! \brief Returns the type id of the object, if a class method is being executed.
  2031. //! \param[in] stackLevel The index on the call stack.
  2032. //! \return Returns the type id of the object if it is a class method.
  2033. virtual int GetThisTypeId(int stackLevel = -1) = 0;
  2034. //! \brief Returns a pointer to the object, if a class method is being executed.
  2035. //! \param[in] stackLevel The index on the call stack.
  2036. //! \return Returns a pointer to the object if it is a class method.
  2037. virtual void *GetThisPointer(int stackLevel = -1) = 0;
  2038. //! \}
  2039. // User data
  2040. //! \name User data
  2041. //! \{
  2042. //! \brief Register the memory address of some user data.
  2043. //! \param[in] data A pointer to the user data.
  2044. //! \return The previous pointer stored in the context.
  2045. //!
  2046. //! This method allows the application to associate a value, e.g. a pointer, with the context instance.
  2047. virtual void *SetUserData(void *data) = 0;
  2048. //! \brief Returns the address of the previously registered user data.
  2049. //! \return The pointer to the user data.
  2050. virtual void *GetUserData() = 0;
  2051. //! \}
  2052. protected:
  2053. virtual ~asIScriptContext() {}
  2054. };
  2055. //! \brief The interface for the generic calling convention
  2056. class asIScriptGeneric
  2057. {
  2058. public:
  2059. // Miscellaneous
  2060. //! \name Miscellaneous
  2061. //! \{
  2062. //! \brief Returns a pointer to the script engine.
  2063. //! \return A pointer to the engine.
  2064. virtual asIScriptEngine *GetEngine() = 0;
  2065. //! \brief Returns the function id of the called function.
  2066. //! \return The function id of the function being called.
  2067. virtual int GetFunctionId() = 0;
  2068. //! \}
  2069. // Object
  2070. //! \name Object
  2071. //! \{
  2072. //! \brief Returns the object pointer if this is a class method, or null if it not.
  2073. //! \return A pointer to the object, if this is a method.
  2074. virtual void *GetObject() = 0;
  2075. //! \brief Returns the type id of the object if this is a class method.
  2076. //! \return The type id of the object if this is a method.
  2077. virtual int GetObjectTypeId() = 0;
  2078. //! \}
  2079. // Arguments
  2080. //! \name Arguments
  2081. //! \{
  2082. //! \brief Returns the number of arguments.
  2083. //! \return The number of arguments to the function.
  2084. virtual int GetArgCount() = 0;
  2085. //! \brief Returns the type id of the argument.
  2086. //! \param[in] arg The argument index.
  2087. //! \return The type id of the argument.
  2088. virtual int GetArgTypeId(asUINT arg) = 0;
  2089. //! \brief Returns the value of an 8-bit argument.
  2090. //! \param[in] arg The argument index.
  2091. //! \return The 1 byte argument value.
  2092. virtual asBYTE GetArgByte(asUINT arg) = 0;
  2093. //! \brief Returns the value of a 16-bit argument.
  2094. //! \param[in] arg The argument index.
  2095. //! \return The 2 byte argument value.
  2096. virtual asWORD GetArgWord(asUINT arg) = 0;
  2097. //! \brief Returns the value of a 32-bit integer argument.
  2098. //! \param[in] arg The argument index.
  2099. //! \return The 4 byte argument value.
  2100. virtual asDWORD GetArgDWord(asUINT arg) = 0;
  2101. //! \brief Returns the value of a 64-bit integer argument.
  2102. //! \param[in] arg The argument index.
  2103. //! \return The 8 byte argument value.
  2104. virtual asQWORD GetArgQWord(asUINT arg) = 0;
  2105. //! \brief Returns the value of a float argument.
  2106. //! \param[in] arg The argument index.
  2107. //! \return The float argument value.
  2108. virtual float GetArgFloat(asUINT arg) = 0;
  2109. //! \brief Returns the value of a double argument.
  2110. //! \param[in] arg The argument index.
  2111. //! \return The double argument value.
  2112. virtual double GetArgDouble(asUINT arg) = 0;
  2113. //! \brief Returns the address held in a reference or handle argument.
  2114. //! \param[in] arg The argument index.
  2115. //! \return The address argument value, which can be a reference or and object handle.
  2116. //!
  2117. //! Don't release the pointer if this is an object or object handle, the asIScriptGeneric object will
  2118. //! do that for you.
  2119. virtual void *GetArgAddress(asUINT arg) = 0;
  2120. //! \brief Returns a pointer to the object in a object argument.
  2121. //! \param[in] arg The argument index.
  2122. //! \return A pointer to the object argument, which can be an object value or object handle.
  2123. //!
  2124. //! Don't release the pointer if this is an object handle, the asIScriptGeneric object will
  2125. //! do that for you.
  2126. virtual void *GetArgObject(asUINT arg) = 0;
  2127. //! \brief Returns a pointer to the argument value.
  2128. //! \param[in] arg The argument index.
  2129. //! \return A pointer to the argument value.
  2130. virtual void *GetAddressOfArg(asUINT arg) = 0;
  2131. //! \}
  2132. // Return value
  2133. //! \name Return value
  2134. //! \{
  2135. //! \brief Gets the type id of the return value.
  2136. //! \return The type id of the return value.
  2137. virtual int GetReturnTypeId() = 0;
  2138. //! \brief Sets the 8-bit return value.
  2139. //! \param[in] val The return value.
  2140. //! \return A negative value on error.
  2141. //! \retval asINVALID_TYPE The return type is not an 8-bit value.
  2142. //! Sets the 1 byte return value.
  2143. virtual int SetReturnByte(asBYTE val) = 0;
  2144. //! \brief Sets the 16-bit return value.
  2145. //! \param[in] val The return value.
  2146. //! \return A negative value on error.
  2147. //! \retval asINVALID_TYPE The return type is not a 16-bit value.
  2148. //! Sets the 2 byte return value.
  2149. virtual int SetReturnWord(asWORD val) = 0;
  2150. //! \brief Sets the 32-bit integer return value.
  2151. //! \param[in] val The return value.
  2152. //! \return A negative value on error.
  2153. //! \retval asINVALID_TYPE The return type is not a 32-bit value.
  2154. //! Sets the 4 byte return value.
  2155. virtual int SetReturnDWord(asDWORD val) = 0;
  2156. //! \brief Sets the 64-bit integer return value.
  2157. //! \param[in] val The return value.
  2158. //! \return A negative value on error.
  2159. //! \retval asINVALID_TYPE The return type is not a 64-bit value.
  2160. //! Sets the 8 byte return value.
  2161. virtual int SetReturnQWord(asQWORD val) = 0;
  2162. //! \brief Sets the float return value.
  2163. //! \param[in] val The return value.
  2164. //! \return A negative value on error.
  2165. //! \retval asINVALID_TYPE The return type is not a 32-bit value.
  2166. //! Sets the float return value.
  2167. virtual int SetReturnFloat(float val) = 0;
  2168. //! \brief Sets the double return value.
  2169. //! \param[in] val The return value.
  2170. //! \return A negative value on error.
  2171. //! \retval asINVALID_TYPE The return type is not a 64-bit value.
  2172. //! Sets the double return value.
  2173. virtual int SetReturnDouble(double val) = 0;
  2174. //! \brief Sets the address return value when the return is a reference or handle.
  2175. //! \param[in] addr The return value, which is an address.
  2176. //! \return A negative value on error.
  2177. //! \retval asINVALID_TYPE The return type is not a reference or handle.
  2178. //!
  2179. //! Sets the address return value. If an object handle the application must first
  2180. //! increment the reference counter, unless it won't keep a reference itself.
  2181. virtual int SetReturnAddress(void *addr) = 0;
  2182. //! \brief Sets the object return value.
  2183. //! \param[in] obj A pointer to the object return value.
  2184. //! \return A negative value on error.
  2185. //! \retval asINVALID_TYPE The return type is not an object value or handle.
  2186. //!
  2187. //! If the function returns an object, the library will automatically do what is
  2188. //! necessary based on how the object was declared, i.e. if the function was
  2189. //! registered to return a handle then the library will call the addref behaviour.
  2190. //! If it was registered to return an object by value, then the library will make
  2191. //! a copy of the object.
  2192. virtual int SetReturnObject(void *obj) = 0;
  2193. //! \brief Gets the address to the memory where the return value should be placed.
  2194. //! \return A pointer to the memory where the return values is to be placed.
  2195. //!
  2196. //! The memory is not initialized, so if you're going to return a complex type by value,
  2197. //! you shouldn't use the assignment operator to initialize it. Instead use the placement new
  2198. //! operator to call the type's copy constructor to perform the initialization.
  2199. //!
  2200. //! \code
  2201. //! new(gen->GetAddressOfReturnLocation()) std::string(myRetValue);
  2202. //! \endcode
  2203. //!
  2204. //! The placement new operator works for primitive types too, so this method is ideal
  2205. //! for writing automatically generated functions that works the same way for all types.
  2206. virtual void *GetAddressOfReturnLocation() = 0;
  2207. //! \}
  2208. protected:
  2209. virtual ~asIScriptGeneric() {}
  2210. };
  2211. //! \brief The interface for an instance of a script object
  2212. class asIScriptObject
  2213. {
  2214. public:
  2215. // Memory management
  2216. //! \name Memory management
  2217. //! \{
  2218. //! \brief Increase reference counter.
  2219. //!
  2220. //! \return The number of references to this object.
  2221. //!
  2222. //! Call this method when storing an additional reference to the object.
  2223. virtual int AddRef() = 0;
  2224. //! \brief Decrease reference counter.
  2225. //!
  2226. //! \return The number of references to this object.
  2227. //!
  2228. //! Call this method when you will no longer use the references that you own.
  2229. virtual int Release() = 0;
  2230. //! \}
  2231. // Type info
  2232. //! \name Type info
  2233. //! \{
  2234. //! \brief Returns the type id of the object.
  2235. //! \return The type id of the script object.
  2236. virtual int GetTypeId() const = 0;
  2237. //! \brief Returns the object type interface for the object.
  2238. //! \return The object type interface of the script object.
  2239. virtual asIObjectType *GetObjectType() const = 0;
  2240. //! \}
  2241. // Class properties
  2242. //! \name Properties
  2243. //! \{
  2244. //! \brief Returns the number of properties that the object contains.
  2245. //! \return The number of member properties of the script object.
  2246. virtual int GetPropertyCount() const = 0;
  2247. //! \brief Returns the type id of the property referenced by prop.
  2248. //! \param[in] prop The property index.
  2249. //! \return The type id of the member property, or a negative value on error.
  2250. //! \retval asINVALID_ARG \a prop is too large
  2251. virtual int GetPropertyTypeId(asUINT prop) const = 0;
  2252. //! \brief Returns the name of the property referenced by prop.
  2253. //! \param[in] prop The property index.
  2254. //! \return A null terminated string with the property name.
  2255. virtual const char *GetPropertyName(asUINT prop) const = 0;
  2256. //! \brief Returns a pointer to the property referenced by prop.
  2257. //! \param[in] prop The property index.
  2258. //! \return A pointer to the property value.
  2259. //!
  2260. //! The method returns a pointer to the memory location for the property. Use the type
  2261. //! id for the property to determine the content of the pointer, and how to handle it.
  2262. virtual void *GetAddressOfProperty(asUINT prop) = 0;
  2263. //! \}
  2264. //! \name Miscellaneous
  2265. //! \{
  2266. //! \brief Return the script engine.
  2267. //! \return The script engine.
  2268. virtual asIScriptEngine *GetEngine() const = 0;
  2269. //! \brief Copies the content from another object of the same type.
  2270. //! \param[in] other A pointer to the source object.
  2271. //! \return A negative value on error.
  2272. //! \retval asINVALID_ARG The argument is null.
  2273. //! \retval asINVALID_TYPE The other object is of different type.
  2274. //!
  2275. //! This method copies the contents of the other object to this one.
  2276. virtual int CopyFrom(asIScriptObject *other) = 0;
  2277. //! \}
  2278. protected:
  2279. virtual ~asIScriptObject() {}
  2280. };
  2281. //! \brief The interface for a script array object
  2282. class asIScriptArray
  2283. {
  2284. public:
  2285. //! \brief Return the script engine.
  2286. //! \return The script engine.
  2287. virtual asIScriptEngine *GetEngine() const = 0;
  2288. // Memory management
  2289. //! \brief Increase reference counter.
  2290. //!
  2291. //! \return The number of references to this object.
  2292. //!
  2293. //! Call this method when storing an additional reference to the object.
  2294. virtual int AddRef() = 0;
  2295. //! \brief Decrease reference counter.
  2296. //!
  2297. //! \return The number of references to this object.
  2298. //!
  2299. //! Call this method when you will no longer use the references that you own.
  2300. virtual int Release() = 0;
  2301. // Array type
  2302. //! \brief Returns the type id of the array object.
  2303. //! \return The type id of the array object.
  2304. virtual int GetArrayTypeId() = 0;
  2305. // Elements
  2306. //! \brief Returns the type id of the contained elements.
  2307. //! \return The type id of the array elements.
  2308. virtual int GetElementTypeId() = 0;
  2309. //! \brief Returns the size of the array.
  2310. //! \return The number of elements in the array.
  2311. virtual asUINT GetElementCount() = 0;
  2312. //! \brief Returns a pointer to the element referenced by index.
  2313. //! \param[in] index The element index.
  2314. //! \return A pointer to the element value.
  2315. //!
  2316. //! The method returns a pointer to the memory location for the element. Use the
  2317. //! type id for the element to determine the content of the pointer, and how to handle it.
  2318. virtual void * GetElementPointer(asUINT index) = 0;
  2319. //! \brief Resizes the array.
  2320. //! \param[in] size The new size of the array.
  2321. //!
  2322. //! This method allows the application to resize the array.
  2323. virtual void Resize(asUINT size) = 0;
  2324. //! \brief Copies the elements from another array, overwriting the current content.
  2325. //! \param[in] other A pointer to the source array.
  2326. //! \return A negative value on error.
  2327. //! \retval asINVALID_ARG The argument is null.
  2328. //! \retval asINVALID_TYPE The other array is of different type.
  2329. //!
  2330. //! This method copies the contents of the other object to this one.
  2331. virtual int CopyFrom(asIScriptArray *other) = 0;
  2332. protected:
  2333. virtual ~asIScriptArray() {}
  2334. };
  2335. //! \brief The interface for an object type
  2336. class asIObjectType
  2337. {
  2338. public:
  2339. //! \name Miscellaneous
  2340. //! \{
  2341. //! \brief Returns a pointer to the script engine.
  2342. //! \return A pointer to the engine.
  2343. virtual asIScriptEngine *GetEngine() const = 0;
  2344. //! \brief Returns the config group in which the type was registered.
  2345. //! \return The name of the config group, or null if not set.
  2346. virtual const char *GetConfigGroup() const = 0;
  2347. //! \}
  2348. // Memory management
  2349. //! \name Memory management
  2350. //! \{
  2351. //! \brief Increases the reference counter.
  2352. //!
  2353. //! \return The number of references to this object.
  2354. //!
  2355. //! Call this method when storing an additional reference to the object.
  2356. virtual int AddRef() = 0;
  2357. //! \brief Decrease reference counter.
  2358. //!
  2359. //! \return The number of references to this object.
  2360. //!
  2361. //! Call this method when you will no longer use the references that you own.
  2362. virtual int Release() = 0;
  2363. //! \}
  2364. // Type info
  2365. //! \name Type info
  2366. //! \{
  2367. //! \brief Returns a temporary pointer to the name of the datatype.
  2368. //! \return A null terminated string with the name of the object type.
  2369. virtual const char *GetName() const = 0;
  2370. //! \brief Returns the object type that this type derives from.
  2371. //! \return A pointer to the object type that this type derives from.
  2372. //!
  2373. //! This method will only return a pointer in case of script classes that derives from another script class.
  2374. virtual asIObjectType *GetBaseType() const = 0;
  2375. //! \brief Returns the object type flags.
  2376. //! \return A bit mask with the flags from \ref asEObjTypeFlags.
  2377. //!
  2378. //! Script classes are identified by having the asOBJ_SCRIPT_OBJECT flag set.
  2379. //! Interfaces are identified as a script class with a size of zero.
  2380. //!
  2381. //! \see GetSize
  2382. virtual asDWORD GetFlags() const = 0;
  2383. //! \brief Returns the size of the object type.
  2384. //! \return The number of bytes necessary to store instances of this type.
  2385. //!
  2386. //! Application registered reference types doesn't store this information,
  2387. //! as the script engine doesn't allocate memory for these itself.
  2388. virtual asUINT GetSize() const = 0;
  2389. //! \brief Returns the type id for the object type.
  2390. //! \return The type id for the object type.
  2391. virtual int GetTypeId() const = 0;
  2392. //! \brief Returns the type id of the template sub type.
  2393. //! \return The type id of the template sub type, or a negative value on error.
  2394. //! \retval asERROR The type is not a template type.
  2395. virtual int GetSubTypeId() const = 0;
  2396. //! \}
  2397. // Interfaces
  2398. //! \name Interfaces
  2399. //! \{
  2400. //! \brief Returns the number of interfaces implemented.
  2401. //! \return The number of interfaces implemented by this type.
  2402. virtual int GetInterfaceCount() const = 0;
  2403. //! \brief Returns a temporary pointer to the specified interface or null if none are found.
  2404. //! \param[in] index The interface index.
  2405. //! \return A pointer to the interface type.
  2406. virtual asIObjectType *GetInterface(asUINT index) const = 0;
  2407. //! \}
  2408. // Factories
  2409. //! \name Factories
  2410. //! \{
  2411. //! \brief Returns the number of factory functions for the object type.
  2412. //! \return A negative value on error, or the number of factory functions for this object.
  2413. virtual int GetFactoryCount() const = 0;
  2414. //! \brief Returns the factory id by index.
  2415. //! \param[in] index The index of the factory function.
  2416. //! \return A negative value on error, or the factory id.
  2417. //! \retval asINVALID_ARG \a index is out of bounds.
  2418. virtual int GetFactoryIdByIndex(int index) const = 0;
  2419. //! \brief Returns the factory id by declaration.
  2420. //! \param[in] decl The factory signature.
  2421. //! \return A negative value on error, or the factory id.
  2422. //! \retval asNO_FUNCTION Didn't find any matching functions.
  2423. //! \retval asINVALID_DECLARATION \a decl is not a valid declaration.
  2424. //! \retval asERROR The module for the type was not built successfully.
  2425. //!
  2426. //! The factory function is named after the object type and
  2427. //! returns a handle to the object. Example:
  2428. //!
  2429. //! \code
  2430. //! id = type->GetFactoryIdByDecl("object@ object(int arg1, int arg2)");
  2431. //! \endcode
  2432. virtual int GetFactoryIdByDecl(const char *decl) const = 0;
  2433. //! \}
  2434. // Methods
  2435. //! \name Methods
  2436. //! \{
  2437. //! \brief Returns the number of methods for the object type.
  2438. //! \return A negative value on error, or the number of methods for this object.
  2439. virtual int GetMethodCount() const = 0;
  2440. //! \brief Returns the method id by index.
  2441. //! \param[in] index The index of the method.
  2442. //! \return A negative value on error, or the method id.
  2443. //! \retval asINVALID_ARG \a index is out of bounds.
  2444. //!
  2445. //! This method should be used to retrieve the ID of the script method for the object
  2446. //! that you wish to execute. The ID is then sent to the context's \ref asIScriptContext::Prepare "Prepare" method.
  2447. virtual int GetMethodIdByIndex(int index) const = 0;
  2448. //! \brief Returns the method id by name.
  2449. //! \param[in] name The name of the method.
  2450. //! \return A negative value on error, or the method id.
  2451. //! \retval asMULTIPLE_FUNCTIONS Found multiple matching methods.
  2452. //! \retval asNO_FUNCTION Didn't find any matching method.
  2453. //!
  2454. //! This method should be used to retrieve the ID of the script method for the object
  2455. //! that you wish to execute. The ID is then sent to the context's \ref asIScriptContext::Prepare "Prepare" method.
  2456. virtual int GetMethodIdByName(const char *name) const = 0;
  2457. //! \brief Returns the method id by declaration.
  2458. //! \param[in] decl The method signature.
  2459. //! \return A negative value on error, or the method id.
  2460. //! \retval asMULTIPLE_FUNCTIONS Found multiple matching methods.
  2461. //! \retval asNO_FUNCTION Didn't find any matching method.
  2462. //! \retval asINVALID_DECLARATION \a decl is not a valid declaration.
  2463. //! \retval asERROR The module for the type was not built successfully.
  2464. //!
  2465. //! This method should be used to retrieve the ID of the script method for the object
  2466. //! that you wish to execute. The ID is then sent to the context's \ref asIScriptContext::Prepare "Prepare" method.
  2467. //!
  2468. //! The method will find the script method with the exact same declaration.
  2469. virtual int GetMethodIdByDecl(const char *decl) const = 0;
  2470. //! \brief Returns the function descriptor for the script method
  2471. //! \param[in] index The index of the method.
  2472. //! \return A pointer to the method description interface, or null if not found.
  2473. virtual asIScriptFunction *GetMethodDescriptorByIndex(int index) const = 0;
  2474. //! \}
  2475. // Properties
  2476. //! \name Properties
  2477. //! \{
  2478. //! \brief Returns the number of properties that the object contains.
  2479. //! \return The number of member properties of the script object.
  2480. virtual int GetPropertyCount() const = 0;
  2481. //! \brief Returns the type id of the property referenced by \a prop.
  2482. //! \param[in] prop The property index.
  2483. //! \return The type id of the member property, or a negative value on error.
  2484. //! \retval asINVALID_ARG \a prop is too large
  2485. virtual int GetPropertyTypeId(asUINT prop) const = 0;
  2486. //! \brief Returns the name of the property referenced by \a prop.
  2487. //! \param[in] prop The property index.
  2488. //! \return A null terminated string with the property name.
  2489. virtual const char *GetPropertyName(asUINT prop) const = 0;
  2490. //! \brief Returns the offset of the property in the memory layout.
  2491. //! \param[in] prop The property index.
  2492. //! \return The offset of the property in the memory layout.
  2493. virtual int GetPropertyOffset(asUINT prop) const = 0;
  2494. //! \}
  2495. // Behaviours
  2496. //! \name Behaviours
  2497. //! \{
  2498. //! \brief Returns the number of behaviours.
  2499. //! \return The number of behaviours for this type.
  2500. virtual int GetBehaviourCount() const = 0;
  2501. //! \brief Returns the function id and type of the behaviour.
  2502. //! \param[in] index The index of the behaviour.
  2503. //! \param[out] outBehaviour Receives the type of the behaviour.
  2504. //! \return The function id of the behaviour.
  2505. //! \retval asINVALID_ARG The \a index is too large.
  2506. virtual int GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const = 0;
  2507. //! \}
  2508. protected:
  2509. virtual ~asIObjectType() {}
  2510. };
  2511. //! \brief The interface for a script function description
  2512. class asIScriptFunction
  2513. {
  2514. public:
  2515. //! \name Miscellaneous
  2516. //! \{
  2517. //! \brief Returns a pointer to the script engine.
  2518. //! \return A pointer to the engine.
  2519. virtual asIScriptEngine *GetEngine() const = 0;
  2520. // Memory management
  2521. //! \brief Increases the reference counter.
  2522. //!
  2523. //! \return The number of references to this object.
  2524. //!
  2525. //! Call this method when storing an additional reference to the object.
  2526. virtual int AddRef() = 0;
  2527. //! \brief Decrease reference counter.
  2528. //!
  2529. //! \return The number of references to this object.
  2530. //!
  2531. //! Call this method when you will no longer use the references that you own.
  2532. virtual int Release() = 0;
  2533. //! \brief Returns the id of the function
  2534. //! \return The id of the function
  2535. virtual int GetId() const = 0;
  2536. //! \brief Returns the name of the module where the function was implemented
  2537. //! \return A null terminated string with the module name.
  2538. virtual const char *GetModuleName() const = 0;
  2539. //! \brief Returns the name of the script section where the function was implemented.
  2540. //! \return A null terminated string with the script section name where the function was implemented.
  2541. virtual const char *GetScriptSectionName() const = 0;
  2542. //! \brief Returns the name of the config group in which the function was registered.
  2543. //! \return The name of the config group, or null if not in any group.
  2544. virtual const char *GetConfigGroup() const = 0;
  2545. //! \}
  2546. //! \name Function info
  2547. //! \{
  2548. //! \brief Returns the object type for class or interface method
  2549. //! \return A pointer to the object type interface if this is a method.
  2550. virtual asIObjectType *GetObjectType() const = 0;
  2551. //! \brief Returns the name of the object for class or interface methods
  2552. //! \return A null terminated string with the name of the object type if this a method.
  2553. virtual const char *GetObjectName() const = 0;
  2554. //! \brief Returns the name of the function or method
  2555. //! \return A null terminated string with the name of the function.
  2556. virtual const char *GetName() const = 0;
  2557. //! \brief Returns the function declaration
  2558. //! \param[in] includeObjectName Indicate whether the object name should be prepended to the function name
  2559. //! \return A null terminated string with the function declaration.
  2560. virtual const char *GetDeclaration(bool includeObjectName = true) const = 0;
  2561. //! \brief Returns true if it is a class method
  2562. //! \return True if this a class method.
  2563. virtual bool IsClassMethod() const = 0;
  2564. //! \brief Returns true if it is an interface method
  2565. //! \return True if this is an interface method.
  2566. virtual bool IsInterfaceMethod() const = 0;
  2567. //! \brief Returns true if the class method is read-only
  2568. //! \return True if the class method is read-only
  2569. virtual bool IsReadOnly() const = 0;
  2570. //! \}
  2571. //! \name Parameter and return types
  2572. //! \{
  2573. //! \brief Returns the number of parameters for this function.
  2574. //! \return The number of parameters.
  2575. virtual int GetParamCount() const = 0;
  2576. //! \brief Returns the type id of the specified parameter.
  2577. //! \param[in] index The zero based parameter index.
  2578. //! \param[out] flags A combination of \ref asETypeModifiers.
  2579. //! \return A negative value on error, or the type id of the specified parameter.
  2580. //! \retval asINVALID_ARG The index is out of bounds.
  2581. virtual int GetParamTypeId(int index, asDWORD *flags = 0) const = 0;
  2582. //! \brief Returns the type id of the return type.
  2583. //! \return The type id of the return type.
  2584. virtual int GetReturnTypeId() const = 0;
  2585. //! \}
  2586. //! \name JIT compilation
  2587. //! \{
  2588. // For JIT compilation
  2589. //! \brief Returns the byte code buffer and length.
  2590. //! \param[out] length The length of the byte code buffer in DWORDs
  2591. //! \return A pointer to the byte code buffer, or 0 if this is not a script function.
  2592. //!
  2593. //! This function is used by the \ref asIJITCompiler to obtain the byte
  2594. //! code buffer for building the native machine code representation.
  2595. virtual asDWORD *GetByteCode(asUINT *length = 0) = 0;
  2596. //! \}
  2597. protected:
  2598. virtual ~asIScriptFunction() {};
  2599. };
  2600. //! \brief A binary stream interface.
  2601. //!
  2602. //! This interface is used when storing compiled bytecode to disk or memory, and then loading it into the engine again.
  2603. //!
  2604. //! \see \ref asIScriptModule::SaveByteCode, \ref asIScriptModule::LoadByteCode
  2605. class asIBinaryStream
  2606. {
  2607. public:
  2608. //! \brief Read size bytes from the stream into the memory pointed to by ptr.
  2609. //!
  2610. //! \param[out] ptr A pointer to the buffer that will receive the data.
  2611. //! \param[in] size The number of bytes to read.
  2612. //!
  2613. //! Read \a size bytes from the data stream into the memory pointed to by \a ptr.
  2614. virtual void Read(void *ptr, asUINT size) = 0;
  2615. //! \brief Write size bytes to the stream from the memory pointed to by ptr.
  2616. //!
  2617. //! \param[in] ptr A pointer to the buffer that the data should written from.
  2618. //! \param[in] size The number of bytes to write.
  2619. //!
  2620. //! Write \a size bytes to the data stream from the memory pointed to by \a ptr.
  2621. virtual void Write(const void *ptr, asUINT size) = 0;
  2622. public:
  2623. virtual ~asIBinaryStream() {}
  2624. };
  2625. //-----------------------------------------------------------------
  2626. // Function pointers
  2627. // Use our own memset() and memcpy() implementations for better portability
  2628. inline void asMemClear(void *_p, int size)
  2629. {
  2630. char *p = (char *)_p;
  2631. const char *e = p + size;
  2632. for( ; p < e; p++ )
  2633. *p = 0;
  2634. }
  2635. inline void asMemCopy(void *_d, const void *_s, int size)
  2636. {
  2637. char *d = (char *)_d;
  2638. const char *s = (const char *)_s;
  2639. const char *e = s + size;
  2640. for( ; s < e; d++, s++ )
  2641. *d = *s;
  2642. }
  2643. // Template function to capture all global functions,
  2644. // except the ones using the generic calling convention
  2645. template <class T>
  2646. inline asSFuncPtr asFunctionPtr(T func)
  2647. {
  2648. asSFuncPtr p;
  2649. asMemClear(&p, sizeof(p));
  2650. p.ptr.f.func = (asFUNCTION_t)(size_t)func;
  2651. // Mark this as a global function
  2652. p.flag = 2;
  2653. return p;
  2654. }
  2655. // Specialization for functions using the generic calling convention
  2656. template<>
  2657. inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
  2658. {
  2659. asSFuncPtr p;
  2660. asMemClear(&p, sizeof(p));
  2661. p.ptr.f.func = (asFUNCTION_t)func;
  2662. // Mark this as a generic function
  2663. p.flag = 1;
  2664. return p;
  2665. }
  2666. #ifndef AS_NO_CLASS_METHODS
  2667. // Method pointers
  2668. // Declare a dummy class so that we can determine the size of a simple method pointer
  2669. class asCSimpleDummy {};
  2670. typedef void (asCSimpleDummy::*asSIMPLEMETHOD_t)();
  2671. const int SINGLE_PTR_SIZE = sizeof(asSIMPLEMETHOD_t);
  2672. // Define template
  2673. template <int N>
  2674. struct asSMethodPtr
  2675. {
  2676. template<class M>
  2677. static asSFuncPtr Convert(M Mthd)
  2678. {
  2679. // This version of the function should never be executed, nor compiled,
  2680. // as it would mean that the size of the method pointer cannot be determined.
  2681. int ERROR_UnsupportedMethodPtr[N-100];
  2682. return 0;
  2683. }
  2684. };
  2685. // Template specialization
  2686. template <>
  2687. struct asSMethodPtr<SINGLE_PTR_SIZE>
  2688. {
  2689. template<class M>
  2690. static asSFuncPtr Convert(M Mthd)
  2691. {
  2692. asSFuncPtr p;
  2693. asMemClear(&p, sizeof(p));
  2694. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE);
  2695. // Mark this as a class method
  2696. p.flag = 3;
  2697. return p;
  2698. }
  2699. };
  2700. #if defined(_MSC_VER) && !defined(__MWERKS__)
  2701. // MSVC and Intel uses different sizes for different class method pointers
  2702. template <>
  2703. struct asSMethodPtr<SINGLE_PTR_SIZE+1*sizeof(int)>
  2704. {
  2705. template <class M>
  2706. static asSFuncPtr Convert(M Mthd)
  2707. {
  2708. asSFuncPtr p;
  2709. asMemClear(&p, sizeof(p));
  2710. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+sizeof(int));
  2711. // Mark this as a class method
  2712. p.flag = 3;
  2713. return p;
  2714. }
  2715. };
  2716. template <>
  2717. struct asSMethodPtr<SINGLE_PTR_SIZE+2*sizeof(int)>
  2718. {
  2719. template <class M>
  2720. static asSFuncPtr Convert(M Mthd)
  2721. {
  2722. // This is where a class with virtual inheritance falls, or
  2723. // on 64bit platforms with 8byte data alignments.
  2724. // Method pointers for virtual inheritance is not supported,
  2725. // as it requires the location of the vbase table, which is
  2726. // only available to the C++ compiler, but not in the method
  2727. // pointer.
  2728. // You can get around this by forward declaring the class and
  2729. // storing the sizeof its method pointer in a constant. Example:
  2730. // class ClassWithVirtualInheritance;
  2731. // const int ClassWithVirtualInheritance_workaround = sizeof(void ClassWithVirtualInheritance::*());
  2732. // This will force the compiler to use the unknown type
  2733. // for the class, which falls under the next case
  2734. // TODO: We need to try to identify if this is really a method pointer
  2735. // with virtual inheritance, or just a method pointer for multiple
  2736. // inheritance with pad bytes to produce a 16byte structure.
  2737. asSFuncPtr p;
  2738. asMemClear(&p, sizeof(p));
  2739. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+2*sizeof(int));
  2740. // Mark this as a class method
  2741. p.flag = 3;
  2742. return p;
  2743. }
  2744. };
  2745. template <>
  2746. struct asSMethodPtr<SINGLE_PTR_SIZE+3*sizeof(int)>
  2747. {
  2748. template <class M>
  2749. static asSFuncPtr Convert(M Mthd)
  2750. {
  2751. asSFuncPtr p;
  2752. asMemClear(&p, sizeof(p));
  2753. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+3*sizeof(int));
  2754. // Mark this as a class method
  2755. p.flag = 3;
  2756. return p;
  2757. }
  2758. };
  2759. template <>
  2760. struct asSMethodPtr<SINGLE_PTR_SIZE+4*sizeof(int)>
  2761. {
  2762. template <class M>
  2763. static asSFuncPtr Convert(M Mthd)
  2764. {
  2765. // On 64bit platforms with 8byte data alignment
  2766. // the unknown class method pointers will come here.
  2767. asSFuncPtr p;
  2768. asMemClear(&p, sizeof(p));
  2769. asMemCopy(&p, &Mthd, SINGLE_PTR_SIZE+4*sizeof(int));
  2770. // Mark this as a class method
  2771. p.flag = 3;
  2772. return p;
  2773. }
  2774. };
  2775. #endif
  2776. #endif // AS_NO_CLASS_METHODS
  2777. //----------------------------------------------------------------
  2778. // JIT compiler
  2779. //! \brief A struct with registers from the VM sent to a JIT compiled function
  2780. //!
  2781. //! The JIT compiled function will receive a pointer to this structure when called.
  2782. //! It is the responsibility of the JIT compiled function to make sure these
  2783. //! values are updated correctly before control is returned to the VM.
  2784. //!
  2785. //! \see \ref doc_adv_jit
  2786. struct asSVMRegisters
  2787. {
  2788. //! \brief Points to the current bytecode instruction
  2789. asDWORD *programPointer; // points to current bytecode instruction
  2790. //! \brief Function stack frame. This doesn't change during the function execution.
  2791. asDWORD *stackFramePointer; // function stack frame
  2792. //! \brief Top of the stack (grows downward)
  2793. asDWORD *stackPointer; // top of stack (grows downward)
  2794. //! \brief Array of global variable pointers. This doesn't change during the function execution.
  2795. void **globalVarPointers; // global variable pointers
  2796. //! \brief Temporary register for primitives and unmanaged references
  2797. asQWORD valueRegister; // temp register for primitives
  2798. //! \brief Temporary register for managed object references/handles
  2799. void *objectRegister; // temp register for objects and handles
  2800. //! \brief Type of the object held in the object register
  2801. asIObjectType *objectType; // type of object held in object register
  2802. //! \brief Set to true if the SUSPEND instruction should be processed. Do not update this value.
  2803. bool doProcessSuspend; // whether or not the JIT should break out when it encounters a suspend instruction
  2804. };
  2805. //! \brief The function signature of a JIT compiled function
  2806. //! \param [in] registers A pointer to the virtual machine's registers.
  2807. //! \param [in] entryId The value defined by the JIT compiler for the current entry point in the JIT function.
  2808. //!
  2809. //! A JIT function receives a pointer to the virtual machine's registers when called and
  2810. //! an argument telling it where in the script function to continue the execution. The JIT
  2811. //! function must make sure to update the VM's registers according to the actions performed
  2812. //! before returning control to the VM.
  2813. //!
  2814. //! \see \ref doc_adv_jit
  2815. typedef void (*asJITFunction)(asSVMRegisters *registers, asDWORD entryId);
  2816. //! \brief The interface that AS use to interact with the JIT compiler
  2817. //!
  2818. //! This is the minimal interface that the JIT compiler must implement
  2819. //! so that AngelScript can request the compilation of the script functions.
  2820. //!
  2821. //! \see \ref doc_adv_jit
  2822. class asIJITCompiler
  2823. {
  2824. public:
  2825. //! \brief Called by AngelScript to begin the compilation
  2826. //!
  2827. //! \param [in] function A pointer to the script function
  2828. //! \param [out] output The JIT compiled function
  2829. //! \return A negative value on error.
  2830. //!
  2831. //! AngelScript will call this function to request the compilation of
  2832. //! a script function. The JIT compiler should produce the native machine
  2833. //! code representation of the function and update the JitEntry instructions
  2834. //! in the byte code to allow the VM to transfer the control to the JIT compiled
  2835. //! function.
  2836. virtual int CompileFunction(asIScriptFunction *function, asJITFunction *output) = 0;
  2837. //! \brief Called by AngelScript when the JIT function is released
  2838. //! \param [in] func Pointer to the JIT function
  2839. virtual void ReleaseJITFunction(asJITFunction func) = 0;
  2840. public:
  2841. virtual ~asIJITCompiler() {}
  2842. };
  2843. // Byte code instructions
  2844. //! \brief The bytecode instructions used by the VM
  2845. //! \see \ref doc_adv_jit_1
  2846. enum asEBCInstr
  2847. {
  2848. //! \brief Decrease the stack with the amount in the argument
  2849. asBC_POP = 0,
  2850. //! \brief Increase the stack with the amount in the argument
  2851. asBC_PUSH = 1,
  2852. //! \brief Push the 32bit value in the argument onto the stack
  2853. asBC_PshC4 = 2,
  2854. //! \brief Push the 32bit value from a variable onto the stack
  2855. asBC_PshV4 = 3,
  2856. //! \brief Push the address of the stack frame onto the stack
  2857. asBC_PSF = 4,
  2858. //! \brief Swap the top two DWORDs on the stack
  2859. asBC_SWAP4 = 5,
  2860. //! \brief Perform a boolean not on the value in a variable
  2861. asBC_NOT = 6,
  2862. //! \brief Push the 32bit value from a global variable onto the stack
  2863. asBC_PshG4 = 7,
  2864. //! \brief Perform the actions of \ref asBC_LDG followed by \ref asBC_RDR4
  2865. asBC_LdGRdR4 = 8,
  2866. //! \brief Jump to a script function, indexed by the argument
  2867. asBC_CALL = 9,
  2868. //! \brief Return to the instruction after the last executed call
  2869. asBC_RET = 10,
  2870. //! \brief Unconditional jump to a relative position in this function
  2871. asBC_JMP = 11,
  2872. //! \brief If the value register is 0 jump to a relative position in this function
  2873. asBC_JZ = 12,
  2874. //! \brief If the value register is not 0 jump to a relative position in this function
  2875. asBC_JNZ = 13,
  2876. //! \brief If the value register is less than 0 jump to a relative position in this function
  2877. asBC_JS = 14,
  2878. //! \brief If the value register is greater than or equal to 0 jump to a relative position in this function
  2879. asBC_JNS = 15,
  2880. //! \brief If the value register is greater than 0 jump to a relative position in this function
  2881. asBC_JP = 16,
  2882. //! \brief If the value register is less than or equal to 0 jump to a relative position in this function
  2883. asBC_JNP = 17,
  2884. //! \brief If the value register is 0 set it to 1
  2885. asBC_TZ = 18,
  2886. //! \brief If the value register is not 0 set it to 1
  2887. asBC_TNZ = 19,
  2888. //! \brief If the value register is less than 0 set it to 1
  2889. asBC_TS = 20,
  2890. //! \brief If the value register is greater than or equal to 0 set it to 1
  2891. asBC_TNS = 21,
  2892. //! \brief If the value register is greater than 0 set it to 1
  2893. asBC_TP = 22,
  2894. //! \brief If the value register is less than or equal to 0 set it to 1
  2895. asBC_TNP = 23,
  2896. //! \brief Negate the 32bit integer value in the variable
  2897. asBC_NEGi = 24,
  2898. //! \brief Negate the float value in the variable
  2899. asBC_NEGf = 25,
  2900. //! \brief Negate the double value in the variable
  2901. asBC_NEGd = 26,
  2902. //! \brief Increment the 16bit integer value that is stored at the address pointed to by the reference in the value register
  2903. asBC_INCi16 = 27,
  2904. //! \brief Increment the 8bit integer value that is stored at the address pointed to by the reference in the value register
  2905. asBC_INCi8 = 28,
  2906. //! \brief Decrement the 16bit integer value that is stored at the address pointed to by the reference in the value register
  2907. asBC_DECi16 = 29,
  2908. //! \brief Increment the 8bit integer value that is stored at the address pointed to by the reference in the value register
  2909. asBC_DECi8 = 30,
  2910. //! \brief Increment the 32bit integer value that is stored at the address pointed to by the reference in the value register
  2911. asBC_INCi = 31,
  2912. //! \brief Decrement the 32bit integer value that is stored at the address pointed to by the reference in the value register
  2913. asBC_DECi = 32,
  2914. //! \brief Increment the float value that is stored at the address pointed to by the reference in the value register
  2915. asBC_INCf = 33,
  2916. //! \brief Decrement the float value that is stored at the address pointed to by the reference in the value register
  2917. asBC_DECf = 34,
  2918. //! \brief Increment the double value that is stored at the address pointed to by the reference in the value register
  2919. asBC_INCd = 35,
  2920. //! \brief Decrement the double value that is stored at the address pointed to by the reference in the value register
  2921. asBC_DECd = 36,
  2922. //! \brief Increment the 32bit integer value in the variable
  2923. asBC_IncVi = 37,
  2924. //! \brief Decrement the 32bit integer value in the variable
  2925. asBC_DecVi = 38,
  2926. //! \brief Perform a bitwise complement on the 32bit value in the variable
  2927. asBC_BNOT = 39,
  2928. //! \brief Perform a bitwise and of two 32bit values and store the result in a third variable
  2929. asBC_BAND = 40,
  2930. //! \brief Perform a bitwise or of two 32bit values and store the result in a third variable
  2931. asBC_BOR = 41,
  2932. //! \brief Perform a bitwise exclusive or of two 32bit values and store the result in a third variable
  2933. asBC_BXOR = 42,
  2934. //! \brief Perform a logical left shift of a 32bit value and store the result in a third variable
  2935. asBC_BSLL = 43,
  2936. //! \brief Perform a logical right shift of a 32bit value and store the result in a third variable
  2937. asBC_BSRL = 44,
  2938. //! \brief Perform a arithmetical right shift of a 32bit value and store the result in a third variable
  2939. asBC_BSRA = 45,
  2940. //! \brief Pop the destination and source addresses from the stack. Perform a bitwise copy of the referred object. Push the destination address on the stack.
  2941. asBC_COPY = 46,
  2942. //! \brief Push a 64bit value on the stack
  2943. asBC_PshC8 = 47,
  2944. //! \brief Pop an address from the stack, then read a 64bit value from that address and push it on the stack
  2945. asBC_RDS8 = 48,
  2946. //! \brief Swap the top two QWORDs on the stack
  2947. asBC_SWAP8 = 49,
  2948. //! \brief Compare two double variables and store the result in the value register
  2949. asBC_CMPd = 50,
  2950. //! \brief Compare two unsigned 32bit integer variables and store the result in the value register
  2951. asBC_CMPu = 51,
  2952. //! \brief Compare two float variables and store the result in the value register
  2953. asBC_CMPf = 52,
  2954. //! \brief Compare two 32bit integer variables and store the result in the value register
  2955. asBC_CMPi = 53,
  2956. //! \brief Compare 32bit integer variable with constant and store the result in value register
  2957. asBC_CMPIi = 54,
  2958. //! \brief Compare float variable with constant and store the result in value register
  2959. asBC_CMPIf = 55,
  2960. //! \brief Compare unsigned 32bit integer variable with constant and store the result in value register
  2961. asBC_CMPIu = 56,
  2962. //! \brief Jump to relative position in the function where the offset is stored in a variable
  2963. asBC_JMPP = 57,
  2964. //! \brief Pop a pointer from the stack and store it in the value register
  2965. asBC_PopRPtr = 58,
  2966. //! \brief Push a pointer from the value register onto the stack
  2967. asBC_PshRPtr = 59,
  2968. //! \brief Push string address and length on the stack
  2969. asBC_STR = 60,
  2970. //! \brief Call registered function. Suspend further execution if requested.
  2971. asBC_CALLSYS = 61,
  2972. //! \brief Jump to an imported script function, indexed by the argument
  2973. asBC_CALLBND = 62,
  2974. //! \brief Call line callback function if set. Suspend execution if requested.
  2975. asBC_SUSPEND = 63,
  2976. //! \brief Allocate the memory for the object. If the type is a script object then jump to the constructor, else call the registered constructor behaviour. Suspend further execution if requested.
  2977. asBC_ALLOC = 64,
  2978. //! \brief Pop the address of the object variable from the stack. If ref type, call the release method, else call the destructor then free the memory. Clear the pointer in the variable.
  2979. asBC_FREE = 65,
  2980. //! \brief Copy the object pointer from a variable to the object register. Clear the variable.
  2981. asBC_LOADOBJ = 66,
  2982. //! \brief Copy the object pointer from the object register to the variable. Clear the object register.
  2983. asBC_STOREOBJ = 67,
  2984. //! \brief Move object pointer from variable onto stack location.
  2985. asBC_GETOBJ = 68,
  2986. //! \brief Pop destination handle reference. Perform a handle assignment, while updating the reference count for both previous and new objects.
  2987. asBC_REFCPY = 69,
  2988. //! \brief Throw an exception if the pointer on the top of the stack is null.
  2989. asBC_CHKREF = 70,
  2990. //! \brief Replace a variable index on the stack with the object handle stored in that variable.
  2991. asBC_GETOBJREF = 71,
  2992. //! \brief Replace a variable index on the stack with the address of the variable.
  2993. asBC_GETREF = 72,
  2994. //! \brief Swap the top DWORD with the QWORD below it
  2995. asBC_SWAP48 = 73,
  2996. //! \brief Swap the top QWORD with the DWORD below it
  2997. asBC_SWAP84 = 74,
  2998. //! \brief Push the pointer argument onto the stack. The pointer is a pointer to an object type structure
  2999. asBC_OBJTYPE = 75,
  3000. //! \brief Push the type id onto the stack. Equivalent to \ref asBC_PshC4 "PshC4".
  3001. asBC_TYPEID = 76,
  3002. //! \brief Initialize the variable with a DWORD.
  3003. asBC_SetV4 = 77,
  3004. //! \brief Initialize the variable with a QWORD.
  3005. asBC_SetV8 = 78,
  3006. //! \brief Add a value to the top pointer on the stack, thus updating the address itself.
  3007. asBC_ADDSi = 79,
  3008. //! \brief Copy a DWORD from one variable to another
  3009. asBC_CpyVtoV4 = 80,
  3010. //! \brief Copy a QWORD from one variable to another
  3011. asBC_CpyVtoV8 = 81,
  3012. //! \brief Copy a DWORD from a variable into the value register
  3013. asBC_CpyVtoR4 = 82,
  3014. //! \brief Copy a QWORD from a variable into the value register
  3015. asBC_CpyVtoR8 = 83,
  3016. //! \brief Copy a DWORD from a local variable to a global variable
  3017. asBC_CpyVtoG4 = 84,
  3018. //! \brief Copy a DWORD from the value register into a variable
  3019. asBC_CpyRtoV4 = 85,
  3020. //! \brief Copy a QWORD from the value register into a variable
  3021. asBC_CpyRtoV8 = 86,
  3022. //! \brief Copy a DWORD from a global variable to a local variable
  3023. asBC_CpyGtoV4 = 87,
  3024. //! \brief Copy a BYTE from a variable to the address held in the value register
  3025. asBC_WRTV1 = 88,
  3026. //! \brief Copy a WORD from a variable to the address held in the value register
  3027. asBC_WRTV2 = 89,
  3028. //! \brief Copy a DWORD from a variable to the address held in the value register
  3029. asBC_WRTV4 = 90,
  3030. //! \brief Copy a QWORD from a variable to the address held in the value register
  3031. asBC_WRTV8 = 91,
  3032. //! \brief Copy a BYTE from address held in the value register to a variable. Clear the top bytes in the variable
  3033. asBC_RDR1 = 92,
  3034. //! \brief Copy a WORD from address held in the value register to a variable. Clear the top word in the variable
  3035. asBC_RDR2 = 93,
  3036. //! \brief Copy a DWORD from address held in the value register to a variable.
  3037. asBC_RDR4 = 94,
  3038. //! \brief Copy a QWORD from address held in the value register to a variable.
  3039. asBC_RDR8 = 95,
  3040. //! \brief Load the address of a global variable into the value register
  3041. asBC_LDG = 96,
  3042. //! \brief Load the address of a local variable into the value register
  3043. asBC_LDV = 97,
  3044. //! \brief Push the address of a global variable on the stack
  3045. asBC_PGA = 98,
  3046. //! \brief Pop an address from the stack. Read a DWORD from the address, and push it on the stack.
  3047. asBC_RDS4 = 99,
  3048. //! \brief Push the index of the variable on the stack, with the size of a pointer.
  3049. asBC_VAR = 100,
  3050. //! \brief Convert the 32bit integer value to a float in the variable
  3051. asBC_iTOf = 101,
  3052. //! \brief Convert the float value to a 32bit integer in the variable
  3053. asBC_fTOi = 102,
  3054. //! \brief Convert the unsigned 32bit integer value to a float in the variable
  3055. asBC_uTOf = 103,
  3056. //! \brief Convert the float value to an unsigned 32bit integer in the variable
  3057. asBC_fTOu = 104,
  3058. //! \brief Expand the low byte as a signed value to a full 32bit integer in the variable
  3059. asBC_sbTOi = 105,
  3060. //! \brief Expand the low word as a signed value to a full 32bit integer in the variable
  3061. asBC_swTOi = 106,
  3062. //! \brief Expand the low byte as an unsigned value to a full 32bit integer in the variable
  3063. asBC_ubTOi = 107,
  3064. //! \brief Expand the low word as an unsigned value to a full 32bit integer in the variable
  3065. asBC_uwTOi = 108,
  3066. //! \brief Convert the double value in one variable to a 32bit integer in another variable
  3067. asBC_dTOi = 109,
  3068. //! \brief Convert the double value in one variable to a 32bit unsigned integer in another variable
  3069. asBC_dTOu = 110,
  3070. //! \brief Convert the double value in one variable to a float in another variable
  3071. asBC_dTOf = 111,
  3072. //! \brief Convert the 32bit integer value in one variable to a double in another variable
  3073. asBC_iTOd = 112,
  3074. //! \brief Convert the 32bit unsigned integer value in one variable to a double in another variable
  3075. asBC_uTOd = 113,
  3076. //! \brief Convert the float value in one variable to a double in another variable
  3077. asBC_fTOd = 114,
  3078. //! \brief Add the values of two 32bit integer variables and store in a third variable
  3079. asBC_ADDi = 115,
  3080. //! \brief Subtract the values of two 32bit integer variables and store in a third variable
  3081. asBC_SUBi = 116,
  3082. //! \brief Multiply the values of two 32bit integer variables and store in a third variable
  3083. asBC_MULi = 117,
  3084. //! \brief Divide the values of two 32bit integer variables and store in a third variable
  3085. asBC_DIVi = 118,
  3086. //! \brief Calculate the modulo of values of two 32bit integer variables and store in a third variable
  3087. asBC_MODi = 119,
  3088. //! \brief Add the values of two float variables and store in a third variable
  3089. asBC_ADDf = 120,
  3090. //! \brief Subtract the values of two float variables and store in a third variable
  3091. asBC_SUBf = 121,
  3092. //! \brief Multiply the values of two float variables and store in a third variable
  3093. asBC_MULf = 122,
  3094. //! \brief Divide the values of two float variables and store in a third variable
  3095. asBC_DIVf = 123,
  3096. //! \brief Calculate the modulo of values of two float variables and store in a third variable
  3097. asBC_MODf = 124,
  3098. //! \brief Add the values of two double variables and store in a third variable
  3099. asBC_ADDd = 125,
  3100. //! \brief Subtract the values of two double variables and store in a third variable
  3101. asBC_SUBd = 126,
  3102. //! \brief Multiply the values of two double variables and store in a third variable
  3103. asBC_MULd = 127,
  3104. //! \brief Divide the values of two double variables and store in a third variable
  3105. asBC_DIVd = 128,
  3106. //! \brief Calculate the modulo of values of two double variables and store in a third variable
  3107. asBC_MODd = 129,
  3108. //! \brief Add a 32bit integer variable with a constant value and store the result in another variable
  3109. asBC_ADDIi = 130,
  3110. //! \brief Subtract a 32bit integer variable with a constant value and store the result in another variable
  3111. asBC_SUBIi = 131,
  3112. //! \brief Multiply a 32bit integer variable with a constant value and store the result in another variable
  3113. asBC_MULIi = 132,
  3114. //! \brief Add a float variable with a constant value and store the result in another variable
  3115. asBC_ADDIf = 133,
  3116. //! \brief Subtract a float variable with a constant value and store the result in another variable
  3117. asBC_SUBIf = 134,
  3118. //! \brief Multiply a float variable with a constant value and store the result in another variable
  3119. asBC_MULIf = 135,
  3120. //! \brief Set the value of global variable to a 32bit word
  3121. asBC_SetG4 = 136,
  3122. //! \brief Throw an exception if the address stored on the stack points to a null pointer
  3123. asBC_ChkRefS = 137,
  3124. //! \brief Throw an exception if the variable is null
  3125. asBC_ChkNullV = 138,
  3126. //! \brief Jump to an interface method, indexed by the argument
  3127. asBC_CALLINTF = 139,
  3128. //! \brief Convert a 32bit integer in a variable to a byte, clearing the top bytes
  3129. asBC_iTOb = 140,
  3130. //! \brief Convert a 32bit integer in a variable to a word, clearing the top word
  3131. asBC_iTOw = 141,
  3132. //! \brief Same as \ref asBC_SetV4 "SetV4"
  3133. asBC_SetV1 = 142,
  3134. //! \brief Same as \ref asBC_SetV4 "SetV4"
  3135. asBC_SetV2 = 143,
  3136. //! \brief Pop an object handle to a script class from the stack. Perform a dynamic cast on it and store the result in the object register.
  3137. asBC_Cast = 144,
  3138. //! \brief Convert the 64bit integer value in one variable to a 32bit integer in another variable
  3139. asBC_i64TOi = 145,
  3140. //! \brief Convert the 32bit unsigned integer value in one variable to a 64bit integer in another variable
  3141. asBC_uTOi64 = 146,
  3142. //! \brief Convert the 32bit integer value in one variable to a 64bit integer in another variable
  3143. asBC_iTOi64 = 147,
  3144. //! \brief Convert the float value in one variable to a 64bit integer in another variable
  3145. asBC_fTOi64 = 148,
  3146. //! \brief Convert the double value in the variable to a 64bit integer
  3147. asBC_dTOi64 = 149,
  3148. //! \brief Convert the float value in one variable to a 64bit unsigned integer in another variable
  3149. asBC_fTOu64 = 150,
  3150. //! \brief Convert the double value in the variable to a 64bit unsigned integer
  3151. asBC_dTOu64 = 151,
  3152. //! \brief Convert the 64bit integer value in one variable to a float in another variable
  3153. asBC_i64TOf = 152,
  3154. //! \brief Convert the 64bit unsigned integer value in one variable to a float in another variable
  3155. asBC_u64TOf = 153,
  3156. //! \brief Convert the 32bit integer value in the variable to a double
  3157. asBC_i64TOd = 154,
  3158. //! \brief Convert the 32bit unsigned integer value in the variable to a double
  3159. asBC_u64TOd = 155,
  3160. //! \brief Negate the 64bit integer value in the variable
  3161. asBC_NEGi64 = 156,
  3162. //! \brief Increment the 64bit integer value that is stored at the address pointed to by the reference in the value register
  3163. asBC_INCi64 = 157,
  3164. //! \brief Decrement the 64bit integer value that is stored at the address pointed to by the reference in the value register
  3165. asBC_DECi64 = 158,
  3166. //! \brief Perform a bitwise complement on the 64bit value in the variable
  3167. asBC_BNOT64 = 159,
  3168. //! \brief Perform an addition with two 64bit integer variables and store the result in a third variable
  3169. asBC_ADDi64 = 160,
  3170. //! \brief Perform a subtraction with two 64bit integer variables and store the result in a third variable
  3171. asBC_SUBi64 = 161,
  3172. //! \brief Perform a multiplication with two 64bit integer variables and store the result in a third variable
  3173. asBC_MULi64 = 162,
  3174. //! \brief Perform a division with two 64bit integer variables and store the result in a third variable
  3175. asBC_DIVi64 = 163,
  3176. //! \brief Perform the modulo operation with two 64bit integer variables and store the result in a third variable
  3177. asBC_MODi64 = 164,
  3178. //! \brief Perform a bitwise and of two 64bit values and store the result in a third variable
  3179. asBC_BAND64 = 165,
  3180. //! \brief Perform a bitwise or of two 64bit values and store the result in a third variable
  3181. asBC_BOR64 = 166,
  3182. //! \brief Perform a bitwise exclusive or of two 64bit values and store the result in a third variable
  3183. asBC_BXOR64 = 167,
  3184. //! \brief Perform a logical left shift of a 64bit value and store the result in a third variable
  3185. asBC_BSLL64 = 168,
  3186. //! \brief Perform a logical right shift of a 64bit value and store the result in a third variable
  3187. asBC_BSRL64 = 169,
  3188. //! \brief Perform a arithmetical right shift of a 64bit value and store the result in a third variable
  3189. asBC_BSRA64 = 170,
  3190. //! \brief Compare two 64bit integer variables and store the result in the value register
  3191. asBC_CMPi64 = 171,
  3192. //! \brief Compare two unsigned 64bit integer variables and store the result in the value register
  3193. asBC_CMPu64 = 172,
  3194. //! \brief Check if a pointer on the stack is null, and if it is throw an exception. The argument is relative to the top of the stack
  3195. asBC_ChkNullS = 173,
  3196. //! \brief Clear the upper bytes of the value register so that only the value in the lowest byte is kept
  3197. asBC_ClrHi = 174,
  3198. //! \brief If a JIT function is available and the argument is not 0 then call the JIT function
  3199. asBC_JitEntry = 175,
  3200. asBC_MAXBYTECODE = 176,
  3201. // Temporary tokens. Can't be output to the final program
  3202. asBC_PSP = 253,
  3203. asBC_LINE = 254,
  3204. asBC_LABEL = 255
  3205. };
  3206. // Instruction types
  3207. //! \brief Describes the structure of a bytecode instruction
  3208. enum asEBCType
  3209. {
  3210. asBCTYPE_INFO = 0,
  3211. //! \brief Instruction + no args
  3212. asBCTYPE_NO_ARG = 1,
  3213. //! \brief Instruction + WORD arg
  3214. asBCTYPE_W_ARG = 2,
  3215. //! \brief Instruction + WORD arg (dest var)
  3216. asBCTYPE_wW_ARG = 3,
  3217. //! \brief Instruction + DWORD arg
  3218. asBCTYPE_DW_ARG = 4,
  3219. //! \brief Instruction + WORD arg (source var) + DWORD arg
  3220. asBCTYPE_rW_DW_ARG = 5,
  3221. //! \brief Instruction + QWORD arg
  3222. asBCTYPE_QW_ARG = 6,
  3223. //! \brief Instruction + DWORD arg + DWORD arg
  3224. asBCTYPE_DW_DW_ARG = 7,
  3225. //! \brief Instruction + WORD arg (dest var) + WORD arg (source var) + WORD arg (source var)
  3226. asBCTYPE_wW_rW_rW_ARG = 8,
  3227. //! \brief Instruction + WORD arg (dest var) + QWORD arg
  3228. asBCTYPE_wW_QW_ARG = 9,
  3229. //! \brief Instruction + WORD arg (dest var) + WORD arg (source var)
  3230. asBCTYPE_wW_rW_ARG = 10,
  3231. //! \brief Instruction + WORD arg (source var)
  3232. asBCTYPE_rW_ARG = 11,
  3233. //! \brief Instruction + WORD arg (dest var) + DWORD arg
  3234. asBCTYPE_wW_DW_ARG = 12,
  3235. //! \brief Instruction + WORD arg (dest var) + WORD arg (source var) + DWORD arg
  3236. asBCTYPE_wW_rW_DW_ARG = 13,
  3237. //! \brief Instruction + WORD arg (source var) + WORD arg (source var)
  3238. asBCTYPE_rW_rW_ARG = 14,
  3239. //! \brief Instruction + WORD arg + WORD arg (source var)
  3240. asBCTYPE_W_rW_ARG = 15,
  3241. //! \brief Instruction + WORD arg (dest var) + WORD arg
  3242. asBCTYPE_wW_W_ARG = 16,
  3243. //! \brief Instruction + WORD arg + DWORD arg
  3244. asBCTYPE_W_DW_ARG = 17,
  3245. //! \brief Instruction + QWORD arg + DWORD arg
  3246. asBCTYPE_QW_DW_ARG = 18
  3247. };
  3248. // Instruction type sizes
  3249. //! \brief Lookup table for determining the size of each \ref asEBCType "type" of bytecode instruction.
  3250. const int asBCTypeSize[19] =
  3251. {
  3252. 0, // asBCTYPE_INFO
  3253. 1, // asBCTYPE_NO_ARG
  3254. 1, // asBCTYPE_W_ARG
  3255. 1, // asBCTYPE_wW_ARG
  3256. 2, // asBCTYPE_DW_ARG
  3257. 2, // asBCTYPE_rW_DW_ARG
  3258. 3, // asBCTYPE_QW_ARG
  3259. 3, // asBCTYPE_DW_DW_ARG
  3260. 2, // asBCTYPE_wW_rW_rW_ARG
  3261. 3, // asBCTYPE_wW_QW_ARG
  3262. 2, // asBCTYPE_wW_rW_ARG
  3263. 1, // asBCTYPE_rW_ARG
  3264. 2, // asBCTYPE_wW_DW_ARG
  3265. 3, // asBCTYPE_wW_rW_DW_ARG
  3266. 2, // asBCTYPE_rW_rW_ARG
  3267. 2, // asBCTYPE_W_rW_ARG
  3268. 2, // asBCTYPE_wW_W_ARG
  3269. 2, // asBCTYPE_W_DW_ARG
  3270. 4 // asBCTYPE_QW_DW_ARG
  3271. };
  3272. // Instruction info
  3273. //! \brief Information on a bytecode instruction
  3274. //!
  3275. //! This structure can be obtained for each bytecode instruction
  3276. //! by looking it up in the \ref asBCInfo array.
  3277. //!
  3278. //! The size of the instruction can be obtained by looking up the
  3279. //! type in the \ref asBCTypeSize array.
  3280. //!
  3281. //! \see \ref doc_adv_jit
  3282. struct asSBCInfo
  3283. {
  3284. //! \brief Bytecode instruction id
  3285. asEBCInstr bc;
  3286. //! \brief Instruction argument layout
  3287. asEBCType type;
  3288. //! \brief How much this argument increments the stack pointer. 0xFFFF if it depends on the arguments.
  3289. int stackInc;
  3290. //! \brief Name of the instruction for debugging
  3291. const char *name;
  3292. };
  3293. #ifndef AS_64BIT_PTR
  3294. #define asBCTYPE_PTR_ARG asBCTYPE_DW_ARG
  3295. #define asBCTYPE_PTR_DW_ARG asBCTYPE_DW_DW_ARG
  3296. #ifndef AS_PTR_SIZE
  3297. #define AS_PTR_SIZE 1
  3298. #endif
  3299. #else
  3300. #define asBCTYPE_PTR_ARG asBCTYPE_QW_ARG
  3301. #define asBCTYPE_PTR_DW_ARG asBCTYPE_QW_DW_ARG
  3302. #ifndef AS_PTR_SIZE
  3303. #define AS_PTR_SIZE 2
  3304. #endif
  3305. #endif
  3306. #define asBCINFO(b,t,s) {asBC_##b, asBCTYPE_##t, s, #b}
  3307. #define asBCINFO_DUMMY(b) {asEBCInstr(b), asBCTYPE_INFO, 0, "BC_" #b}
  3308. //! \brief Information on each bytecode instruction
  3309. const asSBCInfo asBCInfo[256] =
  3310. {
  3311. asBCINFO(POP, W_ARG, 0xFFFF),
  3312. asBCINFO(PUSH, W_ARG, 0xFFFF),
  3313. asBCINFO(PshC4, DW_ARG, 1),
  3314. asBCINFO(PshV4, rW_ARG, 1),
  3315. asBCINFO(PSF, rW_ARG, AS_PTR_SIZE),
  3316. asBCINFO(SWAP4, NO_ARG, 0),
  3317. asBCINFO(NOT, rW_ARG, 0),
  3318. asBCINFO(PshG4, W_ARG, 1),
  3319. asBCINFO(LdGRdR4, wW_W_ARG, 0),
  3320. asBCINFO(CALL, DW_ARG, 0xFFFF),
  3321. asBCINFO(RET, W_ARG, 0xFFFF),
  3322. asBCINFO(JMP, DW_ARG, 0),
  3323. asBCINFO(JZ, DW_ARG, 0),
  3324. asBCINFO(JNZ, DW_ARG, 0),
  3325. asBCINFO(JS, DW_ARG, 0),
  3326. asBCINFO(JNS, DW_ARG, 0),
  3327. asBCINFO(JP, DW_ARG, 0),
  3328. asBCINFO(JNP, DW_ARG, 0),
  3329. asBCINFO(TZ, NO_ARG, 0),
  3330. asBCINFO(TNZ, NO_ARG, 0),
  3331. asBCINFO(TS, NO_ARG, 0),
  3332. asBCINFO(TNS, NO_ARG, 0),
  3333. asBCINFO(TP, NO_ARG, 0),
  3334. asBCINFO(TNP, NO_ARG, 0),
  3335. asBCINFO(NEGi, rW_ARG, 0),
  3336. asBCINFO(NEGf, rW_ARG, 0),
  3337. asBCINFO(NEGd, rW_ARG, 0),
  3338. asBCINFO(INCi16, NO_ARG, 0),
  3339. asBCINFO(INCi8, NO_ARG, 0),
  3340. asBCINFO(DECi16, NO_ARG, 0),
  3341. asBCINFO(DECi8, NO_ARG, 0),
  3342. asBCINFO(INCi, NO_ARG, 0),
  3343. asBCINFO(DECi, NO_ARG, 0),
  3344. asBCINFO(INCf, NO_ARG, 0),
  3345. asBCINFO(DECf, NO_ARG, 0),
  3346. asBCINFO(INCd, NO_ARG, 0),
  3347. asBCINFO(DECd, NO_ARG, 0),
  3348. asBCINFO(IncVi, rW_ARG, 0),
  3349. asBCINFO(DecVi, rW_ARG, 0),
  3350. asBCINFO(BNOT, rW_ARG, 0),
  3351. asBCINFO(BAND, wW_rW_rW_ARG, 0),
  3352. asBCINFO(BOR, wW_rW_rW_ARG, 0),
  3353. asBCINFO(BXOR, wW_rW_rW_ARG, 0),
  3354. asBCINFO(BSLL, wW_rW_rW_ARG, 0),
  3355. asBCINFO(BSRL, wW_rW_rW_ARG, 0),
  3356. asBCINFO(BSRA, wW_rW_rW_ARG, 0),
  3357. asBCINFO(COPY, W_ARG, -AS_PTR_SIZE),
  3358. asBCINFO(PshC8, QW_ARG, 2),
  3359. asBCINFO(RDS8, NO_ARG, 2-AS_PTR_SIZE),
  3360. asBCINFO(SWAP8, NO_ARG, 0),
  3361. asBCINFO(CMPd, rW_rW_ARG, 0),
  3362. asBCINFO(CMPu, rW_rW_ARG, 0),
  3363. asBCINFO(CMPf, rW_rW_ARG, 0),
  3364. asBCINFO(CMPi, rW_rW_ARG, 0),
  3365. asBCINFO(CMPIi, rW_DW_ARG, 0),
  3366. asBCINFO(CMPIf, rW_DW_ARG, 0),
  3367. asBCINFO(CMPIu, rW_DW_ARG, 0),
  3368. asBCINFO(JMPP, rW_ARG, 0),
  3369. asBCINFO(PopRPtr, NO_ARG, -AS_PTR_SIZE),
  3370. asBCINFO(PshRPtr, NO_ARG, AS_PTR_SIZE),
  3371. asBCINFO(STR, W_ARG, 1+AS_PTR_SIZE),
  3372. asBCINFO(CALLSYS, DW_ARG, 0xFFFF),
  3373. asBCINFO(CALLBND, DW_ARG, 0xFFFF),
  3374. asBCINFO(SUSPEND, NO_ARG, 0),
  3375. asBCINFO(ALLOC, PTR_DW_ARG, 0xFFFF),
  3376. asBCINFO(FREE, PTR_ARG, -AS_PTR_SIZE),
  3377. asBCINFO(LOADOBJ, rW_ARG, 0),
  3378. asBCINFO(STOREOBJ, wW_ARG, 0),
  3379. asBCINFO(GETOBJ, W_ARG, 0),
  3380. asBCINFO(REFCPY, PTR_ARG, -AS_PTR_SIZE),
  3381. asBCINFO(CHKREF, NO_ARG, 0),
  3382. asBCINFO(GETOBJREF, W_ARG, 0),
  3383. asBCINFO(GETREF, W_ARG, 0),
  3384. asBCINFO(SWAP48, NO_ARG, 0),
  3385. asBCINFO(SWAP84, NO_ARG, 0),
  3386. asBCINFO(OBJTYPE, PTR_ARG, AS_PTR_SIZE),
  3387. asBCINFO(TYPEID, DW_ARG, 1),
  3388. asBCINFO(SetV4, wW_DW_ARG, 0),
  3389. asBCINFO(SetV8, wW_QW_ARG, 0),
  3390. asBCINFO(ADDSi, DW_ARG, 0),
  3391. asBCINFO(CpyVtoV4, wW_rW_ARG, 0),
  3392. asBCINFO(CpyVtoV8, wW_rW_ARG, 0),
  3393. asBCINFO(CpyVtoR4, rW_ARG, 0),
  3394. asBCINFO(CpyVtoR8, rW_ARG, 0),
  3395. asBCINFO(CpyVtoG4, W_rW_ARG, 0),
  3396. asBCINFO(CpyRtoV4, wW_ARG, 0),
  3397. asBCINFO(CpyRtoV8, wW_ARG, 0),
  3398. asBCINFO(CpyGtoV4, wW_W_ARG, 0),
  3399. asBCINFO(WRTV1, rW_ARG, 0),
  3400. asBCINFO(WRTV2, rW_ARG, 0),
  3401. asBCINFO(WRTV4, rW_ARG, 0),
  3402. asBCINFO(WRTV8, rW_ARG, 0),
  3403. asBCINFO(RDR1, wW_ARG, 0),
  3404. asBCINFO(RDR2, wW_ARG, 0),
  3405. asBCINFO(RDR4, wW_ARG, 0),
  3406. asBCINFO(RDR8, wW_ARG, 0),
  3407. asBCINFO(LDG, W_ARG, 0),
  3408. asBCINFO(LDV, rW_ARG, 0),
  3409. asBCINFO(PGA, W_ARG, AS_PTR_SIZE),
  3410. asBCINFO(RDS4, NO_ARG, 1-AS_PTR_SIZE),
  3411. asBCINFO(VAR, rW_ARG, AS_PTR_SIZE),
  3412. asBCINFO(iTOf, rW_ARG, 0),
  3413. asBCINFO(fTOi, rW_ARG, 0),
  3414. asBCINFO(uTOf, rW_ARG, 0),
  3415. asBCINFO(fTOu, rW_ARG, 0),
  3416. asBCINFO(sbTOi, rW_ARG, 0),
  3417. asBCINFO(swTOi, rW_ARG, 0),
  3418. asBCINFO(ubTOi, rW_ARG, 0),
  3419. asBCINFO(uwTOi, rW_ARG, 0),
  3420. asBCINFO(dTOi, wW_rW_ARG, 0),
  3421. asBCINFO(dTOu, wW_rW_ARG, 0),
  3422. asBCINFO(dTOf, wW_rW_ARG, 0),
  3423. asBCINFO(iTOd, wW_rW_ARG, 0),
  3424. asBCINFO(uTOd, wW_rW_ARG, 0),
  3425. asBCINFO(fTOd, wW_rW_ARG, 0),
  3426. asBCINFO(ADDi, wW_rW_rW_ARG, 0),
  3427. asBCINFO(SUBi, wW_rW_rW_ARG, 0),
  3428. asBCINFO(MULi, wW_rW_rW_ARG, 0),
  3429. asBCINFO(DIVi, wW_rW_rW_ARG, 0),
  3430. asBCINFO(MODi, wW_rW_rW_ARG, 0),
  3431. asBCINFO(ADDf, wW_rW_rW_ARG, 0),
  3432. asBCINFO(SUBf, wW_rW_rW_ARG, 0),
  3433. asBCINFO(MULf, wW_rW_rW_ARG, 0),
  3434. asBCINFO(DIVf, wW_rW_rW_ARG, 0),
  3435. asBCINFO(MODf, wW_rW_rW_ARG, 0),
  3436. asBCINFO(ADDd, wW_rW_rW_ARG, 0),
  3437. asBCINFO(SUBd, wW_rW_rW_ARG, 0),
  3438. asBCINFO(MULd, wW_rW_rW_ARG, 0),
  3439. asBCINFO(DIVd, wW_rW_rW_ARG, 0),
  3440. asBCINFO(MODd, wW_rW_rW_ARG, 0),
  3441. asBCINFO(ADDIi, wW_rW_DW_ARG, 0),
  3442. asBCINFO(SUBIi, wW_rW_DW_ARG, 0),
  3443. asBCINFO(MULIi, wW_rW_DW_ARG, 0),
  3444. asBCINFO(ADDIf, wW_rW_DW_ARG, 0),
  3445. asBCINFO(SUBIf, wW_rW_DW_ARG, 0),
  3446. asBCINFO(MULIf, wW_rW_DW_ARG, 0),
  3447. asBCINFO(SetG4, W_DW_ARG, 0),
  3448. asBCINFO(ChkRefS, NO_ARG, 0),
  3449. asBCINFO(ChkNullV, rW_ARG, 0),
  3450. asBCINFO(CALLINTF, DW_ARG, 0xFFFF),
  3451. asBCINFO(iTOb, rW_ARG, 0),
  3452. asBCINFO(iTOw, rW_ARG, 0),
  3453. asBCINFO(SetV1, wW_DW_ARG, 0),
  3454. asBCINFO(SetV2, wW_DW_ARG, 0),
  3455. asBCINFO(Cast, DW_ARG, -AS_PTR_SIZE),
  3456. asBCINFO(i64TOi, wW_rW_ARG, 0),
  3457. asBCINFO(uTOi64, wW_rW_ARG, 0),
  3458. asBCINFO(iTOi64, wW_rW_ARG, 0),
  3459. asBCINFO(fTOi64, wW_rW_ARG, 0),
  3460. asBCINFO(dTOi64, rW_ARG, 0),
  3461. asBCINFO(fTOu64, wW_rW_ARG, 0),
  3462. asBCINFO(dTOu64, rW_ARG, 0),
  3463. asBCINFO(i64TOf, wW_rW_ARG, 0),
  3464. asBCINFO(u64TOf, wW_rW_ARG, 0),
  3465. asBCINFO(i64TOd, rW_ARG, 0),
  3466. asBCINFO(u64TOd, rW_ARG, 0),
  3467. asBCINFO(NEGi64, rW_ARG, 0),
  3468. asBCINFO(INCi64, NO_ARG, 0),
  3469. asBCINFO(DECi64, NO_ARG, 0),
  3470. asBCINFO(BNOT64, rW_ARG, 0),
  3471. asBCINFO(ADDi64, wW_rW_rW_ARG, 0),
  3472. asBCINFO(SUBi64, wW_rW_rW_ARG, 0),
  3473. asBCINFO(MULi64, wW_rW_rW_ARG, 0),
  3474. asBCINFO(DIVi64, wW_rW_rW_ARG, 0),
  3475. asBCINFO(MODi64, wW_rW_rW_ARG, 0),
  3476. asBCINFO(BAND64, wW_rW_rW_ARG, 0),
  3477. asBCINFO(BOR64, wW_rW_rW_ARG, 0),
  3478. asBCINFO(BXOR64, wW_rW_rW_ARG, 0),
  3479. asBCINFO(BSLL64, wW_rW_rW_ARG, 0),
  3480. asBCINFO(BSRL64, wW_rW_rW_ARG, 0),
  3481. asBCINFO(BSRA64, wW_rW_rW_ARG, 0),
  3482. asBCINFO(CMPi64, rW_rW_ARG, 0),
  3483. asBCINFO(CMPu64, rW_rW_ARG, 0),
  3484. asBCINFO(ChkNullS, W_ARG, 0),
  3485. asBCINFO(ClrHi, NO_ARG, 0),
  3486. asBCINFO(JitEntry, W_ARG, 0),
  3487. asBCINFO_DUMMY(176),
  3488. asBCINFO_DUMMY(177),
  3489. asBCINFO_DUMMY(178),
  3490. asBCINFO_DUMMY(179),
  3491. asBCINFO_DUMMY(180),
  3492. asBCINFO_DUMMY(181),
  3493. asBCINFO_DUMMY(182),
  3494. asBCINFO_DUMMY(183),
  3495. asBCINFO_DUMMY(184),
  3496. asBCINFO_DUMMY(185),
  3497. asBCINFO_DUMMY(186),
  3498. asBCINFO_DUMMY(187),
  3499. asBCINFO_DUMMY(188),
  3500. asBCINFO_DUMMY(189),
  3501. asBCINFO_DUMMY(190),
  3502. asBCINFO_DUMMY(191),
  3503. asBCINFO_DUMMY(192),
  3504. asBCINFO_DUMMY(193),
  3505. asBCINFO_DUMMY(194),
  3506. asBCINFO_DUMMY(195),
  3507. asBCINFO_DUMMY(196),
  3508. asBCINFO_DUMMY(197),
  3509. asBCINFO_DUMMY(198),
  3510. asBCINFO_DUMMY(199),
  3511. asBCINFO_DUMMY(200),
  3512. asBCINFO_DUMMY(201),
  3513. asBCINFO_DUMMY(202),
  3514. asBCINFO_DUMMY(203),
  3515. asBCINFO_DUMMY(204),
  3516. asBCINFO_DUMMY(205),
  3517. asBCINFO_DUMMY(206),
  3518. asBCINFO_DUMMY(207),
  3519. asBCINFO_DUMMY(208),
  3520. asBCINFO_DUMMY(209),
  3521. asBCINFO_DUMMY(210),
  3522. asBCINFO_DUMMY(211),
  3523. asBCINFO_DUMMY(212),
  3524. asBCINFO_DUMMY(213),
  3525. asBCINFO_DUMMY(214),
  3526. asBCINFO_DUMMY(215),
  3527. asBCINFO_DUMMY(216),
  3528. asBCINFO_DUMMY(217),
  3529. asBCINFO_DUMMY(218),
  3530. asBCINFO_DUMMY(219),
  3531. asBCINFO_DUMMY(220),
  3532. asBCINFO_DUMMY(221),
  3533. asBCINFO_DUMMY(222),
  3534. asBCINFO_DUMMY(223),
  3535. asBCINFO_DUMMY(224),
  3536. asBCINFO_DUMMY(225),
  3537. asBCINFO_DUMMY(226),
  3538. asBCINFO_DUMMY(227),
  3539. asBCINFO_DUMMY(228),
  3540. asBCINFO_DUMMY(229),
  3541. asBCINFO_DUMMY(230),
  3542. asBCINFO_DUMMY(231),
  3543. asBCINFO_DUMMY(232),
  3544. asBCINFO_DUMMY(233),
  3545. asBCINFO_DUMMY(234),
  3546. asBCINFO_DUMMY(235),
  3547. asBCINFO_DUMMY(236),
  3548. asBCINFO_DUMMY(237),
  3549. asBCINFO_DUMMY(238),
  3550. asBCINFO_DUMMY(239),
  3551. asBCINFO_DUMMY(240),
  3552. asBCINFO_DUMMY(241),
  3553. asBCINFO_DUMMY(242),
  3554. asBCINFO_DUMMY(243),
  3555. asBCINFO_DUMMY(244),
  3556. asBCINFO_DUMMY(245),
  3557. asBCINFO_DUMMY(246),
  3558. asBCINFO_DUMMY(247),
  3559. asBCINFO_DUMMY(248),
  3560. asBCINFO_DUMMY(249),
  3561. asBCINFO_DUMMY(250),
  3562. asBCINFO_DUMMY(251),
  3563. asBCINFO_DUMMY(252),
  3564. asBCINFO(PSP, W_ARG, AS_PTR_SIZE),
  3565. asBCINFO(LINE, INFO, 0xFFFF),
  3566. asBCINFO(LABEL, INFO, 0xFFFF)
  3567. };
  3568. // Macros to access bytecode instruction arguments
  3569. //! \brief Macro to access the first DWORD argument in the bytecode instruction
  3570. #define asBC_DWORDARG(x) (asDWORD(*(x+1)))
  3571. //! \brief Macro to access the first 32bit integer argument in the bytecode instruction
  3572. #define asBC_INTARG(x) (int(*(x+1)))
  3573. //! \brief Macro to access the first QWORD argument in the bytecode instruction
  3574. #define asBC_QWORDARG(x) (*(asQWORD*)(x+1))
  3575. //! \brief Macro to access the first float argument in the bytecode instruction
  3576. #define asBC_FLOATARG(x) (*(float*)(x+1))
  3577. //! \brief Macro to access the first pointer argument in the bytecode instruction
  3578. #define asBC_PTRARG(x) (asPTRWORD(*(x+1)))
  3579. //! \brief Macro to access the first WORD argument in the bytecode instruction
  3580. #define asBC_WORDARG0(x) (*(((asWORD*)x)+1))
  3581. //! \brief Macro to access the second WORD argument in the bytecode instruction
  3582. #define asBC_WORDARG1(x) (*(((asWORD*)x)+2))
  3583. //! \brief Macro to access the first signed WORD argument in the bytecode instruction
  3584. #define asBC_SWORDARG0(x) (*(((short*)x)+1))
  3585. //! \brief Macro to access the second signed WORD argument in the bytecode instruction
  3586. #define asBC_SWORDARG1(x) (*(((short*)x)+2))
  3587. //! \brief Macro to access the third signed WORD argument in the bytecode instruction
  3588. #define asBC_SWORDARG2(x) (*(((short*)x)+3))
  3589. END_AS_NAMESPACE
  3590. #endif