lua_MathUtil.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_MathUtil.h"
  4. #include "Base.h"
  5. #include "MathUtil.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_MathUtil()
  9. {
  10. const luaL_Reg lua_members[] =
  11. {
  12. {NULL, NULL}
  13. };
  14. const luaL_Reg lua_statics[] =
  15. {
  16. {"smooth", lua_MathUtil_static_smooth},
  17. {NULL, NULL}
  18. };
  19. std::vector<std::string> scopePath;
  20. gameplay::ScriptUtil::registerClass("MathUtil", lua_members, NULL, lua_MathUtil__gc, lua_statics, scopePath);
  21. }
  22. static MathUtil* getInstance(lua_State* state)
  23. {
  24. void* userdata = luaL_checkudata(state, 1, "MathUtil");
  25. luaL_argcheck(state, userdata != NULL, 1, "'MathUtil' expected.");
  26. return (MathUtil*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  27. }
  28. int lua_MathUtil__gc(lua_State* state)
  29. {
  30. // Get the number of parameters.
  31. int paramCount = lua_gettop(state);
  32. // Attempt to match the parameters to a valid binding.
  33. switch (paramCount)
  34. {
  35. case 1:
  36. {
  37. if ((lua_type(state, 1) == LUA_TUSERDATA))
  38. {
  39. void* userdata = luaL_checkudata(state, 1, "MathUtil");
  40. luaL_argcheck(state, userdata != NULL, 1, "'MathUtil' expected.");
  41. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)userdata;
  42. if (object->owns)
  43. {
  44. MathUtil* instance = (MathUtil*)object->instance;
  45. SAFE_DELETE(instance);
  46. }
  47. return 0;
  48. }
  49. lua_pushstring(state, "lua_MathUtil__gc - Failed to match the given parameters to a valid function signature.");
  50. lua_error(state);
  51. break;
  52. }
  53. default:
  54. {
  55. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  56. lua_error(state);
  57. break;
  58. }
  59. }
  60. return 0;
  61. }
  62. int lua_MathUtil_static_smooth(lua_State* state)
  63. {
  64. // Get the number of parameters.
  65. int paramCount = lua_gettop(state);
  66. // Attempt to match the parameters to a valid binding.
  67. switch (paramCount)
  68. {
  69. case 4:
  70. {
  71. do
  72. {
  73. if ((lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TLIGHTUSERDATA) &&
  74. lua_type(state, 2) == LUA_TNUMBER &&
  75. lua_type(state, 3) == LUA_TNUMBER &&
  76. lua_type(state, 4) == LUA_TNUMBER)
  77. {
  78. // Get parameter 1 off the stack.
  79. gameplay::ScriptUtil::LuaArray<float> param1 = gameplay::ScriptUtil::getFloatPointer(1);
  80. // Get parameter 2 off the stack.
  81. float param2 = (float)luaL_checknumber(state, 2);
  82. // Get parameter 3 off the stack.
  83. float param3 = (float)luaL_checknumber(state, 3);
  84. // Get parameter 4 off the stack.
  85. float param4 = (float)luaL_checknumber(state, 4);
  86. MathUtil::smooth(param1, param2, param3, param4);
  87. return 0;
  88. }
  89. } while (0);
  90. lua_pushstring(state, "lua_MathUtil_static_smooth - Failed to match the given parameters to a valid function signature.");
  91. lua_error(state);
  92. break;
  93. }
  94. case 5:
  95. {
  96. do
  97. {
  98. if ((lua_type(state, 1) == LUA_TTABLE || lua_type(state, 1) == LUA_TLIGHTUSERDATA) &&
  99. lua_type(state, 2) == LUA_TNUMBER &&
  100. lua_type(state, 3) == LUA_TNUMBER &&
  101. lua_type(state, 4) == LUA_TNUMBER &&
  102. lua_type(state, 5) == LUA_TNUMBER)
  103. {
  104. // Get parameter 1 off the stack.
  105. gameplay::ScriptUtil::LuaArray<float> param1 = gameplay::ScriptUtil::getFloatPointer(1);
  106. // Get parameter 2 off the stack.
  107. float param2 = (float)luaL_checknumber(state, 2);
  108. // Get parameter 3 off the stack.
  109. float param3 = (float)luaL_checknumber(state, 3);
  110. // Get parameter 4 off the stack.
  111. float param4 = (float)luaL_checknumber(state, 4);
  112. // Get parameter 5 off the stack.
  113. float param5 = (float)luaL_checknumber(state, 5);
  114. MathUtil::smooth(param1, param2, param3, param4, param5);
  115. return 0;
  116. }
  117. } while (0);
  118. lua_pushstring(state, "lua_MathUtil_static_smooth - Failed to match the given parameters to a valid function signature.");
  119. lua_error(state);
  120. break;
  121. }
  122. default:
  123. {
  124. lua_pushstring(state, "Invalid number of parameters (expected 4 or 5).");
  125. lua_error(state);
  126. break;
  127. }
  128. }
  129. return 0;
  130. }
  131. }