-- 打印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. android4.1 JELLY_BEAN:All WebView methods must be called on the same thread[问题已解决]

    11-06 18:29:15.582: W/WebView(27807): java.lang.Throwable: A WebView method was called on thread 'Ja ...

  2. 兄弟连新版Linux视频教程

    兄弟连新版Linux视频教程目录:F:\linux\兄弟连新版Linux视频教程├(1)云计算是什么东西集群又是嘛玩意?.mp4├(2)兄弟连新版Linux教程 1.1.1 Linux系统简介-UNI ...

  3. API Monitor---------------Using API Monitor to crack copy protected software

    For this tutorial we will be using Mirial Softphone which is a HD video conferencing application. Th ...

  4. 如何编写一个shellcode

    ShellCode的编写就是将函数或变量在内存中的间接地址改为函数或变量在内存中的直接地址,直接调用! 以MessageBox函数为例进行讲解如下 新建shellcode.cpp: 编写代码如下: 运 ...

  5. [80Sec]深掘XSS漏洞场景之XSS Rootkit

    顶80SEC的牛. 深掘XSS漏洞场景之XSS Rootkit[完整修订版] EMail: rayh4c#80sec.com Site: http://www.80sec.com Date: 2011 ...

  6. 【算法导论C++代码】Strassen算法

    简单方阵矩乘法 SQUARE-MATRIX-MULTIPLY(A,B) n = A.rows let C be a new n*n natrix to n to n cij = to n cij=ci ...

  7. Spark SQL 代码简要阅读(基于Spark 1.1.0)

    Spark SQL允许相关的查询如SQL,HiveQL或Scala运行在spark上.其核心组件是一个新的RDD:SchemaRDD,SchemaRDDs由行对象组成,并包含一个描述此行对象的每一列的 ...

  8. FireFox插件SQLite Manager的使用

    最近几天开始高IOS数据库来着,一开始就CoreData的学习,结果高了一天没有一点进展. 没法,还是先老实代码着吧,不过用的火狐插件可视化数据库的操作也是不错的似乎. FireFox 插件:SQLi ...

  9. mysql中,由于JDBC连接限制了最大包长度1024B,即1KB,报错“max_allowed_packet' ”

    报错:org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [INS ...

  10. vue - utils for extract-text-webpack-plugin

    描述:将包或包中的文本提取到单独的文件中, 点击查看官网详情: https://www.npmjs.com/package/extract-text-webpack-plugin