as_callfunc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. AngelCode Scripting Library
  3. Copyright (c) 2003-2014 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. //
  24. // as_callfunc.h
  25. //
  26. // These functions handle the actual calling of system functions
  27. //
  28. #ifndef AS_CALLFUNC_H
  29. #define AS_CALLFUNC_H
  30. #include "as_array.h"
  31. BEGIN_AS_NAMESPACE
  32. class asCContext;
  33. class asCScriptEngine;
  34. class asCScriptFunction;
  35. struct asSSystemFunctionInterface;
  36. int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, void *objForThiscall, asSSystemFunctionInterface *internal);
  37. int PrepareSystemFunctionGeneric(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine);
  38. int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *internal, asCScriptEngine *engine);
  39. int CallSystemFunction(int id, asCContext *context, void *objectPointer);
  40. inline asPWORD FuncPtrToUInt(asFUNCTION_t func)
  41. {
  42. // A little trickery as the C++ standard doesn't allow direct
  43. // conversion between function pointer and data pointer
  44. union { asFUNCTION_t func; asPWORD idx; } u;
  45. u.func = func;
  46. return u.idx;
  47. }
  48. enum internalCallConv
  49. {
  50. ICC_GENERIC_FUNC,
  51. ICC_GENERIC_FUNC_RETURNINMEM, // never used
  52. ICC_CDECL,
  53. ICC_CDECL_RETURNINMEM,
  54. ICC_STDCALL,
  55. ICC_STDCALL_RETURNINMEM,
  56. ICC_THISCALL,
  57. ICC_THISCALL_RETURNINMEM,
  58. ICC_VIRTUAL_THISCALL,
  59. ICC_VIRTUAL_THISCALL_RETURNINMEM,
  60. ICC_CDECL_OBJLAST,
  61. ICC_CDECL_OBJLAST_RETURNINMEM,
  62. ICC_CDECL_OBJFIRST,
  63. ICC_CDECL_OBJFIRST_RETURNINMEM,
  64. ICC_GENERIC_METHOD,
  65. ICC_GENERIC_METHOD_RETURNINMEM, // never used
  66. ICC_THISCALL_OBJLAST,
  67. ICC_THISCALL_OBJLAST_RETURNINMEM,
  68. ICC_VIRTUAL_THISCALL_OBJLAST,
  69. ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM,
  70. ICC_THISCALL_OBJFIRST,
  71. ICC_THISCALL_OBJFIRST_RETURNINMEM,
  72. ICC_VIRTUAL_THISCALL_OBJFIRST,
  73. ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM
  74. };
  75. struct asSSystemFunctionInterface
  76. {
  77. asFUNCTION_t func;
  78. int baseOffset;
  79. internalCallConv callConv;
  80. int scriptReturnSize;
  81. bool hostReturnInMemory;
  82. bool hostReturnFloat;
  83. int hostReturnSize;
  84. int paramSize;
  85. bool takesObjByVal;
  86. asCArray<bool> paramAutoHandles;
  87. bool returnAutoHandle;
  88. bool hasAutoHandles;
  89. void *objForThiscall;
  90. asSSystemFunctionInterface() {}
  91. asSSystemFunctionInterface(const asSSystemFunctionInterface &in)
  92. {
  93. *this = in;
  94. }
  95. asSSystemFunctionInterface &operator=(const asSSystemFunctionInterface &in)
  96. {
  97. func = in.func;
  98. baseOffset = in.baseOffset;
  99. callConv = in.callConv;
  100. scriptReturnSize = in.scriptReturnSize;
  101. hostReturnInMemory = in.hostReturnInMemory;
  102. hostReturnFloat = in.hostReturnFloat;
  103. hostReturnSize = in.hostReturnSize;
  104. paramSize = in.paramSize;
  105. takesObjByVal = in.takesObjByVal;
  106. paramAutoHandles = in.paramAutoHandles;
  107. returnAutoHandle = in.returnAutoHandle;
  108. hasAutoHandles = in.hasAutoHandles;
  109. objForThiscall = in.objForThiscall;
  110. return *this;
  111. }
  112. };
  113. END_AS_NAMESPACE
  114. #endif