Lua 相当于 Python dis()?

发布于 2024-09-26 07:33:13 字数 99 浏览 1 评论 0原文

在 Python 中,您可以使用 dis 查看用户定义函数的已编译字节码。

Lua 是否有与此等效的内置函数?

真的很有用!

In Python you have the ability to view the compiled bytecode of a user-defined function using dis.

Is there a builtin equivalent to this for Lua?

It would really useful!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

动听の歌 2024-10-03 07:33:13

标准lua附带的luac实用程序可以使用其-l选项从Lua源创建程序集列表。例如,从 stdin 上的源代码进行编译:

C:...> echo a=b | luac -l -

main  (3 instructions, 12 bytes at 00334C30)
0+ params, 2 slots, 0 upvalues, 0 locals, 2 constants, 0 functions
        1       [1]     GETGLOBAL       0 -2    ; b
        2       [1]     SETGLOBAL       0 -1    ; a
        3       [1]     RETURN          0 1
C:...> 

The luac utility that comes with standard lua can create an assembly listing from Lua source using its -l option. For example, compiling from source on stdin:

C:...> echo a=b | luac -l -

main  (3 instructions, 12 bytes at 00334C30)
0+ params, 2 slots, 0 upvalues, 0 locals, 2 constants, 0 functions
        1       [1]     GETGLOBAL       0 -2    ; b
        2       [1]     SETGLOBAL       0 -1    ; a
        3       [1]     RETURN          0 1
C:...> 
又爬满兰若 2024-10-03 07:33:13

Chunkspy 可能就是您要找的。引自该网站:

ChunkSpy 是一个将 Lua 5 二进制块分解为详细列表的工具,然后可以对其进行研究。它的输出与汇编器的输出列表类似。我想要一些可以详细告诉我 Lua 二进制块文件内部发生的事情的东西,而不仅仅是指令。它也旨在成为学习 Lua 内部原理的工具。

Chunkspy might be what you're looking for. Quoting from the site:

ChunkSpy is a tool to disassemble a Lua 5 binary chunk into a verbose listing that can then be studied. Its output bears a resemblance to the output listing of assemblers. I wanted something that can tell me in great detail what goes on inside a Lua binary chunk file, not just the instructions. It is intended to be a tool for learning Lua internals as well.

故事↓在人 2024-10-03 07:33:13

还有 lbci,一个字节码检查器库。

There is also lbci, a bytecode inspector library.

红玫瑰 2024-10-03 07:33:13

您还可以使用 luac -l 编译 lua 文件并输出反汇编结果。

You can also use luac -l to compile a lua file and output the disassembly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文