ToluaUtils.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "OctreeQuery.h"
  24. #include "PhysicsWorld.h"
  25. #include "Vector2.h"
  26. #include "Vector3.h"
  27. struct lua_State;
  28. namespace Urho3D
  29. {
  30. class Context;
  31. class SoundSource;
  32. class UIElement;
  33. }
  34. using namespace Urho3D;
  35. /// Check is String.
  36. #define tolua_isurho3dstring tolua_isstring
  37. /// Push String.
  38. #define tolua_pushurho3dstring(x, y) tolua_pushstring(x, y.CString())
  39. /// Convert to String.
  40. const char* tolua_tourho3dstring(lua_State* L, int narg, const char* str);
  41. /// Convert to String.
  42. const char* tolua_tourho3dstring(lua_State* L, int narg, const String& str);
  43. /// Set context.
  44. void SetContext(lua_State* L, Context* context);
  45. /// Return context.
  46. Context* GetContext(lua_State* L);
  47. /// Create new object.
  48. template<typename T> int ToluaNewObject(lua_State* tolua_S)
  49. {
  50. T* object = Mtolua_new(T(GetContext(tolua_S)));
  51. tolua_pushusertype(tolua_S, (void*)object,T::GetTypeNameStatic().CString());
  52. return 1;
  53. }
  54. /// Create new object with GC.
  55. template<typename T> int ToluaNewObjectGC(lua_State* tolua_S)
  56. {
  57. T* object = Mtolua_new(T(GetContext(tolua_S)));
  58. tolua_pushusertype(tolua_S, (void*)object,T::GetTypeNameStatic().CString());
  59. tolua_register_gc(tolua_S, lua_gettop(tolua_S));
  60. return 1;
  61. }
  62. /// Check Lua table is Vector<T>.
  63. template<typename T> int ToluaIsVector(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
  64. /// Check Lua table is Vector<String>.
  65. template<> int ToluaIsVector<String>(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
  66. /// Convert Lua table to Vector<T>.
  67. template<typename T> void* ToluaToVector(lua_State* L, int narg, void* def);
  68. /// Convert Lua table to Vector<String>.
  69. template<> void* ToluaToVector<String>(lua_State* L, int narg, void* def);
  70. /// Push Vector<T> to Lua as a table.
  71. template<typename T> int ToluaPushVector(lua_State*L, void* data, const char* type);
  72. /// Push Vector<String> to Lua as a table.
  73. template<> int ToluaPushVector<String>(lua_State* L, void* data, const char* type);
  74. /// Check Lua table is Vector<T>.
  75. template<typename T> int ToluaIsPODVector(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
  76. /// Check Lua table is Vector<unsigned>.
  77. template<> int ToluaIsPODVector<unsigned>(lua_State* L, int lo, const char* type, int def, tolua_Error* err);
  78. /// Convert Lua table to PODVector<T>.
  79. template<typename T> void* ToluaToPODVector(lua_State* L, int narg, void* def);
  80. /// Convert Lua table to PODVector<unsigned>.
  81. template<> void* ToluaToPODVector<unsigned>(lua_State* L, int narg, void* def);
  82. /// Push PODVector<T> to Lua as a table.
  83. template<typename T> int ToluaPushPODVector(lua_State* L, void* data, const char* type);
  84. /// Push PODVector<int> to Lua as a table.
  85. template<> int ToluaPushPODVector<int>(lua_State* L, void* data, const char* type);
  86. /// Push PODVector<unsigned> to Lua as a table.
  87. template<> int ToluaPushPODVector<unsigned>(lua_State* L, void* data, const char* type);
  88. /// Push PODVector<SoundSource*> to Lua as a table.
  89. template<> int ToluaPushPODVector<SoundSource*>(lua_State* L, void* data, const char* type);
  90. /// Push PODVector<UIElement*> to Lua as a table.
  91. template<> int ToluaPushPODVector<UIElement*>(lua_State* L, void* data, const char* type);
  92. /// Push PODVector<Vector3> to Lua as a table.
  93. template<> int ToluaPushPODVector<Vector3>(lua_State* L, void* data, const char* type);
  94. /// Push PODVector<IntVector2> to Lua as a table.
  95. template<> int ToluaPushPODVector<IntVector2>(lua_State* L, void* data, const char* type);
  96. /// Push PODVector<OctreeQueryResult> to Lua as a table.
  97. template<> int ToluaPushPODVector<OctreeQueryResult>(lua_State* L, void* data, const char* type);
  98. /// Push PODVector<PhysicsRaycastResult> to Lua as a table.
  99. template<> int ToluaPushPODVector<PhysicsRaycastResult>(lua_State* L, void* data, const char* type);
  100. /// Push PODVector<RayQueryResult> to Lua as a table.
  101. template<> int ToluaPushPODVector<RayQueryResult>(lua_State* L, void* data, const char* type);