2
0

lua_AnimationValue.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_AnimationValue.h"
  4. #include "AnimationValue.h"
  5. #include "Base.h"
  6. namespace gameplay
  7. {
  8. void luaRegister_AnimationValue()
  9. {
  10. const luaL_Reg lua_members[] =
  11. {
  12. {"getFloat", lua_AnimationValue_getFloat},
  13. {"getFloats", lua_AnimationValue_getFloats},
  14. {"setFloat", lua_AnimationValue_setFloat},
  15. {"setFloats", lua_AnimationValue_setFloats},
  16. {NULL, NULL}
  17. };
  18. const luaL_Reg* lua_statics = NULL;
  19. std::vector<std::string> scopePath;
  20. ScriptUtil::registerClass("AnimationValue", lua_members, NULL, NULL, lua_statics, scopePath);
  21. }
  22. static AnimationValue* getInstance(lua_State* state)
  23. {
  24. void* userdata = luaL_checkudata(state, 1, "AnimationValue");
  25. luaL_argcheck(state, userdata != NULL, 1, "'AnimationValue' expected.");
  26. return (AnimationValue*)((ScriptUtil::LuaObject*)userdata)->instance;
  27. }
  28. int lua_AnimationValue_getFloat(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 2:
  36. {
  37. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  38. lua_type(state, 2) == LUA_TNUMBER)
  39. {
  40. // Get parameter 1 off the stack.
  41. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  42. AnimationValue* instance = getInstance(state);
  43. float result = instance->getFloat(param1);
  44. // Push the return value onto the stack.
  45. lua_pushnumber(state, result);
  46. return 1;
  47. }
  48. else
  49. {
  50. lua_pushstring(state, "lua_AnimationValue_getFloat - Failed to match the given parameters to a valid function signature.");
  51. lua_error(state);
  52. }
  53. break;
  54. }
  55. default:
  56. {
  57. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  58. lua_error(state);
  59. break;
  60. }
  61. }
  62. return 0;
  63. }
  64. int lua_AnimationValue_getFloats(lua_State* state)
  65. {
  66. // Get the number of parameters.
  67. int paramCount = lua_gettop(state);
  68. // Attempt to match the parameters to a valid binding.
  69. switch (paramCount)
  70. {
  71. case 4:
  72. {
  73. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  74. lua_type(state, 2) == LUA_TNUMBER &&
  75. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
  76. lua_type(state, 4) == LUA_TNUMBER)
  77. {
  78. // Get parameter 1 off the stack.
  79. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  80. // Get parameter 2 off the stack.
  81. ScriptUtil::LuaArray<float> param2 = ScriptUtil::getFloatPointer(3);
  82. // Get parameter 3 off the stack.
  83. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  84. AnimationValue* instance = getInstance(state);
  85. instance->getFloats(param1, param2, param3);
  86. return 0;
  87. }
  88. else
  89. {
  90. lua_pushstring(state, "lua_AnimationValue_getFloats - Failed to match the given parameters to a valid function signature.");
  91. lua_error(state);
  92. }
  93. break;
  94. }
  95. default:
  96. {
  97. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  98. lua_error(state);
  99. break;
  100. }
  101. }
  102. return 0;
  103. }
  104. int lua_AnimationValue_setFloat(lua_State* state)
  105. {
  106. // Get the number of parameters.
  107. int paramCount = lua_gettop(state);
  108. // Attempt to match the parameters to a valid binding.
  109. switch (paramCount)
  110. {
  111. case 3:
  112. {
  113. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  114. lua_type(state, 2) == LUA_TNUMBER &&
  115. lua_type(state, 3) == LUA_TNUMBER)
  116. {
  117. // Get parameter 1 off the stack.
  118. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  119. // Get parameter 2 off the stack.
  120. float param2 = (float)luaL_checknumber(state, 3);
  121. AnimationValue* instance = getInstance(state);
  122. instance->setFloat(param1, param2);
  123. return 0;
  124. }
  125. else
  126. {
  127. lua_pushstring(state, "lua_AnimationValue_setFloat - Failed to match the given parameters to a valid function signature.");
  128. lua_error(state);
  129. }
  130. break;
  131. }
  132. default:
  133. {
  134. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  135. lua_error(state);
  136. break;
  137. }
  138. }
  139. return 0;
  140. }
  141. int lua_AnimationValue_setFloats(lua_State* state)
  142. {
  143. // Get the number of parameters.
  144. int paramCount = lua_gettop(state);
  145. // Attempt to match the parameters to a valid binding.
  146. switch (paramCount)
  147. {
  148. case 4:
  149. {
  150. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  151. lua_type(state, 2) == LUA_TNUMBER &&
  152. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
  153. lua_type(state, 4) == LUA_TNUMBER)
  154. {
  155. // Get parameter 1 off the stack.
  156. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  157. // Get parameter 2 off the stack.
  158. ScriptUtil::LuaArray<float> param2 = ScriptUtil::getFloatPointer(3);
  159. // Get parameter 3 off the stack.
  160. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  161. AnimationValue* instance = getInstance(state);
  162. instance->setFloats(param1, param2, param3);
  163. return 0;
  164. }
  165. else
  166. {
  167. lua_pushstring(state, "lua_AnimationValue_setFloats - Failed to match the given parameters to a valid function signature.");
  168. lua_error(state);
  169. }
  170. break;
  171. }
  172. default:
  173. {
  174. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  175. lua_error(state);
  176. break;
  177. }
  178. }
  179. return 0;
  180. }
  181. }