lua_AnimationValue.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. gameplay::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*)((gameplay::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. lua_pushstring(state, "lua_AnimationValue_getFloat - Failed to match the given parameters to a valid function signature.");
  49. lua_error(state);
  50. break;
  51. }
  52. default:
  53. {
  54. lua_pushstring(state, "Invalid number of parameters (expected 2).");
  55. lua_error(state);
  56. break;
  57. }
  58. }
  59. return 0;
  60. }
  61. int lua_AnimationValue_getFloats(lua_State* state)
  62. {
  63. // Get the number of parameters.
  64. int paramCount = lua_gettop(state);
  65. // Attempt to match the parameters to a valid binding.
  66. switch (paramCount)
  67. {
  68. case 4:
  69. {
  70. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  71. lua_type(state, 2) == LUA_TNUMBER &&
  72. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
  73. lua_type(state, 4) == LUA_TNUMBER)
  74. {
  75. // Get parameter 1 off the stack.
  76. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  77. // Get parameter 2 off the stack.
  78. gameplay::ScriptUtil::LuaArray<float> param2 = gameplay::ScriptUtil::getFloatPointer(3);
  79. // Get parameter 3 off the stack.
  80. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  81. AnimationValue* instance = getInstance(state);
  82. instance->getFloats(param1, param2, param3);
  83. return 0;
  84. }
  85. lua_pushstring(state, "lua_AnimationValue_getFloats - Failed to match the given parameters to a valid function signature.");
  86. lua_error(state);
  87. break;
  88. }
  89. default:
  90. {
  91. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  92. lua_error(state);
  93. break;
  94. }
  95. }
  96. return 0;
  97. }
  98. int lua_AnimationValue_setFloat(lua_State* state)
  99. {
  100. // Get the number of parameters.
  101. int paramCount = lua_gettop(state);
  102. // Attempt to match the parameters to a valid binding.
  103. switch (paramCount)
  104. {
  105. case 3:
  106. {
  107. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  108. lua_type(state, 2) == LUA_TNUMBER &&
  109. lua_type(state, 3) == LUA_TNUMBER)
  110. {
  111. // Get parameter 1 off the stack.
  112. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  113. // Get parameter 2 off the stack.
  114. float param2 = (float)luaL_checknumber(state, 3);
  115. AnimationValue* instance = getInstance(state);
  116. instance->setFloat(param1, param2);
  117. return 0;
  118. }
  119. lua_pushstring(state, "lua_AnimationValue_setFloat - Failed to match the given parameters to a valid function signature.");
  120. lua_error(state);
  121. break;
  122. }
  123. default:
  124. {
  125. lua_pushstring(state, "Invalid number of parameters (expected 3).");
  126. lua_error(state);
  127. break;
  128. }
  129. }
  130. return 0;
  131. }
  132. int lua_AnimationValue_setFloats(lua_State* state)
  133. {
  134. // Get the number of parameters.
  135. int paramCount = lua_gettop(state);
  136. // Attempt to match the parameters to a valid binding.
  137. switch (paramCount)
  138. {
  139. case 4:
  140. {
  141. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  142. lua_type(state, 2) == LUA_TNUMBER &&
  143. (lua_type(state, 3) == LUA_TTABLE || lua_type(state, 3) == LUA_TLIGHTUSERDATA) &&
  144. lua_type(state, 4) == LUA_TNUMBER)
  145. {
  146. // Get parameter 1 off the stack.
  147. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  148. // Get parameter 2 off the stack.
  149. gameplay::ScriptUtil::LuaArray<float> param2 = gameplay::ScriptUtil::getFloatPointer(3);
  150. // Get parameter 3 off the stack.
  151. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  152. AnimationValue* instance = getInstance(state);
  153. instance->setFloats(param1, param2, param3);
  154. return 0;
  155. }
  156. lua_pushstring(state, "lua_AnimationValue_setFloats - Failed to match the given parameters to a valid function signature.");
  157. lua_error(state);
  158. break;
  159. }
  160. default:
  161. {
  162. lua_pushstring(state, "Invalid number of parameters (expected 4).");
  163. lua_error(state);
  164. break;
  165. }
  166. }
  167. return 0;
  168. }
  169. }