转储函数源代码

lua-users home
wiki

[Zarutian]: 我的建议是添加一种转储函数源代码的方法。这对调试器和序列化器会很有用。

我使用 Tcl 已经有一段时间了,发现 "info body <procedures name>" 这个过程非常方便,我希望 Lua 也有这个功能。

string.dump(<function)>) 可以扩展为 string.dump(<function>,<sourcecode?>),如果 <sourcecode> 不是 nil,则返回函数的源代码。

Example

function bla (n)
  print(n)
end
print(string.dump(bla,true))

将打印

function (n)
  print(n)
end

RecentChanges · preferences
编辑 · 历史
最后编辑于 2007 年 7 月 7 日下午 2:21 GMT (差异)