foxygit / fake-08-xbox360 Log in
commit 5f6c29c1d35eefe456445bb2d14979ced8027cfd
Author:     Jon Bell <j.to.the.bell@gmail.com>
AuthorDate: Fri Feb 10 21:04:23 2023 -0700
Commit:     Jon Bell <j.to.the.bell@gmail.com>
CommitDate: Fri Feb 10 21:04:23 2023 -0700

    Slight refactor to handling null char
---
 source/picoluaapi.cpp  | 21 +++++++++++++--------
 source/printHelper.cpp |  4 ----
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index bef7550..a720481 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -301,29 +301,34 @@ int print(lua_State *L){
         return 0;
     }

-    std::string str = "";
+    const char * charArray = "";
+    size_t len = 0;
     int newx = 0;

     //todo: handle other cases, maybe move this somewhere else
     //learned this from zepto8 https://github.com/samhocevar/zepto8/blob/27f83fe0626d4823fe2a33568d8310d8def84ae9/src/pico8/vm.cpp
     if (lua_isnil(L, 1)){
-        str = "[nil]";
+        charArray = "[nil]";
+        len = 5;
     }
     else if (lua_isstring(L, 1)){
-        size_t len;
-        const char *raw_string = lua_tolstring(L, 1, &len);
-        str = std::string(raw_string, len);
+        charArray = lua_tolstring(L, 1, &len);
     }
     else if (lua_isnumber(L, 1)){
-        str = lua_tolstring(L, 1, nullptr);
+        charArray = lua_tolstring(L, 1, &len);
     }
     else if (lua_isboolean(L, 1)){
-        str = lua_toboolean(L, 1) ? "true" : "false";
+        int boolVal = lua_toboolean(L, 1);
+        charArray = boolVal ? "true" : "false";
+        len = boolVal ? 4 : 5;
     }
     else if (lua_isfunction(L, 1)){
-        str = "[function]";
+        charArray = "[function]";
+        len = 10;
     }

+    std::string str = std::string(charArray, len);
+
     if (numArgs < 2) {
         newx = print(str);
     }
diff --git a/source/printHelper.cpp b/source/printHelper.cpp
index 3501faf..5b135b0 100644
--- a/source/printHelper.cpp
+++ b/source/printHelper.cpp
@@ -127,10 +127,6 @@ int print(std::string str, int x, int y, uint8_t c) {
             _ph_mem->drawState.text_x=x;
             _ph_mem->drawState.text_y=y;

-            //restore palette
-            for(int i = 0; i < 16; i++) {
-                _ph_mem->drawState.drawPaletteMap[i] = prevDrawPal[i];
-            }
             return x;
         }
         else if (ch == 1) { // "\*{p0}" repeat the next character p0 times