From 7e232462d07c1c64cf53142d232518508cb64ffe Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 17 Apr 2020 08:01:04 +0800 Subject: [PATCH] Invalid table insertion, fix kaetemi/ryzomclassic#124 --- ryzom/common/data_common/r2/r2_misc.lua | 21 +++++++++++++++++++ ryzom/common/data_common/r2/r2_translator.lua | 12 +++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ryzom/common/data_common/r2/r2_misc.lua b/ryzom/common/data_common/r2/r2_misc.lua index d85744bd0..2402ff1fd 100644 --- a/ryzom/common/data_common/r2/r2_misc.lua +++ b/ryzom/common/data_common/r2/r2_misc.lua @@ -304,6 +304,27 @@ table.getn = function(table) return #table end +if oldInsertFunction == nil then + oldInsertFunction = table.insert +end + +table.insert = function(t, key, value) + if not key then + debugWarning(string.format("Inserting '%s' '%s' in table with %d elements, nil is not a valid appending value, inserting false instead to fix behaviour!", key, value, #t)) + if value then + oldInsertFunction(t, false, value) + else + oldInsertFunction(t, false) + end + else + if value then + oldInsertFunction(t, key, value) + else + oldInsertFunction(t, key) + end + end +end + -- redefine the hardcoded 'pairs' function to use the redefined 'next' diff --git a/ryzom/common/data_common/r2/r2_translator.lua b/ryzom/common/data_common/r2/r2_translator.lua index eccbe368c..2ef91ff3f 100644 --- a/ryzom/common/data_common/r2/r2_translator.lua +++ b/ryzom/common/data_common/r2/r2_translator.lua @@ -3962,15 +3962,19 @@ function Translator.translateDialog(entity, context) end rtAction = Translator.createAction("chat_step", rtNpcGrp.Id, param) + assert(rtAction) table.insert(rtDialogOk.Children, rtAction) + assert(param.Index) + assert(param.Emote) + assert(param.Says) + assert(param.WhoNoEntity) table.insert(endParam.Indexs, param.Index) - table.insert(endParam.Grps, param.WhoGrp) - table.insert(endParam.Whos, param.Who) + table.insert(endParam.Grps, param.WhoGrp or '') + table.insert(endParam.Whos, param.Who or '') table.insert(endParam.Emotes, param.Emote) table.insert(endParam.Says, param.Says) - table.insert(endParam.WhoNoEntitys, param.WhoNoEntity) - + table.insert(endParam.WhoNoEntitys, param.WhoNoEntity) else -- !if isKindOf("ChatStep") componentIndex, component = next(entity.Components, componentIndex)