foxygit / fake-08-xbox360 Log in
commit 7be57224bc6ca13bcb3cac0bb7762f62303773d6
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Thu Apr 23 11:49:44 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Thu Apr 23 11:49:44 2020 -0600

    implement rect and rectfill overloads; use lua_tonumber
---
 source/graphics.cpp   |  12 ++++++
 source/graphics.h     |   2 +
 source/picoluaapi.cpp | 105 ++++++++++++++++++++++++++++++--------------------
 3 files changed, 78 insertions(+), 41 deletions(-)

diff --git a/source/graphics.cpp b/source/graphics.cpp
index 3a76a55..1b5ed2e 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -354,7 +354,13 @@ void Graphics::circfill(short ox, short oy, short r, uint8_t col){

 }

+void Graphics::rect(short x1, short y1, short x2, short y2) {
+	this->rect(x1, y1, x2, y2, this->_gfxState_color);
+}
+
 void Graphics::rect(short x1, short y1, short x2, short y2, uint8_t col) {
+	color(col);
+
 	sortCoordsForRect(&x1, &y1, &x2, &y2);

 	for (short i = x1; i <= x2; i++) {
@@ -367,7 +373,13 @@ void Graphics::rect(short x1, short y1, short x2, short y2, uint8_t col) {

 }

+void Graphics::rectfill(short x1, short y1, short x2, short y2) {
+	this->rectfill(x1, y1, x2, y2, this->_gfxState_color);
+}
+
 void Graphics::rectfill(short x1, short y1, short x2, short y2, uint8_t col) {
+	color(col);
+
 	sortCoordsForRect(&x1, &y1, &x2, &y2);

 	for (short i = x1; i <= x2; i++) {
diff --git a/source/graphics.h b/source/graphics.h
index 493286a..b1cf92d 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -112,7 +112,9 @@ class Graphics {
 	void circfill(short ox, short oy, short r);
 	void circfill(short ox, short oy, short r, uint8_t col);

+	void rect(short x1, short y1, short x2, short y2);
 	void rect(short x1, short y1, short x2, short y2, uint8_t col);
+	void rectfill(short x1, short y1, short x2, short y2);
 	void rectfill(short x1, short y1, short x2, short y2, uint8_t col);

 	short print(std::string str, short x, short y, uint16_t c);
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 54cb0ae..e6cde83 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -26,7 +26,7 @@ int cls(lua_State *L){
         _graphicsForLuaApi->cls();
     }
     else {
-        short c = lua_tointeger(L,1);
+        short c = lua_tonumber(L,1);
         _graphicsForLuaApi->cls(c);
     }

@@ -34,15 +34,15 @@ int cls(lua_State *L){
 }

 int pset(lua_State *L){
-    short x = lua_tointeger(L,1);
-    short y = lua_tointeger(L,2);
+    short x = lua_tonumber(L,1);
+    short y = lua_tonumber(L,2);

     if (lua_gettop(L) <= 2) {
         _graphicsForLuaApi->pset(x, y);
         return 0;
     }

-    short c = lua_tointeger(L,3);
+    short c = lua_tonumber(L,3);

     _graphicsForLuaApi->pset(x, y, (uint8_t)c);

@@ -73,102 +73,125 @@ int line (lua_State *L){
         _graphicsForLuaApi->line();
     }
     else if (lua_gettop(L) == 1) {
-        uint8_t c = lua_tointeger(L,1);
+        uint8_t c = lua_tonumber(L,1);

         _graphicsForLuaApi->line(c);
     }
     else if (lua_gettop(L) == 2) {
-        short x1 = lua_tointeger(L,1);
-        short y1 = lua_tointeger(L,2);
+        short x1 = lua_tonumber(L,1);
+        short y1 = lua_tonumber(L,2);

         _graphicsForLuaApi->line(x1, y1);
     }
     else if (lua_gettop(L) == 3) {
-        short x1 = lua_tointeger(L,1);
-        short y1 = lua_tointeger(L,2);
-        uint8_t c = lua_tointeger(L,3);
+        short x1 = lua_tonumber(L,1);
+        short y1 = lua_tonumber(L,2);
+        uint8_t c = lua_tonumber(L,3);

         _graphicsForLuaApi->line(x1, y1, c);
     }
     else if (lua_gettop(L) == 4) {
-        short x1 = lua_tointeger(L,1);
-        short y1 = lua_tointeger(L,2);
-        short x2 = lua_tointeger(L,3);
-        short y2 = lua_tointeger(L,4);
+        short x1 = lua_tonumber(L,1);
+        short y1 = lua_tonumber(L,2);
+        short x2 = lua_tonumber(L,3);
+        short y2 = lua_tonumber(L,4);

         _graphicsForLuaApi->line(x1, y1, x2, y2);
     }
     else {
-        short x1 = lua_tointeger(L,1);
-        short y1 = lua_tointeger(L,2);
-        short x2 = lua_tointeger(L,3);
-        short y2 = lua_tointeger(L,4);
-        uint8_t c = lua_tointeger(L,5);
+        short x1 = lua_tonumber(L,1);
+        short y1 = lua_tonumber(L,2);
+        short x2 = lua_tonumber(L,3);
+        short y2 = lua_tonumber(L,4);
+        uint8_t c = lua_tonumber(L,5);

         _graphicsForLuaApi->line(x1, y1, x2, y2, c);
     }

     return 0;
 }
+
 int circ(lua_State *L){
-    short ox = lua_tointeger(L,1);
-    short oy = lua_tointeger(L,2);
+    short ox = lua_tonumber(L,1);
+    short oy = lua_tonumber(L,2);

     if (lua_gettop(L) == 2) {
         _graphicsForLuaApi->circ(ox, oy);
     }
     else if (lua_gettop(L) == 3){
-        short r = lua_tointeger(L,3);
+        short r = lua_tonumber(L,3);
         _graphicsForLuaApi->circ(ox, oy, r);
     }
     else if (lua_gettop(L) > 3){
-        short r = lua_tointeger(L,3);
-        uint8_t c = lua_tointeger(L,4);
+        short r = lua_tonumber(L,3);
+        uint8_t c = lua_tonumber(L,4);

         _graphicsForLuaApi->circ(ox, oy, r, c);
     }

     return 0;
 }
+
 int circfill(lua_State *L){
-    short ox = lua_tointeger(L,1);
-    short oy = lua_tointeger(L,2);
+    short ox = lua_tonumber(L,1);
+    short oy = lua_tonumber(L,2);

     if (lua_gettop(L) == 2) {
         _graphicsForLuaApi->circfill(ox, oy);
     }
     else if (lua_gettop(L) == 3){
-        short r = lua_tointeger(L,3);
+        short r = lua_tonumber(L,3);
         _graphicsForLuaApi->circfill(ox, oy, r);
     }
     else if (lua_gettop(L) > 3){
-        short r = lua_tointeger(L,3);
-        uint8_t c = lua_tointeger(L,4);
+        short r = lua_tonumber(L,3);
+        uint8_t c = lua_tonumber(L,4);

         _graphicsForLuaApi->circfill(ox, oy, r, c);
     }

     return 0;
 }
+
 int rect(lua_State *L){
-    double x1 = lua_tonumber(L,1);
-    double y1 = lua_tonumber(L,2);
-    double x2 = lua_tonumber(L,3);
-    double y2 = lua_tonumber(L,4);
-    double c = lua_tonumber(L,5);

-    _graphicsForLuaApi->rect((short)x1, (short)y1, (short)x2, (short)y2, (uint8_t)c);
+    if (lua_gettop(L) >= 4) {
+        short x1 = lua_tonumber(L,1);
+        short y1 = lua_tonumber(L,2);
+        short x2 = lua_tonumber(L,3);
+        short y2 = lua_tonumber(L,4);
+
+        if (lua_gettop(L) == 4){
+            _graphicsForLuaApi->rect(x1, y1, x2, y2);
+
+        }
+        else {
+            uint8_t c = lua_tonumber(L,5);
+
+            _graphicsForLuaApi->rect(x1, y1, x2, y2, c);
+        }
+    }

     return 0;
 }
+
 int rectfill(lua_State *L){
-    double x1 = lua_tonumber(L,1);
-    double y1 = lua_tonumber(L,2);
-    double x2 = lua_tonumber(L,3);
-    double y2 = lua_tonumber(L,4);
-    double c = lua_tonumber(L,5);
+    if (lua_gettop(L) >= 4) {
+        short x1 = lua_tonumber(L,1);
+        short y1 = lua_tonumber(L,2);
+        short x2 = lua_tonumber(L,3);
+        short y2 = lua_tonumber(L,4);
+
+        if (lua_gettop(L) == 4){
+            _graphicsForLuaApi->rectfill(x1, y1, x2, y2);

-    _graphicsForLuaApi->rectfill((short)x1, (short)y1, (short)x2, (short)y2, (uint8_t)c);
+        }
+        else {
+            double c = lua_tonumber(L,5);
+
+            _graphicsForLuaApi->rectfill(x1, y1, x2, y2, c);
+        }
+    }

     return 0;
 }