lua_AnimationValue.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. {"setFloat", lua_AnimationValue_setFloat},
  14. {NULL, NULL}
  15. };
  16. const luaL_Reg* lua_statics = NULL;
  17. std::vector<std::string> scopePath;
  18. ScriptUtil::registerClass("AnimationValue", lua_members, NULL, NULL, lua_statics, scopePath);
  19. }
  20. static AnimationValue* getInstance(lua_State* state)
  21. {
  22. void* userdata = luaL_checkudata(state, 1, "AnimationValue");
  23. luaL_argcheck(state, userdata != NULL, 1, "'AnimationValue' expected.");
  24. return (AnimationValue*)((ScriptUtil::LuaObject*)userdata)->instance;
  25. }
  26. int lua_AnimationValue_getFloat(lua_State* state)
  27. {
  28. // Get the number of parameters.
  29. int paramCount = lua_gettop(state);
  30. // Attempt to match the parameters to a valid binding.
  31. switch (paramCount)
  32. {
  33. case 2:
  34. {
  35. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  36. lua_type(state, 2) == LUA_TNUMBER)
  37. {
  38. // Get parameter 1 off the stack.
  39. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  40. AnimationValue* instance = getInstance(state);
  41. float result = instance->getFloat(param1);
  42. // Push the return value onto the stack.
  43. lua_pushnumber(state, result);
  44. return 1;
  45. }
  46. else
  47. {
  48. lua_pushstring(state, "lua_AnimationValue_getFloat - Failed to match the given parameters to a valid function signature.");
  49. lua_error(state);
  50. }
  51. break;
  52. }
  53. case 4:
  54. {
  55. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  56. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  57. lua_type(state, 3) == LUA_TNUMBER &&
  58. lua_type(state, 4) == LUA_TNUMBER)
  59. {
  60. // Get parameter 1 off the stack.
  61. float* param1 = ScriptUtil::getFloatPointer(2);
  62. // Get parameter 2 off the stack.
  63. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  64. // Get parameter 3 off the stack.
  65. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  66. AnimationValue* instance = getInstance(state);
  67. instance->getFloat(param1, param2, param3);
  68. return 0;
  69. }
  70. else
  71. {
  72. lua_pushstring(state, "lua_AnimationValue_getFloat - Failed to match the given parameters to a valid function signature.");
  73. lua_error(state);
  74. }
  75. break;
  76. }
  77. default:
  78. {
  79. lua_pushstring(state, "Invalid number of parameters (expected 2 or 4).");
  80. lua_error(state);
  81. break;
  82. }
  83. }
  84. return 0;
  85. }
  86. int lua_AnimationValue_setFloat(lua_State* state)
  87. {
  88. // Get the number of parameters.
  89. int paramCount = lua_gettop(state);
  90. // Attempt to match the parameters to a valid binding.
  91. switch (paramCount)
  92. {
  93. case 3:
  94. {
  95. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  96. lua_type(state, 2) == LUA_TNUMBER &&
  97. lua_type(state, 3) == LUA_TNUMBER)
  98. {
  99. // Get parameter 1 off the stack.
  100. unsigned int param1 = (unsigned int)luaL_checkunsigned(state, 2);
  101. // Get parameter 2 off the stack.
  102. float param2 = (float)luaL_checknumber(state, 3);
  103. AnimationValue* instance = getInstance(state);
  104. instance->setFloat(param1, param2);
  105. return 0;
  106. }
  107. else
  108. {
  109. lua_pushstring(state, "lua_AnimationValue_setFloat - Failed to match the given parameters to a valid function signature.");
  110. lua_error(state);
  111. }
  112. break;
  113. }
  114. case 4:
  115. {
  116. if ((lua_type(state, 1) == LUA_TUSERDATA) &&
  117. (lua_type(state, 2) == LUA_TTABLE || lua_type(state, 2) == LUA_TLIGHTUSERDATA) &&
  118. lua_type(state, 3) == LUA_TNUMBER &&
  119. lua_type(state, 4) == LUA_TNUMBER)
  120. {
  121. // Get parameter 1 off the stack.
  122. float* param1 = ScriptUtil::getFloatPointer(2);
  123. // Get parameter 2 off the stack.
  124. unsigned int param2 = (unsigned int)luaL_checkunsigned(state, 3);
  125. // Get parameter 3 off the stack.
  126. unsigned int param3 = (unsigned int)luaL_checkunsigned(state, 4);
  127. AnimationValue* instance = getInstance(state);
  128. instance->setFloat(param1, param2, param3);
  129. return 0;
  130. }
  131. else
  132. {
  133. lua_pushstring(state, "lua_AnimationValue_setFloat - Failed to match the given parameters to a valid function signature.");
  134. lua_error(state);
  135. }
  136. break;
  137. }
  138. default:
  139. {
  140. lua_pushstring(state, "Invalid number of parameters (expected 3 or 4).");
  141. lua_error(state);
  142. break;
  143. }
  144. }
  145. return 0;
  146. }
  147. }