So, I've been asked to make a bytecode for the simpliest code:
print("Hello, world!")
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
解决方案
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())
If the code to be compiled is in a string, use load(s).
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())