joypad.set(int which, table buttons) Sets the given buttons to be pressed during the next frame advance. The table should have the right keys (no pun intended) set. FatRatKnight: I changed some of the logic. Now with 4 options!*/
| 2899 | /*FatRatKnight: I changed some of the logic. |
| 2900 | Now with 4 options!*/ |
| 2901 | static int joypad_set(lua_State *L) { |
| 2902 | |
| 2903 | // Which joypad we're tampering with |
| 2904 | int which = luaL_checkinteger(L,1); |
| 2905 | if (which < 1 || which > 4) { |
| 2906 | luaL_error(L,"Invalid output port (valid range 1-4, specified %d)", which); |
| 2907 | |
| 2908 | } |
| 2909 | |
| 2910 | // And the table of buttons. |
| 2911 | luaL_checktype(L,2,LUA_TTABLE); |
| 2912 | |
| 2913 | // Set up for taking control of the indicated controller |
| 2914 | luajoypads1[which-1] = 0xFF; // .1 Reset right bit |
| 2915 | luajoypads2[which-1] = 0x00; // 0. Reset left bit |
| 2916 | |
| 2917 | int i; |
| 2918 | for (i=0; i < 8; i++) { |
| 2919 | lua_getfield(L, 2, button_mappings[i]); |
| 2920 | |
| 2921 | //Button is not nil, so find out if it is true/false |
| 2922 | if (!lua_isnil(L,-1)) |
| 2923 | { |
| 2924 | if (lua_toboolean(L,-1)) //True or string |
| 2925 | luajoypads2[which-1] |= 1 << i; |
| 2926 | if (lua_toboolean(L,-1) == 0 || lua_isstring(L,-1)) //False or string |
| 2927 | luajoypads1[which-1] &= ~(1 << i); |
| 2928 | } |
| 2929 | |
| 2930 | else |
| 2931 | { |
| 2932 | |
| 2933 | } |
| 2934 | lua_pop(L,1); |
| 2935 | } |
| 2936 | |
| 2937 | return 0; |
| 2938 | } |
| 2939 | |
| 2940 | // Helper function to convert a savestate object to the filename it represents. |
| 2941 | static const char *savestateobj2filename(lua_State *L, int offset) { |
nothing calls this directly
no test coverage detected