lua string.dump
2015-06-26 18:16
1141 查看
string.dump在lua manual 上的描述是:
string.dump (function [, strip])
Returns a string containing a binary representation (a binary chunk) of the given function, so that a later
this string returns a copy of the function (but with new upvalues). If
Functions with upvalues have only their number of upvalues saved. When (re)loaded, those upvalues receive fresh instances containing nil. (You can use the debug library to serialize and reload the upvalues of a
function in a way adequate to your needs.)
返回一个字符串,该字符串包含一个函数的二进制描述,之后可以用load加载这个函数的拷贝。如果strip参数为true,那么函数拷贝为减少空间将不会包含任何调试信息。
函数只保存upvalues的数目。当重新加载时,所有的upvalue设置为nil。
举个简单的例子:
string.dump (function [, strip])
Returns a string containing a binary representation (a binary chunk) of the given function, so that a later
loadon
this string returns a copy of the function (but with new upvalues). If
stripis a true value, the binary representation may not include all debug information about the function, to save space.
Functions with upvalues have only their number of upvalues saved. When (re)loaded, those upvalues receive fresh instances containing nil. (You can use the debug library to serialize and reload the upvalues of a
function in a way adequate to your needs.)
返回一个字符串,该字符串包含一个函数的二进制描述,之后可以用load加载这个函数的拷贝。如果strip参数为true,那么函数拷贝为减少空间将不会包含任何调试信息。
函数只保存upvalues的数目。当重新加载时,所有的upvalue设置为nil。
举个简单的例子:
function test(n) print("test:",n) end a = string.dump(test, true); b = load(a); b(6) -->test:6可以看出函数能被当成参数进行传递!string.dump实现了函数的序列化,能在不同的作用域进行传递。
相关文章推荐
- 触摸精灵lua脚本实现微信群加好友功能
- lua中table如何安全移除元素
- Lua FFI 简单封装 libpcap
- lua5.3 和 vs2010 环境搭建
- lua学习--记录
- Lua Rings库介绍
- Lua面向对象编程系列-通过Table和Closure来实现类机制
- Lua面向对象编程系列-通过Table和Metatable来实现类机制
- Love中conf.lua更改屏幕大小未生效问题
- 让Xcode Lua 语法高亮
- 利用AssetsManager实现在线更新脚本文件lua、js、图片等资源(免去平台审核周期)
- LuaTinker
- lua学习--特殊字符
- [G+smo]gsGeometryEvaluator
- lua学习--冒泡排序和保存奇数
- Lua 与C/C++ 交互系列:利用模板技术在Lua Code中注册C++类
- luasocket是怎么调用socket.core的
- 如何评估机器学习模型(How to Evaluate Machine Learning Models)
- Lua学习二
- luabind 导出string问题