commit fbb427560e369df64138c51e0afce095074b0124
Author: mrfox <jens.se@icloud.com>
AuthorDate: Tue Nov 24 20:49:59 2026 +0100
Commit: mrfox <jens.se@icloud.com>
CommitDate: Tue Nov 24 20:49:59 2026 +0100
Fix customBiosLua overrides never reaching the BIOS cart
customBiosLua() was run with luaL_dostring into _G, but the BIOS cart's
code runs later inside its own sandbox and assigns its own defaults
(cartpath, selectbtn, exitbtn, ...), so platform overrides never showed
up. Inject the overrides into the cart code right before the
"--end customizable per platform" marker instead, falling back to the
old behaviour if the marker is missing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
source/vm.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/source/vm.cpp b/source/vm.cpp
index 63a6a63..e98aec6 100644
--- a/source/vm.cpp
+++ b/source/vm.cpp
@@ -388,7 +388,15 @@ bool Vm::loadCart(Cart* cart) {
if (cart->FullCartPath == DefaultCartName || cart->FullCartPath == SettingsCartName) {
std::string customBiosLua = _host->customBiosLua();
- if (customBiosLua.length() > 0) {
+ // The cart's code runs later inside its own sandbox and assigns its
+ // defaults there, so globals set with luaL_dostring are never seen.
+ // Inject the overrides into the cart code right after the defaults.
+ const std::string customEndMarker = "--end customizable per platform";
+ size_t markerPos = cart->LuaString.find(customEndMarker);
+ if (customBiosLua.length() > 0 && markerPos != std::string::npos) {
+ cart->LuaString.insert(markerPos, customBiosLua + "\n");
+ }
+ else if (customBiosLua.length() > 0) {
int doStrRes = luaL_dostring(_luaState, customBiosLua.c_str());
if (doStrRes != LUA_OK){