commit 3cb7ec51dc2f54f1dea8b0d5d1f871df8bb0e7d3
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Thu Nov 12 22:12:12 2020 -0700
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Thu Nov 12 22:12:12 2020 -0700
fix getting input as a bitfield
---
source/picoluaapi.cpp | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 2fd7b1c..6e50417 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -520,20 +520,34 @@ int flip(lua_State *L) {
//input api
int btn(lua_State *L){
- fix32 i = lua_tonumber(L,1);
+ if (lua_gettop(L) == 0) {
+ uint8_t btnstate = _inputForLuaApi->btn();
- bool pressed = _inputForLuaApi->btn((int)i);
+ lua_pushnumber(L, btnstate);
+ }
+ else {
+ fix32 i = lua_tonumber(L,1);
- lua_pushboolean(L, pressed);
+ bool pressed = _inputForLuaApi->btn((int)i);
+
+ lua_pushboolean(L, pressed);
+ }
return 1;
}
int btnp(lua_State *L){
- fix32 i = lua_tonumber(L,1);
+ if (lua_gettop(L) == 0) {
+ uint8_t btnpstate = _inputForLuaApi->btnp();
- bool pressed = _inputForLuaApi->btnp((int)i);
+ lua_pushnumber(L, btnpstate);
+ }
+ else {
+ fix32 i = lua_tonumber(L,1);
- lua_pushboolean(L, pressed);
+ bool pressed = _inputForLuaApi->btnp((int)i);
+
+ lua_pushboolean(L, pressed);
+ }
return 1;
}