lua_Uniform.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. 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*)((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. ScriptUtil::LuaObject* object = (ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(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. else
  58. {
  59. lua_pushstring(state, "lua_Uniform_getEffect - Failed to match the given parameters to a valid function signature.");
  60. lua_error(state);
  61. }
  62. break;
  63. }
  64. default:
  65. {
  66. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  67. lua_error(state);
  68. break;
  69. }
  70. }
  71. return 0;
  72. }
  73. int lua_Uniform_getName(lua_State* state)
  74. {
  75. // Get the number of parameters.
  76. int paramCount = lua_gettop(state);
  77. // Attempt to match the parameters to a valid binding.
  78. switch (paramCount)
  79. {
  80. case 1:
  81. {
  82. if ((lua_type(state, 1) == LUA_TUSERDATA))
  83. {
  84. Uniform* instance = getInstance(state);
  85. const char* result = instance->getName();
  86. // Push the return value onto the stack.
  87. lua_pushstring(state, result);
  88. return 1;
  89. }
  90. else
  91. {
  92. lua_pushstring(state, "lua_Uniform_getName - Failed to match the given parameters to a valid function signature.");
  93. lua_error(state);
  94. }
  95. break;
  96. }
  97. default:
  98. {
  99. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  100. lua_error(state);
  101. break;
  102. }
  103. }
  104. return 0;
  105. }
  106. int lua_Uniform_getType(lua_State* state)
  107. {
  108. // Get the number of parameters.
  109. int paramCount = lua_gettop(state);
  110. // Attempt to match the parameters to a valid binding.
  111. switch (paramCount)
  112. {
  113. case 1:
  114. {
  115. if ((lua_type(state, 1) == LUA_TUSERDATA))
  116. {
  117. Uniform* instance = getInstance(state);
  118. GLenum result = instance->getType();
  119. // Push the return value onto the stack.
  120. GP_WARN("Attempting to return value with unrecognized type GLenum as an unsigned integer.");
  121. lua_pushunsigned(state, result);
  122. return 1;
  123. }
  124. else
  125. {
  126. lua_pushstring(state, "lua_Uniform_getType - Failed to match the given parameters to a valid function signature.");
  127. lua_error(state);
  128. }
  129. break;
  130. }
  131. default:
  132. {
  133. lua_pushstring(state, "Invalid number of parameters (expected 1).");
  134. lua_error(state);
  135. break;
  136. }
  137. }
  138. return 0;
  139. }
  140. }