/xbmc/visualizations/Vortex/angelscript/angelscript/source/as_module.h

http://github.com/xbmc/xbmc · C++ Header · 213 lines · 107 code · 41 blank · 65 comment · 0 complexity · 63ded9d0aadfb78e4da14d37867f22c7 MD5 · raw file

  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. // as_module.h
  25. //
  26. // A class that holds a script module
  27. //
  28. #ifndef AS_MODULE_H
  29. #define AS_MODULE_H
  30. #include "as_config.h"
  31. #include "as_atomic.h"
  32. #include "as_string.h"
  33. #include "as_array.h"
  34. #include "as_datatype.h"
  35. #include "as_scriptfunction.h"
  36. #include "as_property.h"
  37. BEGIN_AS_NAMESPACE
  38. // TODO: import: Remove this when the imported functions are removed
  39. const int FUNC_IMPORTED = 0x40000000;
  40. class asCScriptEngine;
  41. class asCCompiler;
  42. class asCBuilder;
  43. class asCContext;
  44. class asCConfigGroup;
  45. struct sBindInfo
  46. {
  47. asCScriptFunction *importedFunctionSignature;
  48. asCString importFromModule;
  49. int boundFunctionId;
  50. };
  51. struct sObjectTypePair
  52. {
  53. asCObjectType *a;
  54. asCObjectType *b;
  55. };
  56. // TODO: import: Remove function imports. When I have implemented function
  57. // pointers the function imports should be deprecated.
  58. // TODO: Need a separate interface for compiling scripts. The asIScriptCompiler
  59. // will have a target module, and will allow the compilation of an entire
  60. // script or just individual functions within the scope of the module
  61. //
  62. // With this separation it will be possible to compile the library without
  63. // the compiler, thus giving a much smaller binary executable.
  64. class asCModule : public asIScriptModule
  65. {
  66. //-------------------------------------------
  67. // Public interface
  68. //--------------------------------------------
  69. public:
  70. virtual asIScriptEngine *GetEngine();
  71. virtual void SetName(const char *name);
  72. virtual const char *GetName();
  73. // Compilation
  74. virtual int AddScriptSection(const char *name, const char *code, size_t codeLength, int lineOffset);
  75. virtual int Build();
  76. virtual int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD reserved, asIScriptFunction **outFunc);
  77. virtual int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset);
  78. // Script functions
  79. virtual int GetFunctionCount();
  80. virtual int GetFunctionIdByIndex(int index);
  81. virtual int GetFunctionIdByName(const char *name);
  82. virtual int GetFunctionIdByDecl(const char *decl);
  83. virtual asIScriptFunction *GetFunctionDescriptorByIndex(int index);
  84. virtual asIScriptFunction *GetFunctionDescriptorById(int funcId);
  85. virtual int RemoveFunction(int funcId);
  86. // Script global variables
  87. virtual int ResetGlobalVars();
  88. virtual int GetGlobalVarCount();
  89. virtual int GetGlobalVarIndexByName(const char *name);
  90. virtual int GetGlobalVarIndexByDecl(const char *decl);
  91. virtual const char *GetGlobalVarDeclaration(int index);
  92. virtual const char *GetGlobalVarName(int index);
  93. virtual int GetGlobalVarTypeId(int index, bool *isConst);
  94. virtual void *GetAddressOfGlobalVar(int index);
  95. virtual int RemoveGlobalVar(int index);
  96. // Type identification
  97. virtual int GetObjectTypeCount();
  98. virtual asIObjectType *GetObjectTypeByIndex(asUINT index);
  99. virtual int GetTypeIdByDecl(const char *decl);
  100. // Enums
  101. virtual int GetEnumCount();
  102. virtual const char *GetEnumByIndex(asUINT index, int *enumTypeId);
  103. virtual int GetEnumValueCount(int enumTypeId);
  104. virtual const char *GetEnumValueByIndex(int enumTypeId, asUINT index, int *outValue);
  105. // Typedefs
  106. virtual int GetTypedefCount();
  107. virtual const char *GetTypedefByIndex(asUINT index, int *typeId);
  108. // Dynamic binding between modules
  109. virtual int GetImportedFunctionCount();
  110. virtual int GetImportedFunctionIndexByDecl(const char *decl);
  111. virtual const char *GetImportedFunctionDeclaration(int importIndex);
  112. virtual const char *GetImportedFunctionSourceModule(int importIndex);
  113. virtual int BindImportedFunction(int index, int sourceID);
  114. virtual int UnbindImportedFunction(int importIndex);
  115. virtual int BindAllImportedFunctions();
  116. virtual int UnbindAllImportedFunctions();
  117. // Bytecode Saving/Loading
  118. virtual int SaveByteCode(asIBinaryStream *out);
  119. virtual int LoadByteCode(asIBinaryStream *in);
  120. //-----------------------------------------------
  121. // Internal
  122. //-----------------------------------------------
  123. asCModule(const char *name, asCScriptEngine *engine);
  124. ~asCModule();
  125. //protected:
  126. friend class asCScriptEngine;
  127. friend class asCBuilder;
  128. friend class asCCompiler;
  129. friend class asCContext;
  130. friend class asCRestore;
  131. void InternalReset();
  132. int CallInit();
  133. void CallExit();
  134. void JITCompile();
  135. int AddScriptFunction(int sectionIdx, int id, const char *name, const asCDataType &returnType, asCDataType *params, asETypeModifiers *inOutFlags, int paramCount, bool isInterface, asCObjectType *objType = 0, bool isConstMethod = false, bool isGlobalFunction = false);
  136. int AddScriptFunction(asCScriptFunction *func);
  137. int AddImportedFunction(int id, const char *name, const asCDataType &returnType, asCDataType *params, asETypeModifiers *inOutFlags, int paramCount, const asCString &moduleName);
  138. int GetNextImportedFunctionId();
  139. void ResolveInterfaceIds();
  140. bool AreInterfacesEqual(asCObjectType *a, asCObjectType *b, asCArray<sObjectTypePair> &equals);
  141. bool AreTypesEqual(const asCDataType &a, const asCDataType &b, asCArray<sObjectTypePair> &equals);
  142. asCScriptFunction *GetImportedFunction(int funcId);
  143. asCObjectType *GetObjectType(const char *type);
  144. asCGlobalProperty *AllocateGlobalProperty(const char *name, const asCDataType &dt);
  145. asCString name;
  146. asCScriptEngine *engine;
  147. asCBuilder *builder;
  148. // This array holds all functions, class members, factories, etc that were compiled with the module
  149. asCArray<asCScriptFunction *> scriptFunctions;
  150. // This array holds global functions declared in the module
  151. asCArray<asCScriptFunction *> globalFunctions;
  152. // This array holds imported functions in the module
  153. asCArray<sBindInfo *> bindInformations;
  154. // This array holds the global variables declared in the script
  155. asCArray<asCGlobalProperty *> scriptGlobals;
  156. bool isGlobalVarInitialized;
  157. // This array holds class and interface types
  158. asCArray<asCObjectType*> classTypes;
  159. // This array holds enum types
  160. asCArray<asCObjectType*> enumTypes;
  161. // This array holds typedefs
  162. asCArray<asCObjectType*> typeDefs;
  163. };
  164. END_AS_NAMESPACE
  165. #endif