lua_Uniform.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #include "Base.h"
  2. #include "ScriptController.h"
  3. #include "lua_Uniform.h"
  4. #include "Base.h"
  5. #include "Effect.h"
  6. #include "FileSystem.h"
  7. #include "Game.h"
  8. #include "Ref.h"
  9. namespace gameplay
  10. {
  11. void luaRegister_Uniform()
  12. {
  13. const luaL_Reg lua_members[] =
  14. {
  15. {"getEffect", lua_Uniform_getEffect},
  16. {"getName", lua_Uniform_getName},
  17. {"getType", lua_Uniform_getType},
  18. {NULL, NULL}
  19. };
  20. const luaL_Reg* lua_statics = NULL;
  21. std::vector<std::string> scopePath;
  22. gameplay::ScriptUtil::registerClass("Uniform", lua_members, NULL, NULL, lua_statics, scopePath);
  23. }
  24. static Uniform* getInstance(lua_State* state)
  25. {
  26. void* userdata = luaL_checkudata(state, 1, "Uniform");
  27. luaL_argcheck(state, userdata != NULL, 1, "'Uniform' expected.");
  28. return (Uniform*)((gameplay::ScriptUtil::LuaObject*)userdata)->instance;
  29. }
  30. int lua_Uniform_getEffect(lua_State* state)
  31. {
  32. // Get the number of parameters.
  33. int paramCount = lua_gettop(state);
  34. // Attempt to match the parameters to a valid binding.
  35. switch (paramCount)
  36. {
  37. case 1:
  38. {
  39. if ((lua_type(state, 1) == LUA_TUSERDATA))
  40. {
  41. Uniform* instance = getInstance(state);
  42. void* returnPtr = (void*)instance->getEffect();
  43. if (returnPtr)
  44. {
  45. gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
  46. object->instance = returnPtr;
  47. object->owns = false;
  48. luaL_getmetatable(state, "Effect");
  49. lua_setmetatable(state, -2);
  50. }
  51. else
  52. {
  53. lua_pushnil(state);
  54. }
  55. return 1;
  56. }
  57. lua_pushstring(state, "lua_Uniform_getEffect - Failed to match the given parameters to a valid function signature.");
  58. lua_error(state);
  59. break;
  60. }
  61. default:
  62. {
  63. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  64. lua_error(state);
  65. break;
  66. }
  67. }
  68. return 0;
  69. }
  70. int lua_Uniform_getName(lua_State* state)
  71. {
  72. // Get the number of parameters.
  73. int paramCount = lua_gettop(state);
  74. // Attempt to match the parameters to a valid binding.
  75. switch (paramCount)
  76. {
  77. case 1:
  78. {
  79. if ((lua_type(state, 1) == LUA_TUSERDATA))
  80. {
  81. Uniform* instance = getInstance(state);
  82. const char* result = instance->getName();
  83. // Push the return value onto the stack.
  84. lua_pushstring(state, result);
  85. return 1;
  86. }
  87. lua_pushstring(state, "lua_Uniform_getName - Failed to match the given parameters to a valid function signature.");
  88. lua_error(state);
  89. break;
  90. }
  91. default:
  92. {
  93. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  94. lua_error(state);
  95. break;
  96. }
  97. }
  98. return 0;
  99. }
  100. int lua_Uniform_getType(lua_State* state)
  101. {
  102. // Get the number of parameters.
  103. int paramCount = lua_gettop(state);
  104. // Attempt to match the parameters to a valid binding.
  105. switch (paramCount)
  106. {
  107. case 1:
  108. {
  109. if ((lua_type(state, 1) == LUA_TUSERDATA))
  110. {
  111. Uniform* instance = getInstance(state);
  112. GLenum result = instance->getType();
  113. // Push the return value onto the stack.
  114. GP_WARN("Attempting to return value with unrecognized type GLenum as an unsigned integer.");
  115. lua_pushunsigned(state, result);
  116. return 1;
  117. }
  118. lua_pushstring(state, "lua_Uniform_getType - 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 1).");
  125. lua_error(state);
  126. break;
  127. }
  128. }
  129. return 0;
  130. }
  131. }