[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is there an #include equivalent in Lua (I do not mean require)
- From: Sean Conner <sean@...>
- Date: Thu, 18 Sep 2014 14:09:17 -0400
It was thus said that the Great tonyp@acm.org once stated:
> Maybe I wasn't clear enough.
>
> What I meant by executable was a Lua executable (which maintains the
> advantage of portability to any system Lua can run), not something like an
> EXE file.
>
> I need to give someone a compiled Lua program that s/he can run using just
> the Lua interpreter but
> a. without being able to look at the source, and
> b. given as a single file which contains the complete application, rather
> than a tree structure of library files.
>
> Thank you all for your suggestions, I will try them ASAP.
I did start a project a few months ago to address this issue [1], but the code
is still very rough and there were some issues that I could not fully
resolve. The intent was to package up a Lua application into a ZIP file and
run all the code from there. It does work (I'm able to run LuaRocks from
such a package) but the issues I ran into were:
1) Lua modules in C had to be written to disk first before loading;
I could not run C-based modules directly out of the ZIP file.
2) I was able to patch Lua's loadfile() function; I have yet to fix
dofile() or modify io.open() to handle read-only files.
3) Any other type of file that the Lua application required needed
to be written out to disk (becuase they could be opened for
writing). This is still an unresolved issue.
4) It requires a few other modules to be already installed for this
to all work. It's not entirely self-contained.
Now, speaking of ZIP files, perhaps the following will work for you.
Compile the Lua application using luac. Then, write a shell script (or
batch file, depending upon operating system) to run the resulting Lua code,
fixing $LUA_PATH and $LUA_CPATH as required. Take the resulting compiled
Lua code and shell script/batch file, zip them up and give her the resulting
zip file, which the person can unzip and run.
This a) prevents them from seeing the source code and
b) is a single file that contains the complete application.
Yes, there's the addtional extraction phase, but everything should be in
one central location.
-spc
[1] https://github.com/spc476/LEM