as_scriptengine.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2016 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. [email protected]
  22. */
  23. // Modified by Lasse Oorni for Urho3D
  24. //
  25. // as_scriptengine.h
  26. //
  27. // The implementation of the script engine interface
  28. //
  29. #ifndef AS_SCRIPTENGINE_H
  30. #define AS_SCRIPTENGINE_H
  31. #include "as_config.h"
  32. #include "as_atomic.h"
  33. #include "as_scriptfunction.h"
  34. #include "as_array.h"
  35. #include "as_datatype.h"
  36. #include "as_objecttype.h"
  37. #include "as_module.h"
  38. #include "as_callfunc.h"
  39. #include "as_configgroup.h"
  40. #include "as_memory.h"
  41. #include "as_gc.h"
  42. #include "as_tokenizer.h"
  43. BEGIN_AS_NAMESPACE
  44. class asCBuilder;
  45. class asCContext;
  46. // TODO: import: Remove this when import is removed
  47. struct sBindInfo;
  48. class asCScriptEngine : public asIScriptEngine
  49. {
  50. //=============================================================
  51. // From asIScriptEngine
  52. //=============================================================
  53. public:
  54. // Memory management
  55. virtual int AddRef() const;
  56. virtual int Release() const;
  57. virtual int ShutDownAndRelease();
  58. // Engine properties
  59. virtual int SetEngineProperty(asEEngineProp property, asPWORD value);
  60. virtual asPWORD GetEngineProperty(asEEngineProp property) const;
  61. // Compiler messages
  62. virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv);
  63. virtual int ClearMessageCallback();
  64. virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message);
  65. // JIT Compiler
  66. virtual int SetJITCompiler(asIJITCompiler *compiler);
  67. virtual asIJITCompiler *GetJITCompiler() const;
  68. // Global functions
  69. virtual int RegisterGlobalFunction(const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0);
  70. virtual asUINT GetGlobalFunctionCount() const;
  71. virtual asIScriptFunction *GetGlobalFunctionByIndex(asUINT index) const;
  72. virtual asIScriptFunction *GetGlobalFunctionByDecl(const char *declaration) const;
  73. // Global properties
  74. virtual int RegisterGlobalProperty(const char *declaration, void *pointer);
  75. virtual asUINT GetGlobalPropertyCount() const;
  76. virtual int GetGlobalPropertyByIndex(asUINT index, const char **name, const char **nameSpace = 0, int *typeId = 0, bool *isConst = 0, const char **configGroup = 0, void **pointer = 0, asDWORD *accessMask = 0) const;
  77. virtual int GetGlobalPropertyIndexByName(const char *name) const;
  78. virtual int GetGlobalPropertyIndexByDecl(const char *decl) const;
  79. // Type registration
  80. virtual int RegisterObjectType(const char *obj, int byteSize, asDWORD flags);
  81. virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset);
  82. virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0);
  83. virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0);
  84. virtual int RegisterInterface(const char *name);
  85. virtual int RegisterInterfaceMethod(const char *intf, const char *declaration);
  86. virtual asUINT GetObjectTypeCount() const;
  87. virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const;
  88. #ifdef AS_DEPRECATED
  89. // Deprecated since 2.31.0, 2015-12-06
  90. virtual asITypeInfo *GetObjectTypeByName(const char *name) const;
  91. virtual asITypeInfo *GetObjectTypeByDecl(const char *decl) const;
  92. #endif
  93. // String factory
  94. virtual int RegisterStringFactory(const char *datatype, const asSFuncPtr &factoryFunc, asDWORD callConv, void *auxiliary = 0);
  95. virtual int GetStringFactoryReturnTypeId(asDWORD *flags) const;
  96. // Default array type
  97. virtual int RegisterDefaultArrayType(const char *type);
  98. virtual int GetDefaultArrayTypeId() const;
  99. // Enums
  100. virtual int RegisterEnum(const char *type);
  101. virtual int RegisterEnumValue(const char *type, const char *name, int value);
  102. virtual asUINT GetEnumCount() const;
  103. virtual asITypeInfo *GetEnumByIndex(asUINT index) const;
  104. // Urho3D: removed deprecation for ScriptAPIDump
  105. // Deprecated since 2.31.0, 2015-12-06
  106. virtual int GetEnumValueCount(int enumTypeId) const;
  107. virtual const char * GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue) const;
  108. // Funcdefs
  109. virtual int RegisterFuncdef(const char *decl);
  110. virtual asUINT GetFuncdefCount() const;
  111. virtual asITypeInfo *GetFuncdefByIndex(asUINT index) const;
  112. // Typedefs
  113. // TODO: interface: Should perhaps rename this to Alias, since it doesn't really create a new type
  114. virtual int RegisterTypedef(const char *type, const char *decl);
  115. virtual asUINT GetTypedefCount() const;
  116. virtual asITypeInfo *GetTypedefByIndex(asUINT index) const;
  117. // Configuration groups
  118. virtual int BeginConfigGroup(const char *groupName);
  119. virtual int EndConfigGroup();
  120. virtual int RemoveConfigGroup(const char *groupName);
  121. virtual asDWORD SetDefaultAccessMask(asDWORD defaultMask);
  122. virtual int SetDefaultNamespace(const char *nameSpace);
  123. virtual const char *GetDefaultNamespace() const;
  124. // Script modules
  125. virtual asIScriptModule *GetModule(const char *module, asEGMFlags flag);
  126. virtual int DiscardModule(const char *module);
  127. virtual asUINT GetModuleCount() const;
  128. virtual asIScriptModule *GetModuleByIndex(asUINT index) const;
  129. // Script functions
  130. virtual asIScriptFunction *GetFunctionById(int funcId) const;
  131. #ifdef AS_DEPRECATED
  132. // deprecated since 2.31.0, 2016-01-01
  133. virtual asIScriptFunction *GetFuncdefFromTypeId(int typeId) const;
  134. #endif
  135. // Type identification
  136. #ifdef AS_DEPRECATED
  137. // Deprecated since 2.31.0, 2015-12-06
  138. virtual asITypeInfo *GetObjectTypeById(int typeId) const;
  139. #endif
  140. virtual int GetTypeIdByDecl(const char *decl) const;
  141. virtual const char *GetTypeDeclaration(int typeId, bool includeNamespace = false) const;
  142. virtual int GetSizeOfPrimitiveType(int typeId) const;
  143. virtual asITypeInfo *GetTypeInfoById(int typeId) const;
  144. virtual asITypeInfo *GetTypeInfoByName(const char *name) const;
  145. virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const;
  146. // Script execution
  147. virtual asIScriptContext *CreateContext();
  148. virtual void *CreateScriptObject(const asITypeInfo *type);
  149. virtual void *CreateScriptObjectCopy(void *obj, const asITypeInfo *type);
  150. virtual void *CreateUninitializedScriptObject(const asITypeInfo *type);
  151. virtual asIScriptFunction *CreateDelegate(asIScriptFunction *func, void *obj);
  152. virtual int AssignScriptObject(void *dstObj, void *srcObj, const asITypeInfo *type);
  153. virtual void ReleaseScriptObject(void *obj, const asITypeInfo *type);
  154. virtual void AddRefScriptObject(void *obj, const asITypeInfo *type);
  155. virtual int RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo *toType, void **newPtr, bool useOnlyImplicitCast = false);
  156. #ifdef AS_DEPRECATED
  157. // Deprecated since 2.30.0, 2014-11-04
  158. virtual bool IsHandleCompatibleWithObject(void *obj, int objTypeId, int handleTypeId) const;
  159. #endif
  160. virtual asILockableSharedBool *GetWeakRefFlagOfScriptObject(void *obj, const asITypeInfo *type) const;
  161. // Context pooling
  162. virtual asIScriptContext *RequestContext();
  163. virtual void ReturnContext(asIScriptContext *ctx);
  164. virtual int SetContextCallbacks(asREQUESTCONTEXTFUNC_t requestCtx, asRETURNCONTEXTFUNC_t returnCtx, void *param = 0);
  165. // String interpretation
  166. virtual asETokenClass ParseToken(const char *string, size_t stringLength = 0, asUINT *tokenLength = 0) const;
  167. // Garbage collection
  168. virtual int GarbageCollect(asDWORD flags = asGC_FULL_CYCLE, asUINT numIterations = 1);
  169. virtual void GetGCStatistics(asUINT *currentSize, asUINT *totalDestroyed, asUINT *totalDetected, asUINT *newObjects, asUINT *totalNewDestroyed) const;
  170. virtual int NotifyGarbageCollectorOfNewObject(void *obj, asITypeInfo *type);
  171. virtual int GetObjectInGC(asUINT idx, asUINT *seqNbr, void **obj = 0, asITypeInfo **type = 0);
  172. virtual void GCEnumCallback(void *reference);
  173. // User data
  174. virtual void *SetUserData(void *data, asPWORD type);
  175. virtual void *GetUserData(asPWORD type) const;
  176. virtual void SetEngineUserDataCleanupCallback(asCLEANENGINEFUNC_t callback, asPWORD type);
  177. virtual void SetModuleUserDataCleanupCallback(asCLEANMODULEFUNC_t callback, asPWORD type);
  178. virtual void SetContextUserDataCleanupCallback(asCLEANCONTEXTFUNC_t callback, asPWORD type);
  179. virtual void SetFunctionUserDataCleanupCallback(asCLEANFUNCTIONFUNC_t callback, asPWORD type);
  180. #ifdef AS_DEPRECATED
  181. // Deprecated since 2.31.0, 2015-12-06
  182. virtual void SetObjectTypeUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type);
  183. #endif
  184. virtual void SetTypeInfoUserDataCleanupCallback(asCLEANTYPEINFOFUNC_t callback, asPWORD type);
  185. virtual void SetScriptObjectUserDataCleanupCallback(asCLEANSCRIPTOBJECTFUNC_t callback, asPWORD type);
  186. //===========================================================
  187. // internal methods
  188. //===========================================================
  189. public:
  190. asCScriptEngine();
  191. virtual ~asCScriptEngine();
  192. //protected:
  193. friend class asCBuilder;
  194. friend class asCCompiler;
  195. friend class asCContext;
  196. friend class asCDataType;
  197. friend class asCModule;
  198. friend class asCRestore;
  199. friend class asCByteCode;
  200. friend int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine);
  201. int RegisterMethodToObjectType(asCObjectType *objectType, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0);
  202. int RegisterBehaviourToObjectType(asCObjectType *objectType, asEBehaviours behaviour, const char *decl, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0);
  203. int VerifyVarTypeNotInFunction(asCScriptFunction *func);
  204. void *CallAlloc(const asCObjectType *objType) const;
  205. void CallFree(void *obj) const;
  206. void *CallGlobalFunctionRetPtr(int func) const;
  207. void *CallGlobalFunctionRetPtr(int func, void *param1) const;
  208. void *CallGlobalFunctionRetPtr(asSSystemFunctionInterface *func, asCScriptFunction *desc) const;
  209. void *CallGlobalFunctionRetPtr(asSSystemFunctionInterface *i, asCScriptFunction *s, void *param1) const;
  210. void CallObjectMethod(void *obj, int func) const;
  211. void CallObjectMethod(void *obj, void *param, int func) const;
  212. void CallObjectMethod(void *obj, asSSystemFunctionInterface *func, asCScriptFunction *desc) const;
  213. void CallObjectMethod(void *obj, void *param, asSSystemFunctionInterface *func, asCScriptFunction *desc) const;
  214. bool CallObjectMethodRetBool(void *obj, int func) const;
  215. int CallObjectMethodRetInt(void *obj, int func) const;
  216. void *CallObjectMethodRetPtr(void *obj, int func) const;
  217. void *CallObjectMethodRetPtr(void *obj, int param1, asCScriptFunction *func) const;
  218. void CallGlobalFunction(void *param1, void *param2, asSSystemFunctionInterface *func, asCScriptFunction *desc) const;
  219. bool CallGlobalFunctionRetBool(void *param1, void *param2, asSSystemFunctionInterface *func, asCScriptFunction *desc) const;
  220. int CallScriptObjectMethod(void *obj, int func);
  221. void ConstructScriptObjectCopy(void *mem, void *obj, asCObjectType *type);
  222. void DeleteDiscardedModules();
  223. void RemoveTemplateInstanceType(asCObjectType *t);
  224. asCConfigGroup *FindConfigGroupForFunction(int funcId) const;
  225. asCConfigGroup *FindConfigGroupForGlobalVar(int gvarId) const;
  226. asCConfigGroup *FindConfigGroupForTypeInfo(const asCTypeInfo *type) const;
  227. asCConfigGroup *FindConfigGroupForFuncDef(const asCFuncdefType *funcDef) const;
  228. int RequestBuild();
  229. void BuildCompleted();
  230. void PrepareEngine();
  231. bool isPrepared;
  232. int CreateContext(asIScriptContext **context, bool isInternal);
  233. asCTypeInfo *GetRegisteredType(const asCString &name, asSNameSpace *ns) const;
  234. asCObjectType *GetListPatternType(int listPatternFuncId);
  235. void DestroyList(asBYTE *buffer, const asCObjectType *listPatternType);
  236. void DestroySubList(asBYTE *&buffer, asSListPatternNode *&patternNode);
  237. int AddBehaviourFunction(asCScriptFunction &func, asSSystemFunctionInterface &internal);
  238. asCString GetFunctionDeclaration(int funcId);
  239. asCScriptFunction *GetScriptFunction(int funcId) const;
  240. asCModule *GetModule(const char *name, bool create);
  241. asCModule *GetModuleFromFuncId(int funcId);
  242. int GetMethodIdByDecl(const asCObjectType *ot, const char *decl, asCModule *mod);
  243. int GetFactoryIdByDecl(const asCObjectType *ot, const char *decl);
  244. int GetNextScriptFunctionId();
  245. void AddScriptFunction(asCScriptFunction *func);
  246. void RemoveScriptFunction(asCScriptFunction *func);
  247. void RemoveFuncdef(asCFuncdefType *func);
  248. int ConfigError(int err, const char *funcName, const char *arg1, const char *arg2);
  249. int GetTypeIdFromDataType(const asCDataType &dt) const;
  250. asCDataType GetDataTypeFromTypeId(int typeId) const;
  251. asCObjectType *GetObjectTypeFromTypeId(int typeId) const;
  252. void RemoveFromTypeIdMap(asCTypeInfo *type);
  253. bool IsTemplateType(const char *name) const;
  254. int SetTemplateRestrictions(asCObjectType *templateType, asCScriptFunction *func, const char *caller, const char *decl);
  255. asCObjectType *GetTemplateInstanceType(asCObjectType *templateType, asCArray<asCDataType> &subTypes, asCModule *requestingModule);
  256. asCScriptFunction *GenerateTemplateFactoryStub(asCObjectType *templateType, asCObjectType *templateInstanceType, int origFactoryId);
  257. bool GenerateNewTemplateFunction(asCObjectType *templateType, asCObjectType *templateInstanceType, asCScriptFunction *templateFunc, asCScriptFunction **newFunc);
  258. asCFuncdefType *GenerateNewTemplateFuncdef(asCObjectType *templateType, asCObjectType *templateInstanceType, asCFuncdefType *templateFuncdef);
  259. asCDataType DetermineTypeForTemplate(const asCDataType &orig, asCObjectType *tmpl, asCObjectType *ot);
  260. bool RequireTypeReplacement(asCDataType &type, asCObjectType *templateType);
  261. asCModule *FindNewOwnerForSharedType(asCTypeInfo *type, asCModule *mod);
  262. asCModule *FindNewOwnerForSharedFunc(asCScriptFunction *func, asCModule *mod);
  263. asCFuncdefType *FindMatchingFuncdef(asCScriptFunction *func, asCModule *mod);
  264. // String constants
  265. // TODO: Must free unused string constants, thus the ref count for each must be tracked
  266. int AddConstantString(const char *str, size_t length);
  267. const asCString &GetConstantString(int id);
  268. // Global property management
  269. asCGlobalProperty *AllocateGlobalProperty();
  270. void RemoveGlobalProperty(asCGlobalProperty *prop);
  271. int GetScriptSectionNameIndex(const char *name);
  272. // Namespace management
  273. asSNameSpace *AddNameSpace(const char *name);
  274. asSNameSpace *FindNameSpace(const char *name) const;
  275. asSNameSpace *GetParentNameSpace(asSNameSpace *ns) const;
  276. //===========================================================
  277. // internal properties
  278. //===========================================================
  279. asCMemoryMgr memoryMgr;
  280. asUINT initialContextStackSize;
  281. asCObjectType *defaultArrayObjectType;
  282. asCObjectType scriptTypeBehaviours;
  283. asCObjectType functionBehaviours;
  284. // Registered interface
  285. asCArray<asCObjectType *> registeredObjTypes; // doesn't increase ref count
  286. asCArray<asCTypedefType *> registeredTypeDefs; // doesn't increase ref count
  287. asCArray<asCEnumType *> registeredEnums; // doesn't increase ref count
  288. // TODO: memory savings: Since there can be only one property with the same name a simpler symbol table should be used for global props
  289. asCSymbolTable<asCGlobalProperty> registeredGlobalProps; // increases ref count
  290. asCSymbolTable<asCScriptFunction> registeredGlobalFuncs;
  291. asCArray<asCFuncdefType *> registeredFuncDefs; // doesn't increase ref count
  292. asCArray<asCObjectType *> registeredTemplateTypes; // doesn't increase ref count
  293. asCScriptFunction *stringFactory;
  294. bool configFailed;
  295. // Stores all registered types
  296. asCMap<asSNameSpaceNamePair, asCTypeInfo*> allRegisteredTypes; // increases ref count
  297. // Dummy types used to name the subtypes in the template objects
  298. asCArray<asCTypeInfo *> templateSubTypes;
  299. // Store information about template types
  300. // This list will contain all instances of templates, both registered specialized
  301. // types and those automacially instantiated from scripts
  302. asCArray<asCObjectType *> templateInstanceTypes; // increases ref count
  303. // Store information about list patterns
  304. asCArray<asCObjectType *> listPatternTypes; // increases ref count
  305. // Stores all global properties, both those registered by application, and those declared by scripts.
  306. // The id of a global property is the index in this array.
  307. asCArray<asCGlobalProperty *> globalProperties; // increases ref count
  308. asCArray<int> freeGlobalPropertyIds;
  309. // This map is used to quickly find a property by its memory address
  310. // It is used principally during building, cleanup, and garbage detection for script functions
  311. asCMap<void*, asCGlobalProperty*> varAddressMap; // doesn't increase ref count
  312. // Stores all functions, i.e. registered functions, script functions, class methods, behaviours, etc.
  313. asCArray<asCScriptFunction *> scriptFunctions; // doesn't increase ref count
  314. asCArray<int> freeScriptFunctionIds;
  315. asCArray<asCScriptFunction *> signatureIds;
  316. // An array with all module imported functions
  317. asCArray<sBindInfo *> importedFunctions; // doesn't increase ref count
  318. asCArray<int> freeImportedFunctionIdxs;
  319. // Synchronized
  320. mutable asCAtomic refCount;
  321. // Synchronized with engineRWLock
  322. // This array holds all live script modules
  323. asCArray<asCModule *> scriptModules;
  324. // Synchronized with engineRWLock
  325. // This is a pointer to the last module that was requested. It is used for performance
  326. // improvement, since it is common that the same module is accessed many times in a row
  327. asCModule *lastModule;
  328. // Synchronized with engineRWLock
  329. // This flag is true if a script is currently being compiled. It is used to prevent multiple
  330. // threads from requesting builds at the same time (without blocking)
  331. bool isBuilding;
  332. // Synchronized with engineRWLock
  333. // This array holds modules that have been discard (thus are no longer visible to the application)
  334. // but cannot yet be deleted due to having external references to some of the entities in them
  335. asCArray<asCModule *> discardedModules;
  336. // This flag is set to true during compilations of scripts (or loading pre-compiled scripts)
  337. // to delay the validation of template types until the subtypes have been fully declared
  338. bool deferValidationOfTemplateTypes;
  339. // Tokenizer is instantiated once to share resources
  340. asCTokenizer tok;
  341. // Stores shared script declared types (classes, interfaces, enums)
  342. asCArray<asCTypeInfo *> sharedScriptTypes; // increases ref count
  343. // This array stores the template instances types that have been automatically generated from template types
  344. asCArray<asCObjectType *> generatedTemplateTypes;
  345. // Stores the funcdefs
  346. // TODO: redesign: Only shared funcdefs should be stored here
  347. // a funcdef becomes shared if all arguments and the return type are shared (or application registered)
  348. asCArray<asCFuncdefType *> funcDefs; // doesn't increases ref count
  349. // Stores the names of the script sections for debugging purposes
  350. asCArray<asCString *> scriptSectionNames;
  351. // Type identifiers
  352. mutable int typeIdSeqNbr;
  353. mutable asCMap<int, asCTypeInfo*> mapTypeIdToTypeInfo;
  354. // Garbage collector
  355. asCGarbageCollector gc;
  356. // Dynamic groups
  357. asCConfigGroup defaultGroup;
  358. asCArray<asCConfigGroup*> configGroups;
  359. asCConfigGroup *currentGroup;
  360. asDWORD defaultAccessMask;
  361. asSNameSpace *defaultNamespace;
  362. // Message callback
  363. bool msgCallback;
  364. asSSystemFunctionInterface msgCallbackFunc;
  365. void *msgCallbackObj;
  366. struct preMessage_t
  367. {
  368. preMessage_t() { isSet = false; }
  369. bool isSet;
  370. asCString message;
  371. asCString scriptname;
  372. int r;
  373. int c;
  374. } preMessage;
  375. // JIt compilation
  376. asIJITCompiler *jitCompiler;
  377. // Namespaces
  378. // These are shared between all entities and are
  379. // only deleted once the engine is destroyed
  380. asCArray<asSNameSpace*> nameSpaces;
  381. // String constants
  382. // These are shared between all scripts and are
  383. // only deleted once the engine is destroyed
  384. asCArray<asCString*> stringConstants;
  385. asCMap<asCStringPointer, int> stringToIdMap;
  386. // Callbacks for context pooling
  387. asREQUESTCONTEXTFUNC_t requestCtxFunc;
  388. asRETURNCONTEXTFUNC_t returnCtxFunc;
  389. void *ctxCallbackParam;
  390. // User data
  391. asCArray<asPWORD> userData;
  392. struct SEngineClean { asPWORD type; asCLEANENGINEFUNC_t cleanFunc; };
  393. asCArray<SEngineClean> cleanEngineFuncs;
  394. struct SModuleClean { asPWORD type; asCLEANMODULEFUNC_t cleanFunc; };
  395. asCArray<SModuleClean> cleanModuleFuncs;
  396. struct SContextClean { asPWORD type; asCLEANCONTEXTFUNC_t cleanFunc; };
  397. asCArray<SContextClean> cleanContextFuncs;
  398. struct SFunctionClean { asPWORD type; asCLEANFUNCTIONFUNC_t cleanFunc; };
  399. asCArray<SFunctionClean> cleanFunctionFuncs;
  400. struct STypeInfoClean { asPWORD type; asCLEANTYPEINFOFUNC_t cleanFunc; };
  401. asCArray<STypeInfoClean> cleanTypeInfoFuncs;
  402. struct SScriptObjClean { asPWORD type; asCLEANSCRIPTOBJECTFUNC_t cleanFunc; };
  403. asCArray<SScriptObjClean> cleanScriptObjectFuncs;
  404. // Synchronization for threads
  405. DECLAREREADWRITELOCK(mutable engineRWLock)
  406. // Engine properties
  407. struct
  408. {
  409. bool allowUnsafeReferences;
  410. bool optimizeByteCode;
  411. bool copyScriptSections;
  412. asUINT maximumContextStackSize;
  413. bool useCharacterLiterals;
  414. bool allowMultilineStrings;
  415. bool allowImplicitHandleTypes;
  416. bool buildWithoutLineCues;
  417. bool initGlobalVarsAfterBuild;
  418. bool requireEnumScope;
  419. int scanner;
  420. bool includeJitInstructions;
  421. int stringEncoding;
  422. int propertyAccessorMode;
  423. bool expandDefaultArrayToTemplate;
  424. bool autoGarbageCollect;
  425. bool disallowGlobalVars;
  426. bool alwaysImplDefaultConstruct;
  427. int compilerWarnings;
  428. bool disallowValueAssignForRefType;
  429. // TODO: 3.0.0: Remove the alterSyntaxNamedArgs
  430. int alterSyntaxNamedArgs;
  431. bool disableIntegerDivision;
  432. bool disallowEmptyListElements;
  433. // TODO: 3.0.0: Remove the privatePropAsProtected
  434. bool privatePropAsProtected;
  435. bool allowUnicodeIdentifiers;
  436. int heredocTrimMode;
  437. } ep;
  438. // This flag is to allow a quicker shutdown when releasing the engine
  439. bool shuttingDown;
  440. // This flag is set when the engine's destructor is called, this is to
  441. // avoid recursive calls if an object happens to increment/decrement
  442. // the ref counter during shutdown
  443. bool inDestructor;
  444. };
  445. END_AS_NAMESPACE
  446. #endif