commit acf040deed773b7033b507cfdbf711c61480a55d
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Thu Apr 15 08:11:18 2021 -0600
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Thu Apr 15 08:11:18 2021 -0600
Fix return value when calling cartdata
---
source/picoluaapi.cpp | 8 ++++++--
source/vm.cpp | 8 ++++----
source/vm.h | 2 +-
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/source/picoluaapi.cpp b/source/picoluaapi.cpp
index 3c04e57..7adccce 100644
--- a/source/picoluaapi.cpp
+++ b/source/picoluaapi.cpp
@@ -967,12 +967,16 @@ int reload(lua_State *L) {
//cart data
int cartdata(lua_State *L) {
+ bool result = false;
+
if (lua_gettop(L) > 0) {
std::string key = lua_tolstring(L, 1, nullptr);
- _vmForLuaApi->vm_cartdata(key);
+ result = _vmForLuaApi->vm_cartdata(key);
}
- return 0;
+ lua_pushboolean(L, result);
+
+ return 1;
}
int dget(lua_State *L) {
diff --git a/source/vm.cpp b/source/vm.cpp
index a78ca85..f693985 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -673,17 +673,17 @@ void Vm::vm_poke4(int addr, fix32 value){
_memory->data[addr + 3] = (uint8_t)(ubits >> 24);
}
-std::string Vm::vm_cartdata(string key) {
+bool Vm::vm_cartdata(string key) {
//match pico 8 errors
if (_cartdataKey != "") {
QueueCartChange(BiosCartName);
_cartLoadError = "cartdata() can only be called once";
- return _cartLoadError;
+ return false;
}
if (key.length() == 0 || key.length() > 64) {
QueueCartChange(BiosCartName);
_cartLoadError = "cart data id too long";
- return _cartLoadError;
+ return false;
}
//todo: validate chars
@@ -696,7 +696,7 @@ std::string Vm::vm_cartdata(string key) {
deserializeCartDataToMemory(cartDataStr);
}
- return "";
+ return true;
//call host to get current cart data and init- set memory
//file name should match pico 8: {key}.p8d.txt in the cdata directory
diff --git a/source/vm.h b/source/vm.h
index 6ed53a5..b331c2d 100644
--- a/source/vm.h
+++ b/source/vm.h
@@ -106,7 +106,7 @@ class Vm {
void vm_poke2(int addr, int16_t value);
void vm_poke4(int addr, fix32 value);
- std::string vm_cartdata(string key);
+ bool vm_cartdata(string key);
fix32 vm_dget(uint8_t n);
void vm_dset(uint8_t n, fix32 value);