-- 打印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. php类库安装xml simplexml

    问题 报错:Call to undefined function dom_import_simplexml() yum install php-dom service restart httpd 参考 ...

  2. iOS面试题合集(77道)

    1.#import和#include的区别 @class? @class一般用于头文件中需要声明该类的某个实例变量的时候用到,在m文 件中还是需要使用#import 而#import比起#includ ...

  3. nginxtomca负载均衡

    Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性: 作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 ...

  4. 流畅的python第五章一等函数学习记录

    在python中,函数是一等对象,一等对象是满足以下条件的程序实体 1在运行时创建 2能复制给变量或数据结构的元素 3能作为参数传给函数 4能作为函数的返回结果 高阶函数(接受函数作为参数或者把函数作 ...

  5. eslint 错误

    是因为你使用了eslint,这个是eslint的规范报错,能不用分号就不用分号. 去掉封号就醒了. 另外,方法的()前面也要有空格,不然页报错: indentifier is not in a cam ...

  6. [Functional Programming Monad] Modify The State Of A State Monad

    Using put to update our state for a given state transaction can make it difficult to modify a given ...

  7. 基于paramiko进行远程执行Linux命令

    直接贴一段代码import paramiko class remote_start(object): def __init__(self,host,username,pwd): self.ssh = ...

  8. WebDriver API——第2部分Exceptions

    Exceptions that may happen in all the webdriver code. exception selenium.common.exceptions.ElementNo ...

  9. ES6 对象转Map

    使用Object.entries const obj = { foo: 'bar', baz: 42 }; const map = new Map(Object.entries(obj)); map ...

  10. 【SSH进阶之路】Struts基本原理 + 实现简单登录(二)

    上面博文,主要简单的介绍了一下SSH的基本概念,比較宏观,作为刚開始学习的人可以有一个总体上的认识,个人觉得对学习有非常好的辅助功能.它不不过一个"瞭望塔".更是检验是否真正掌握全 ...