From 7c51f69901e2d1c820eb8d662745484f95fc522b Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Tue, 8 Jul 2014 21:20:40 -0400 Subject: [PATCH] Create mw.dumpObject split from mw.logObject Add an mw.dumpObject() method, which converts an object in the same manner as mw.logObject(), but returns it instead of adding it to the log buffer. Change-Id: Ie9fbd24d9d8d13ee2ddf8052679010892f61e1e0 --- engines/LuaCommon/lualib/mw.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/engines/LuaCommon/lualib/mw.lua b/engines/LuaCommon/lualib/mw.lua index f9cafbfa..05035b8e 100644 --- a/engines/LuaCommon/lualib/mw.lua +++ b/engines/LuaCommon/lualib/mw.lua @@ -540,7 +540,7 @@ function mw.log( ... ) logBuffer = logBuffer .. mw.allToString( ... ) .. '\n' end -function mw.logObject( object, prefix ) +function mw.dumpObject( object ) local doneTable = {} local doneObj = {} local ct = {} @@ -557,7 +557,7 @@ function mw.logObject( object, prefix ) end return false -- Incomparable end - local function _logObject( object, indent, expandTable ) + local function _dumpObject( object, indent, expandTable ) local tp = type( object ) if tp == 'number' or tp == 'nil' or tp == 'boolean' then return tostring( object ) @@ -584,7 +584,7 @@ function mw.logObject( object, prefix ) if mt then ret[#ret + 1] = string.rep( " ", indent + 2 ) ret[#ret + 1] = 'metatable = ' - ret[#ret + 1] = _logObject( mt, indent + 2, false ) + ret[#ret + 1] = _dumpObject( mt, indent + 2, false ) ret[#ret + 1] = "\n" end @@ -592,7 +592,7 @@ function mw.logObject( object, prefix ) for key, value in ipairs( object ) do doneKeys[key] = true ret[#ret + 1] = string.rep( " ", indent + 2 ) - ret[#ret + 1] = _logObject( value, indent + 2, true ) + ret[#ret + 1] = _dumpObject( value, indent + 2, true ) ret[#ret + 1] = ',\n' end local keys = {} @@ -606,9 +606,9 @@ function mw.logObject( object, prefix ) local key = keys[i] ret[#ret + 1] = string.rep( " ", indent + 2 ) ret[#ret + 1] = '[' - ret[#ret + 1] = _logObject( key, indent + 3, false ) + ret[#ret + 1] = _dumpObject( key, indent + 3, false ) ret[#ret + 1] = '] = ' - ret[#ret + 1] = _logObject( object[key], indent + 2, true ) + ret[#ret + 1] = _dumpObject( object[key], indent + 2, true ) ret[#ret + 1] = ",\n" end ret[#ret + 1] = string.rep( " ", indent ) @@ -622,10 +622,14 @@ function mw.logObject( object, prefix ) return doneObj[object] end end + return _dumpObject( object, 0, true ) +end + +function mw.logObject( object, prefix ) if prefix and prefix ~= '' then logBuffer = logBuffer .. prefix .. ' = ' end - logBuffer = logBuffer .. _logObject( object, 0, true ) .. '\n' + logBuffer = logBuffer .. mw.dumpObject( object ) .. '\n' end function mw.clearLogBuffer()