4

is there a way to create a standalone executable from a simple lua scripts? by simple i mean: i'm just using what lua 5.1 provides.

if so, is there some sort of "cross-compiler" available? i would like create executables for a linux system on my mac osx system.

5 Answers 5

7

You can make Lua scripts executable with chmod +x and adding #!/usr/bin/env lua. But you'll need to have a Lua interpreter installed. For a different approach, see my srlua.

Sign up to request clarification or add additional context in comments.

2 Comments

yes, i know of the #! way ... but i hoped for a way to run the script on a system where lua is not installed. but the srlua thing looks very interesting!
This is neat, I've been trying it out ... but doesn't actually compile the lua code, but wraps lua around the script... if you open the a.out example, you'll see the script embedded.
4

murgaLua packs a single executable compiler, and squish is also reaaaalllly nice to compress lua scripts and even other files and directory trees in 1 simple to distribute file (although you still need a runtime to execute that file).

2 Comments

squish looks quite interesting. maybe i can use it together with some compiler-tool. thanks!
even though i think, that srlua fits my needs best for the case i needed this, thanks for your help again. murgaLua seems to be very interesting project, too.
1

I don't know of any "out-of-the-box" ready for this.

A quite straight forward approach would be to modify the lua interpreter that is shipped with lua to include your custom scripts in the binary (and possibly disable the interactive options of it).

This way you can kick off your script with that executable.

There is a lua2bin (if I remember its name correctly) to convert a lua script to a c-file you may include with your application.

1 Comment

Ah, I spent too long writing that, and Luiz beat me to a relevant answer :)
0

try using Lua's bin2c which will give you C source code of your lua script. If you are using external lua libraries it may be a bit more difficult to pull off, but squish can help with that. Or you can just luaL_loadstring everything

1 Comment

bin2c isn't provided in recent releases. However, there is lua-users.org/wiki/BinToCee
0

LuaJIT 2.0.4 has been released 2015-05-14
(I'm using it on a debian based linux (Crunchbang)

http://luajit.org

$ luajit -v
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/
$ luajit -e 'print(_VERSION)'
Lua 5.1

(stick this at the top of your script)
#!/usr/bin/env luajit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.