2
0

lua_debug_line.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include "lua_stack.h"
  24. #include "lua_environment.h"
  25. #include "debug_line.h"
  26. #include "vector3.h"
  27. #include "color4.h"
  28. namespace crown
  29. {
  30. static int debug_line_add_line(lua_State* L)
  31. {
  32. LuaStack stack(L);
  33. stack.get_debug_line(1)->add_line(Color4::RED, stack.get_vector3(2), stack.get_vector3(3));
  34. return 0;
  35. }
  36. static int debug_line_add_sphere(lua_State* L)
  37. {
  38. LuaStack stack(L);
  39. stack.get_debug_line(1)->add_sphere(Color4::RED, stack.get_vector3(2), stack.get_float(3));
  40. return 0;
  41. }
  42. static int debug_line_clear(lua_State* L)
  43. {
  44. LuaStack stack(L);
  45. stack.get_debug_line(1)->clear();
  46. return 0;
  47. }
  48. static int debug_line_commit(lua_State* L)
  49. {
  50. LuaStack stack(L);
  51. stack.get_debug_line(1)->commit();
  52. return 0;
  53. }
  54. static int debug_line_tostring(lua_State* L)
  55. {
  56. LuaStack stack(L);
  57. stack.push_fstring("DebugLine (%p)", stack.get_debug_line(1));
  58. return 1;
  59. }
  60. void load_debug_line(LuaEnvironment& env)
  61. {
  62. env.load_module_function("DebugLine", "add_line", debug_line_add_line);
  63. env.load_module_function("DebugLine", "add_sphere", debug_line_add_sphere);
  64. env.load_module_function("DebugLine", "clear", debug_line_clear);
  65. env.load_module_function("DebugLine", "commit", debug_line_commit);
  66. env.load_module_function("DebugLine", "__index", "DebugLine");
  67. env.load_module_function("DebugLine", "__tostring", debug_line_tostring);
  68. }
  69. } // namespace crown