PolycodeLUA2D.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include <Polycode.h>
  3. #include "PolycodeLUA2D.h"
  4. extern "C" {
  5. #include <stdio.h>
  6. #include "lua.h"
  7. #include "lualib.h"
  8. #include "lauxlib.h"
  9. // Screen
  10. static int Polycore_Screen(lua_State *L) {
  11. Screen *screen = new Screen();
  12. lua_pushlightuserdata(L, (void*)screen);
  13. return 1;
  14. }
  15. static int Polycore_Screen_addChild(lua_State *L) {
  16. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  17. Screen *screen = (Screen*)lua_topointer(L, 1);
  18. ScreenEntity *child = (ScreenEntity*)lua_topointer(L, 2);
  19. screen->addChild(child);
  20. return 0;
  21. }
  22. static int Polycore_Screen_removeChild(lua_State *L) {
  23. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  24. luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
  25. Screen *screen = (Screen*)lua_topointer(L, 1);
  26. ScreenEntity *child = (ScreenEntity*)lua_topointer(L, 2);
  27. screen->removeChild(child);
  28. return 0;
  29. }
  30. static int Polycore_Screen_setScreenOffset(lua_State *L) {
  31. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  32. luaL_checktype(L, 2, LUA_TNUMBER);
  33. luaL_checktype(L, 3, LUA_TNUMBER);
  34. Screen *screen = (Screen*)lua_topointer(L, 1);
  35. float x = lua_tonumber(L, 2);
  36. float y = lua_tonumber(L, 3);
  37. screen->setScreenOffset(x,y);
  38. return 0;
  39. }
  40. static int Polycore_Screen_getScreenOffset(lua_State *L) {
  41. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  42. Screen *screen = (Screen*)lua_topointer(L, 1);
  43. Vector2 offset = screen->getScreenOffset();
  44. lua_pushnumber(L, offset.x);
  45. lua_pushnumber(L, offset.y);
  46. return 2;
  47. }
  48. static int Polycore_Screen_setScreenShader(lua_State *L) {
  49. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  50. luaL_checktype(L, 2, LUA_TSTRING);
  51. Screen *screen = (Screen*)lua_topointer(L, 1);
  52. const char *str = lua_tostring(L, 2);
  53. screen->setScreenShader(str);
  54. return 0;
  55. }
  56. static int Polycore_Screen_getHighestZIndex(lua_State *L) {
  57. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  58. Screen *screen = (Screen*)lua_topointer(L, 1);
  59. lua_pushinteger(L, screen->getHighestZIndex());
  60. return 1;
  61. }
  62. static int Polycore_Screen_sortChildren(lua_State *L) {
  63. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  64. Screen *screen = (Screen*)lua_topointer(L, 1);
  65. screen->sortChildren();
  66. return 0;
  67. }
  68. static int Polycore_Screen_hasFilterShader(lua_State *L) {
  69. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  70. Screen *screen = (Screen*)lua_topointer(L, 1);
  71. lua_pushboolean(L, screen->hasFilterShader());
  72. return 1;
  73. }
  74. static int Polycore_Screen_getRootEntity(lua_State *L) {
  75. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  76. Screen *screen = (Screen*)lua_topointer(L, 1);
  77. lua_pushlightuserdata(L, (void*)screen->getRootEntity());
  78. return 1;
  79. }
  80. static int Polycore_Screen_setEnabled(lua_State *L) {
  81. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  82. luaL_checktype(L, 2, LUA_TBOOLEAN);
  83. Screen *screen = (Screen*)lua_topointer(L, 1);
  84. bool enabledVal = lua_toboolean(L, 2);
  85. screen->enabled = enabledVal;
  86. return 0;
  87. }
  88. static int Polycore_Screen_getEnabled(lua_State *L) {
  89. luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
  90. Screen *screen = (Screen*)lua_topointer(L, 1);
  91. lua_pushboolean(L, screen->enabled);
  92. return 1;
  93. }
  94. // Screen IMage
  95. static int Polycore_ScreenImage(lua_State *L) {
  96. ScreenImage *screenImage = new ScreenImage(lua_tostring(L, 1));
  97. lua_pushlightuserdata(L, (void*)screenImage);
  98. return 1;
  99. }
  100. static int Polycore_ScreenImage_setRotation(lua_State *L) {
  101. ScreenEntity *image = (ScreenEntity*)lua_topointer(L, 1);
  102. float rotation = lua_tonumber(L, 2);
  103. image->setRotation(rotation);
  104. return 1;
  105. }
  106. }