lua to native linux binary

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

lua to native linux binary

Vasiliy Tolstov
Hello. Is that possible to convert some lua files to
native linux executable?
Idealy i need static binary, that contains all lua files in my project.

Reply | Threaded
Open this post in threaded view
|

Re: lua to native linux binary

Glenn edgar

Use the utility bin2c

On Aug 10, 2011 12:46 AM, "Vasiliy G Tolstov" <[hidden email]> wrote:
> Hello. Is that possible to convert some lua files to
> native linux executable?
> Idealy i need static binary, that contains all lua files in my project.
>
Reply | Threaded
Open this post in threaded view
|

Re: lua to native linux binary

Luiz Henrique de Figueiredo
In reply to this post by Vasiliy Tolstov
> Hello. Is that possible to convert some lua files to
> native linux executable?
> Idealy i need static binary, that contains all lua files in my project.

Try my srlua
        http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/#srlua

There's also a list of solutions at the end of
        http://lua-users.org/wiki/BinToCee

Reply | Threaded
Open this post in threaded view
|

Re: lua to native linux binary

Axel Kittenberger
In reply to this post by Vasiliy Tolstov
Thats the Lua script I'm using. I'm waving any copyright claims of that:

------------------------------
if #arg < 3 then
        error("Usage: "..arg[0].." [infile] [varname] [outfile]")
end

fin, err = io.open(arg[1], "rb")
if fin == nil then
        error("Cannot open '"..arg[1].."' for reading: "..err)
end

fout, err = io.open(arg[3], "w")
if fout == nil then
        error("Cannot open '"..arg[3].."'for writing: "..err)
end

fout:write("/* created by "..arg[0].." from file "..arg[1].." */\n")
fout:write("#include <stddef.h>\n")
fout:write("const char "..arg[2].."_out[] = {\n")
while true do
        local block = fin:read(16)
        if block == nil then
                break
        end
        for i = 1, #block do
                local val = string.format("%x", block:byte(i))
                if #val < 2 then
                        val = "0" ..val
                end
                fout:write("0x",val,",")
        end
        fout:write("\n")
end
fout:write("};\n\nsize_t "..arg[2].."_size = sizeof("..arg[2].."_out);\n");

fin:close();
fout:close();
------------------------------
In my case with following Makefile rules:
------------------------------
luac.o: luac.c

luac.c: luac.out bin2carray.lua
        lua ./bin2carray.lua luac.out luac luac.c

luac.out: lsyncd.lua
        luac $<
------------------------------


In the past I've been using "objcopy", its theoretically quite an
effective way to store any binary data into an executable or library.
However, I've moved back to standard c-file-array-generation since a)
its really Linux only b) had some complains about some stack bits not
correctly set or something like that, so if you arent into
rocketscience thats binary formats and linking better stay away from
it - like I eventually decided to. I just wished the people within
this craft would make the tools simpler to directly link in arbitrary
data. Thats what I had before:
------------------------------
objarch: | lsyncd.o
        objdump -f lsyncd.o | grep architecture | \
                sed -e "s/,.*$$//" -e "s/[^ ]* \(.*\)/\1/" > $@ || rm $@

objtarget: | lsyncd.o
        objdump -f lsyncd.o | grep "file format" | \
                sed -e "s/.* \(.*\)/\1/" > $@ || rm $@

luac.o: luac.out objarch objtarget
        objcopy --input-target=binary \
                --output-target=`cat objtarget` \
                --binary-architecture=`cat objarch` $< $@

luac.out: lsyncd.lua
        luac $<

Reply | Threaded
Open this post in threaded view
|

Re: lua to native linux binary

Ross Andrews
In reply to this post by Vasiliy Tolstov
Coincidentally, this was actually the topic of my post on Play With Lua this week: http://www.playwithlua.com/?p=44

On Wed, Aug 10, 2011 at 2:45 AM, Vasiliy G Tolstov <[hidden email]> wrote:
Hello. Is that possible to convert some lua files to
native linux executable?
Idealy i need static binary, that contains all lua files in my project.


Reply | Threaded
Open this post in threaded view
|

Re: lua to native linux binary

Vasiliy Tolstov
On Wed, 2011-08-10 at 09:14 -0500, Ross Andrews wrote:

> Coincidentally, this was actually the topic of my post on Play With
> Lua this week: http://www.playwithlua.com/?p=44
>
> On Wed, Aug 10, 2011 at 2:45 AM, Vasiliy G Tolstov
> <[hidden email]> wrote:
>         Hello. Is that possible to convert some lua files to
>         native linux executable?
>         Idealy i need static binary, that contains all lua files in my
>         project.
>        
>

Very thanks for all answers! I'm try all of them!
P.S. Can anybody knowns Go language lua bindings?
golua on github needs some work to compile. May be someone work's
on another binding for Go?