[Scummvm-git-logs] scummvm master -> ade1323fc47501fd6d879c6dfd7fd54b77bbd41e
bluegr
noreply at scummvm.org
Fri Dec 4 02:01:12 UTC 2026
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
5926749cad NANCY: NANCY19: Accept an empty player name in the Player functions
ade1323fc4 NANCY: NANCY19: Fix table.insert and table.remove for the Lua scripts
Commit: 5926749cade456d4649da5bf3faa97cb50a87ebb
https://github.com/scummvm/scummvm/commit/5926749cade456d4649da5bf3faa97cb50a87ebb
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-12-04T03:59:44+02:00
Commit Message:
NANCY: NANCY19: Accept an empty player name in the Player functions
An empty name now means the character being played, as in the
original. Nancy19 scene 2622 passes one when Nancy picks up the
zodiac book, which made the script fail.
Changed paths:
engines/nancy/script/gameapi.cpp
diff --git a/engines/nancy/script/gameapi.cpp b/engines/nancy/script/gameapi.cpp
index 3e22c18e48a..58ffe10c794 100644
--- a/engines/nancy/script/gameapi.cpp
+++ b/engines/nancy/script/gameapi.cpp
@@ -2073,13 +2073,18 @@ static int findCharacter(const char *name) {
return -1;
}
-// The character named by an optional argument
+// The character named by an optional argument. An empty name also means the
+// one being played: Nancy19 scene 2622 passes "".
static uint checkCharacter(lua_State *L, int index) {
if (lua_gettop(L) < index) {
return g_nancy->getPlayerCharacter();
}
const char *name = luaL_checkstring(L, index);
+ if (!*name) {
+ return g_nancy->getPlayerCharacter();
+ }
+
const int character = findCharacter(name);
if (character < 0) {
luaL_error(L, "Invalid player %s", name);
Commit: ade1323fc47501fd6d879c6dfd7fd54b77bbd41e
https://github.com/scummvm/scummvm/commit/ade1323fc47501fd6d879c6dfd7fd54b77bbd41e
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-12-04T03:59:46+02:00
Commit Message:
NANCY: NANCY19: Fix table.insert and table.remove for the Lua scripts
They now work like in the Lua that the games ship. Before, the discs of
the Tower of Hanoi puzzle in Nancy19 scene 2639 ended up in the wrong
places, and the puzzle got stuck.
Changed paths:
engines/nancy/script/luastate.cpp
diff --git a/engines/nancy/script/luastate.cpp b/engines/nancy/script/luastate.cpp
index 486c02fe6af..4545957d049 100644
--- a/engines/nancy/script/luastate.cpp
+++ b/engines/nancy/script/luastate.cpp
@@ -246,6 +246,56 @@ static int tableKeySort(lua_State *L) {
return 1;
}
+// The games ship Lua 5.1.2 as it comes, where the size of a table is always
+// its length (#). The Lua of ScummVM can also remember a size for each table
+// (LUA_COMPAT_GETN), which table.insert and table.remove keep, and which
+// table.insert then goes by. The two functions below are those of the games,
+// which never remember a size.
+
+// table.insert(table, [position,] value)
+static int tableInsert(lua_State *L) {
+ luaL_checktype(L, 1, LUA_TTABLE);
+ int last = lua_objlen(L, 1) + 1;
+ int position = last;
+
+ if (lua_gettop(L) == 3) {
+ position = luaL_checkint(L, 2);
+ last = MAX(last, position);
+ for (int i = last; i > position; --i) {
+ lua_rawgeti(L, 1, i - 1);
+ lua_rawseti(L, 1, i);
+ }
+ } else if (lua_gettop(L) != 2) {
+ return luaL_error(L, "wrong number of arguments to " LUA_QL("insert"));
+ }
+
+ lua_rawseti(L, 1, position);
+ return 0;
+}
+
+// table.remove(table[, position]). Unlike later versions, a position outside of
+// the table isn't checked: position 0 moves every value down by one, removing
+// the first one. Nancy19's Tower of Hanoi puzzle (scene 2639) takes the
+// smallest disc off a tower like that.
+static int tableRemove(lua_State *L) {
+ luaL_checktype(L, 1, LUA_TTABLE);
+ const int last = lua_objlen(L, 1);
+ int position = luaL_optint(L, 2, last);
+ if (last == 0) {
+ return 0;
+ }
+
+ lua_rawgeti(L, 1, position);
+ for (; position < last; ++position) {
+ lua_rawgeti(L, 1, position + 1);
+ lua_rawseti(L, 1, position);
+ }
+
+ lua_pushnil(L);
+ lua_rawseti(L, 1, last);
+ return 1;
+}
+
// Nancy20's math.isnan(number)
static int mathIsNaN(lua_State *L) {
const lua_Number number = luaL_checknumber(L, 1);
@@ -369,6 +419,9 @@ LuaState::LuaState(SceneContext *context) {
lua_setfield(_state, -2, "wrap");
lua_pop(_state, 1);
+ setLibraryFunction(_state, LUA_TABLIBNAME, "insert", tableInsert);
+ setLibraryFunction(_state, LUA_TABLIBNAME, "remove", tableRemove);
+
if (g_nancy->getGameType() >= kGameTypeNancy20) {
setLibraryFunction(_state, LUA_TABLIBNAME, "sort", tableSort);
setLibraryFunction(_state, LUA_MATHLIBNAME, "isnan", mathIsNaN);
More information about the Scummvm-git-logs
mailing list