-- 打印table
function print_lua_table (lua_table, indent)
if lua_table == nil or type(lua_table) ~= "table" then
return
end local function print_func(str)
XLPrint("[Dongyuxxx] " .. tostring(str))
end
indent = indent or
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
print_func(formatting)
print_lua_table(v, indent + )
print_func(szPrefix.."},")
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
print_func(formatting..szValue..",")
end
end
end
--拷贝table
function copy_table(ori_tab)
if type(ori_tab) ~= "table" then
return
end
local new_tab = {}
for k,v in pairs(ori_tab) do
local vtype = type(v)
if vtype == "table" then
new_tab[k] = copy_table(v)
else
new_tab[k] = v
end
end
return new_tab
end function deepcopy(object)
local lookup_table = {}
local function _copy(object)
if type(object) ~= "table" then
return object
elseif lookup_table[object] then
return lookup_table[object]
end local new_table = {}
lookup_table[object] = new_table
for index, value in pairs(object) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(object))
end
return _copy(object)
end

貌似deepcopy更厉害一点,找时间求证一下:

This function returns a deep copy of a given table. The function below also copies the metatable to the new table if there is one, so the behaviour of the copied table is the same as the original. But the 2 tables share the same metatable, you can avoid this by changing this 'getmetatable(object)' to '_copy( getmetatable(object) )'.

lua 打印 table 拷贝table的更多相关文章

  1. lua实现深度拷贝table表

    lua当变量作为函数的参数进行传递时,类似的也是boolean,string,number类型的变量进行值传递.而table,function,userdata类型的变量进行引用传递.故而当table ...

  2. lua中打印所以类型功能实现table嵌套table

    lua中打印所以类型功能实现 本人測试 number.string.bool.nil.table嵌套table.userdata没问题 共享一下有什么问题请拍砖 代码例如以下 cclog = func ...

  3. Lua打印Table的数据结构工具类

    --这是quick中的工具,作用就是打印Lua中强大的table的结构, 当table的嵌套层级比较多的时候,这个工具非常方便,开发中必备的工具. --具体使用方法:local debug = req ...

  4. Lua打印table树形结构

    --这是quick中的工具,作用就是打印Lua中强大的table的结构, 当table的嵌套层级比较多的时候,这个工具非常方便,开发中必备的工具.--具体使用方法:local debug = requ ...

  5. Cocos2d-x 脚本语言Lua基本数据结构-表(table)

    Cocos2d-x 脚本语言Lua基本数据结构-表(table) table是Lua中唯一的数据结构.其它语言所提供的数据结构,如:arrays.records.lists.queues.sets等. ...

  6. ORA-01747: user.table.column, table.column 或列说明无效

    Oracle.DataAccess.Client.OracleException ORA-01747: user.table.column, table.column 或列说明无效 原因1: 查了一下 ...

  7. mysqldump:Couldn't execute 'show create table `tablename`': Table tablename' doesn't exist (1146)

    遇到了一个错误mysqldump: Couldn't execute 'show create table `CONCURRENCY_ERRORS`': Table INVOICE_OLD.CONCU ...

  8. SQLServer temporary table and table variable

    Temporary tables are created in tempdb.  The name "temporary" is slightly misleading, for ...

  9. Oracle10g 回收站及彻底删除table : drop table xx purge

    drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 1.通过查询回收站user_recyclebin获取被删除的表信息, ...

随机推荐

  1. EasyUI numbox输入框,金额格式化显示

    1.HTML文件 <th id="sellerHopePrices_Th">委托方保留价:</th> <td id="sellerHopeP ...

  2. [Android Pro] 使用CursorLoader异步加载数据 from 3.0

    Android 3.0引入了CursorLoader实现异步加载数据,为了避免同步查询数据库时阻塞UI线程的问题.在API 11之前可以通过下载支持库,来使之前的系统支持此功能,下载页面为 http: ...

  3. BZOJ3157: 国王奇遇记 & 3516: 国王奇遇记加强版

    令\[S_i=\sum_{k=1}^n k^i m^k\]我们有\[\begin{eqnarray*}(m-1)S_i & = & mS_i - S_i \\& = & ...

  4. tracepath 路由跟踪命令

    [root@c1 scripts]# tracepath 100.2.4.144    (备注:linux系统) 1: c1.nulige.com (100.2.4.144) 0.047ms pmtu ...

  5. Java实现文件MD5加密

    代码实现: import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.s ...

  6. AllJoyn 的JoinSession() 返回timeout问题

    在项目中AllJoyn一直有个问题困扰着我们:client在加入session时调用JoinSession()函数有时会timeout失败. 注意:是“有时”失败,而有时又运行的很好.这种不确定性问题 ...

  7. global constructor

    HQ在要求我们修改code style后,又让我检查并去掉"global constructor". 第一次听说这玩意,就研究了一下.发现网上有人讨论的很精彩,就记下来. “glo ...

  8. Mapper not initialized. Call Initialize with appropriate configuration.

    System.InvalidOperationException:“Mapper not initialized. Call Initialize with appropriate configura ...

  9. FTP服务器配置

    一.FTP服务器: FTP服务使用FTP协议来进行文件的上传和下载,可以非常方便的进行远距离的文件传输,并可以实现相应的安全控制. FTP和NFS.Samba :三大文件服务器 主动模式:消息端口21 ...

  10. HTML学习笔记(五)

    1.       Javascript是一种脚本语言,它的作用是提供用户交互.动态更改内容.数据验证. 2.       我们使用script标签将javascript的语句嵌入到html文档中. 3 ...