diff --git a/docs/changelog.txt b/docs/changelog.txt index ea2c6abd7..fda724985 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -74,6 +74,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - Lua wrappers for functions reverse-engineered from ambushing unit code: ``isHidden(unit)``, ``isFortControlled(unit)``, ``getOuterContainerRef(unit)``, ``getOuterContainerRef(item)`` - ``dwarfmode.enterSidebarMode()``: passing ``df.ui_sidebar_mode.DesignateMine`` now always results in you entering ``DesignateMine`` mode and not ``DesignateChopTrees``, even when you looking at the surface where the default designation mode is ``DesignateChopTrees`` - New string class function: ``string:escape_pattern()`` escapes regex special characters within a string +- ``safe_index`` now properly handles lua sparse tables that are indexed by numbers # 0.47.05-r4 diff --git a/library/lua/dfhack.lua b/library/lua/dfhack.lua index 5fe377b50..26e20f748 100644 --- a/library/lua/dfhack.lua +++ b/library/lua/dfhack.lua @@ -372,7 +372,9 @@ function safe_index(obj,idx,...) if obj == nil or idx == nil then return nil end - if type(idx) == 'number' and (idx < 0 or idx >= #obj) then + if type(idx) == 'number' and + type(obj) == 'userdata' and -- this check is only relevant for c++ + (idx < 0 or idx >= #obj) then return nil end obj = obj[idx]