Lua-制作字节码 [英] Lua - make bytecode

查看:177
本文介绍了Lua-制作字节码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我被要求为最简单的代码制作一个字节码:

So, I've been asked to make a bytecode for the simpliest code:

print("Hello, world!")

但是我不知道该怎么做,我似乎也找不到关于如何制作一个人的任何信息...有人可以帮忙吗?我将Lua for Windows用作编译器.非常感谢

But I have no idea how and I can't seem to find any information on how to make one... Can someone please help? I use Lua for Windows as a compiler. Thanks a lot

推荐答案

您可以使用string.dump在不使用luac的情况下从Lua进行操作.尝试一下

You can do it from Lua without luac using string.dump. Try for instance

f=assert(io.open("luac.out","wb"))
assert(f:write(string.dump(assert(loadfile("foo.lua")))))
assert(f:close())

如果要编译的代码在字符串中,请使用load(s).

If the code to be compiled is in a string, use load(s).

您还可以将以下文件另存为luac.lua并从命令行运行它:

You can also save the file below as luac.luaand run it from the command line:

-- bare-bones luac in Lua
-- usage: lua luac.lua file.lua

assert(arg[1]~=nil and arg[2]==nil,"usage: lua luac.lua file.lua")
f=assert(io.open("luac.out","wb"))
assert(f:write(string.dump(assert(loadfile(arg[1])))))
assert(f:close())

这篇关于Lua-制作字节码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆