handle number-indexed lua maps in safe_index

develop
myk002 2022-04-11 16:56:45 -07:00 committed by Myk
parent 4f9608da13
commit 4a383b1c84
2 changed files with 4 additions and 1 deletions

@ -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

@ -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]