commit 8d74c55b6de06990e3b923f67f72b4d2cf325cff
Author: Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 23 12:41:07 2020 -0600
Commit: Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 23 12:41:07 2020 -0600
Fix default values of sspr params
---
source/graphics.h | 4 ++--
source/picoluaapi.cpp | 54 ++++++++++++++++++++++++++++++++++-----------------
2 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/source/graphics.h b/source/graphics.h
index edb3167..6a15061 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -139,8 +139,8 @@ class Graphics {
short dy,
short dw,
short dh,
- bool flip_x,
- bool flip_y);
+ bool flip_x = false,
+ bool flip_y = false);
bool fget(uint8_t n, uint8_t f);
uint8_t fget(uint8_t n);
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 013e9e3..c43d951 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -272,26 +272,44 @@ int spr(lua_State *L) {
}
int sspr(lua_State *L) {
- double sx = lua_tonumber(L,1);
- double sy = lua_tonumber(L,2);
- double sw = lua_tonumber(L,3);
- double sh = lua_tonumber(L,4);
- double dx = lua_tonumber(L,5);
- double dy = lua_tonumber(L,6);
- double dw = lua_tonumber(L,7);
- double dh = lua_tonumber(L,8);
- bool flip_x = lua_toboolean(L,9);
- bool flip_y = lua_toboolean(L,10);
+ if (lua_gettop(L) < 6) {
+ return 0;
+ }
+
+ short sx = lua_tonumber(L,1);
+ short sy = lua_tonumber(L,2);
+ short sw = lua_tonumber(L,3);
+ short sh = lua_tonumber(L,4);
+ short dx = lua_tonumber(L,5);
+ short dy = lua_tonumber(L,6);
+
+ short dw = sw;
+ short dh = sh;
+ bool flip_x = false;
+ bool flip_y = false;
+
+ if (lua_gettop(L) > 6){
+ dw = lua_tonumber(L,7);
+ }
+ if (lua_gettop(L) > 7){
+ dh = lua_tonumber(L,8);
+ }
+ if (lua_gettop(L) > 8){
+ flip_x = lua_toboolean(L,9);
+ }
+ if (lua_gettop(L) > 9){
+ flip_y = lua_toboolean(L,10);
+ }
_graphicsForLuaApi->sspr(
- (short)sx,
- (short)sy,
- (short)sw,
- (short)sh,
- (short)dx,
- (short)dy,
- (short)dw,
- (short)dh,
+ sx,
+ sy,
+ sw,
+ sh,
+ dx,
+ dy,
+ dw,
+ dh,
flip_x,
flip_y);