Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. // This code is licensed under the MIT Open Source License.
  2.  
  3. // Copyright (c) 2015 Ruairidh Carmichael - ruairidhcarmichael@live.co.uk
  4.  
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11.  
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14.  
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22.  
  23. #include <shared.h>
  24.  
  25. #define JOYSTICK_COUNT 1
  26.  
  27. int joystickInputScan(lua_State *L) { // love.joystick.scan()
  28.  
  29. hidScanInput();
  30.  
  31. }
  32.  
  33. int joystickGetCount(lua_State *L) { //love.joystick.getJoystickCount()
  34.  
  35. // Assuming a joystick in love is technically
  36. // a gamepad with a set of controls
  37. // then return 1 since the 3DS is a gamepad itself.
  38. lua_pushinteger(L, JOYSTICK_COUNT);
  39.  
  40. return 1;
  41.  
  42. }
  43.  
  44. static int joystickX(lua_State *L) { //love.joystick.getX()
  45. circlePosition circleData;
  46. hidCircleRead(&circleData);
  47.  
  48. lua_pushnumber(L, circleData.dx);
  49.  
  50. return 1;
  51. }
  52.  
  53. static int joystickY(lua_State *L) { //love.joystick.getY()
  54. circlePosition circleData;
  55. hidCircleRead(&circleData);
  56.  
  57. lua_pushnumber(L, circleData.dy);
  58.  
  59. return 1;
  60. }
  61.  
  62. int joystickGetList(lua_State *L) { //love.joystick.getJoystickList()
  63.  
  64. // Assuming a joystick in love is technically
  65. // a gamepad with a set of controls
  66. // then return a madeup joystick
  67. lua_newtable(L);
  68. for(int i = 1; i <= JOYSTICK_COUNT; i++ ) //<< In the event that there might be more joysticks
  69. {
  70. lua_pushnumber(L, i);
  71. joystickNew(L, i);
  72. lua_rawset(L, -3);
  73. }
  74.  
  75. return 1;
  76.  
  77. }
  78.  
  79. int joystickNew(lua_State *L);
  80.  
  81. int initLoveJoystick(lua_State *L) {
  82.  
  83. luaL_Reg reg[] = {
  84. { "getJoystickCount", joystickGetCount },
  85. { "getJoysticks", joystickGetList },
  86. { "getX", joystickX },
  87. { "getY", joystickY },
  88. //{ "loadGamepadMappings", gamepadLoadMappings},
  89. //{ "setGamepadMapping", gamepadSetMapping},
  90. { 0, 0 }
  91. };
  92.  
  93. luaL_newlib(L, reg);
  94.  
  95. return 1;
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement