From dc99f78aa08abe83c004b64b46244204cdb4ad93 Mon Sep 17 00:00:00 2001 From: Jerboa-app Date: Mon, 26 Feb 2024 20:30:36 +0000 Subject: [PATCH] adds lua printing to android, fixes null id from string construction tested lua printing on android device --- CMakeLists.txt | 6 ++++++ include/Object/id.h | 32 ++++++++++++++++++----------- include/vendored/lua/src/lbaselib.c | 8 ++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d761a643..8525e4a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,12 @@ else() string(TIMESTAMP TODAY "%Y-%m-%d:%H:%M:%S") add_compile_definitions(TIMESTAMP="${TODAY}") +if (ANDROID) + add_compile_definitions(ANDROID) +elseif (WINDOWS) + add_compile_definitions(WINDOWS) +endif() + if (RELEASE) if (ANDROID) message("ANDROID MinSizeRel!") diff --git a/include/Object/id.h b/include/Object/id.h index 07c7d2d4..5a8e61c9 100644 --- a/include/Object/id.h +++ b/include/Object/id.h @@ -26,24 +26,32 @@ namespace Hop::Object Id(std::string sid) { - size_t delim = sid.find("-"); - - if (delim == sid.npos || delim == sid.size()) + + if (sid == "") { - throw std::runtime_error("Cannot construct id from string: "+sid); + id = Id::NULL_ID_CODE; } + else + { + size_t delim = sid.find("-"); + + if (delim == sid.npos || delim == sid.size()) + { + throw std::runtime_error("Cannot construct id from string: "+sid); + } - std::string index, code; + std::string index, code; - index = sid.substr(0, delim); - code = sid.substr(delim+1, sid.size()); + index = sid.substr(0, delim); + code = sid.substr(delim+1, sid.size()); - if (code != uuids::to_string(getRunUUID())) - { - throw std::runtime_error("Cannot construct id from string, invalid run uuid: "+sid); - } + if (code != uuids::to_string(getRunUUID())) + { + throw std::runtime_error("Cannot construct id from string, invalid run uuid: "+sid); + } - id = uint64_t(std::stoull(index)); + id = uint64_t(std::stoull(index)); + } } static uint64_t next(){uint64_t thisId = nextId; nextId++; return thisId;} diff --git a/include/vendored/lua/src/lbaselib.c b/include/vendored/lua/src/lbaselib.c index 8b8c213a..818e7e7a 100644 --- a/include/vendored/lua/src/lbaselib.c +++ b/include/vendored/lua/src/lbaselib.c @@ -20,6 +20,11 @@ #include "lauxlib.h" #include "lualib.h" +#ifdef ANDROID + #include +#endif + + #if !defined(ANDROID) && !defined(WINDOWS) const char * LUA_PRINT_ENTRY = "\033[1;34m[LUA] \033[0m\0"; const size_t LUA_ENTRY_LENGTH = 23; @@ -41,6 +46,9 @@ static int luaB_print (lua_State *L) { if (i > 1) /* not the first element? */ lua_writestring("\t", 1); /* add a tab before it */ lua_writestring(s, l); /* print it */ + #if defined(ANDROID) + __android_log_print(ANDROID_LOG_INFO,"LUA","%s",s); + #endif lua_pop(L, 1); /* pop result */ } lua_writeline();