lua 打印 table 拷贝table
-- 打印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的更多相关文章
- lua实现深度拷贝table表
lua当变量作为函数的参数进行传递时,类似的也是boolean,string,number类型的变量进行值传递.而table,function,userdata类型的变量进行引用传递.故而当table ...
- lua中打印所以类型功能实现table嵌套table
lua中打印所以类型功能实现 本人測试 number.string.bool.nil.table嵌套table.userdata没问题 共享一下有什么问题请拍砖 代码例如以下 cclog = func ...
- Lua打印Table的数据结构工具类
--这是quick中的工具,作用就是打印Lua中强大的table的结构, 当table的嵌套层级比较多的时候,这个工具非常方便,开发中必备的工具. --具体使用方法:local debug = req ...
- Lua打印table树形结构
--这是quick中的工具,作用就是打印Lua中强大的table的结构, 当table的嵌套层级比较多的时候,这个工具非常方便,开发中必备的工具.--具体使用方法:local debug = requ ...
- Cocos2d-x 脚本语言Lua基本数据结构-表(table)
Cocos2d-x 脚本语言Lua基本数据结构-表(table) table是Lua中唯一的数据结构.其它语言所提供的数据结构,如:arrays.records.lists.queues.sets等. ...
- ORA-01747: user.table.column, table.column 或列说明无效
Oracle.DataAccess.Client.OracleException ORA-01747: user.table.column, table.column 或列说明无效 原因1: 查了一下 ...
- 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 ...
- SQLServer temporary table and table variable
Temporary tables are created in tempdb. The name "temporary" is slightly misleading, for ...
- Oracle10g 回收站及彻底删除table : drop table xx purge
drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 1.通过查询回收站user_recyclebin获取被删除的表信息, ...
随机推荐
- Windows下生成 公钥 私钥以及 配置 Filezilla中的 SFTP的私钥
Win下需要使用到 PuTTYgen.exe来生成公钥私钥,可以参考youtube的这篇文章: 为 SFTP 保管箱生成 Secure Shell (SSH) 密钥对 PuTTYgen.exe的下载 ...
- 关于Android架构那些事
刚开始,因为业务比较赶,我们也没有进行比较好的顶层设计,对代码的要求也是最低要求——完成功能开发就行了.这种短期设计也就造成了我们代码的扩展性几乎为零,稍微添加一点新功能,都要大动干戈.在后台系统架构 ...
- 如何实现jenkins的多平台任务同时执行
如果需要我们的程序在多个平台(linux.mac.window)同时执行,该如何操作 1.首先需要构建一个“多配置项目” 2.配置项目在过个平台上运行
- django queryset合并问题
今天在实现搜索时遇到一个问题,如何同时搜索model里面的title以及content和category字典 contents = Blog.objects.filter(content__conta ...
- Android(Fragment和Activity之间通信)
Fragment的使用可以让我们的应用更灵活的适配各种型号的安卓设备,但是对于Fragment和Activity之间的通信,很多朋友应该比较陌生,下面我们就通过一个实例来看一看如何实现. 一.Acti ...
- 解决phpcms使用php7.1.9时修改后台菜单错误 "[] operator not supported for strings"错误提示
出现这个错误提示是因为 $array 在初始化的时候是一个字符串,在下面使用的时候作为数组使用,php7.x版本并没有将$array自动转换为 数组而是以字符串存在"[]"作为了运 ...
- Spark Streaming updateStateByKey和mapWithState源码解密
本篇从二个方面进行源码分析: 一.updateStateByKey解密 二.mapWithState解密 通过对Spark研究角度来研究jvm.分布式.图计算.架构设计.软件工程思想,可以学到很多东西 ...
- sqlite developer注册码
sqlite developer注册码网上没有找到,只有通过注册表,删除继续使用,删除注册表中 HKEY_CURRENT_USER\SharpPlus\SqliteDev.
- 使用JTextArea示例
相对于JLabel显示提示文字,JTextArea有一个先天优势:文字可以拷贝出来.经过下面设置它也能在外观上和JLabel一致. 代码如下: JTextArea txtArea=new JTextA ...
- 在weblogic上配置数据源
转自:http://blog.csdn.net/weijie_search/article/details/2756585 旁白 这是在weblogic9.0+mysql5.1的环境下配置的数据源.其 ...