foxygit / fake-08-xbox360 Log in
commit 5b11dacdc67ed59bca4b669af6597b88af482ccb
Author:     jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Sun Mar 14 19:29:45 2021 -0600
Commit:     jtothebell <j.to.the.bell@gmail.com>
CommitDate: Sun Mar 14 19:29:45 2021 -0600

    Fix 1p input being used for all players
---
 source/Input.cpp      |  2 +-
 source/picoluaapi.cpp | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/source/Input.cpp b/source/Input.cpp
index 106634f..0c035af 100644
--- a/source/Input.cpp
+++ b/source/Input.cpp
@@ -76,5 +76,5 @@ bool Input::btn(uint8_t i, uint8_t p){
 //todo: repetition behavior to match pico 8
 bool Input::btnp(uint8_t i, uint8_t p){
     //no multiplayer support for now
-    return p == 0 ? btn(i) : 0;
+    return p == 0 ? btnp(i) : 0;
 }
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 15ef97a..87728db 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -611,15 +611,20 @@ int flip(lua_State *L) {

 //input api
 int btn(lua_State *L){
-    if (lua_gettop(L) == 0) {
+    int numArgs = lua_gettop(L);
+    if (numArgs == 0) {
         uint8_t btnstate = _inputForLuaApi->btn();

         lua_pushnumber(L, btnstate);
     }
     else {
         fix32 i = lua_tonumber(L,1);
+        int p = 0;
+        if (numArgs > 1){
+            p = lua_tonumber(L,2);
+        };

-        bool pressed = _inputForLuaApi->btn((int)i);
+        bool pressed = _inputForLuaApi->btn((int)i, p);

         lua_pushboolean(L, pressed);
     }
@@ -627,15 +632,20 @@ int btn(lua_State *L){
     return 1;
 }
 int btnp(lua_State *L){
-    if (lua_gettop(L) == 0) {
+    int numArgs = lua_gettop(L);
+    if (numArgs == 0) {
         uint8_t btnpstate = _inputForLuaApi->btnp();

         lua_pushnumber(L, btnpstate);
     }
     else {
         fix32 i = lua_tonumber(L,1);
+        int p = 0;
+        if (numArgs > 1){
+            p = lua_tonumber(L,2);
+        };

-        bool pressed = _inputForLuaApi->btnp((int)i);
+        bool pressed = _inputForLuaApi->btnp((int)i, p);

         lua_pushboolean(L, pressed);
     }