lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great mchalkley@mail.com once stated:
> I know this is a sore subject to begin with, and is probaby on the
> "forbidden topics for Mondays" list (or should be), but I'm afraid I
> have to do it anyway.

  [ snip ]

> My objective is to decrease the number of files necessary to deploy
> and also to keep folks from mucking about with the code and screwing
> up something, so compressing/obfuscating/something along those lines
> would be necessary.
> 
> Is there currently a "best way" to do this?

  I don't know of any program to construct a single executable, but here's
how I do it at work (similar problem, but instead of multiple Windows boxes
it's multiple Unix boxes)---I compiled everything into a single executable.

  The main C program is very simple---it's just a single function (main())
that creates a Lua state, calls an initialization function (see below), then
loads the main script (in your case, it looks like it would be
"Monitor.lua") and executes it. 

  The "initialization function" [1] modifies the stock Lua module loader to
look for builtin modules stored (or linked) into the executable (and it
would include Monitor.lua in your case).  The C modules are statically
linked into the executable.  The Lua modules are run through a tool [2] that
converts them into a C file or an object file [3] which are then included
into the final executable.  

  Yeah, it was a chore writing the Makefile to build all this, but now that
it's done, I don't have to worry about it anymore.  But I only recommend
this path if you are comfortable with compiling, linking and writing
makefiles.  There might be an automatic way to do this under Windows, but I
not sure what it is, and it would probably do something like this anyway.

  -spc (Hope this helps some ... )

[1]	http://boston.conman.org/2013/03/23.1

[2]	Just do a search for 'bin2c' and you'll find plenty.

[3]	I first compile the Lua modules with luac, then compress using zlib
	to decrease the size of the executable.  I have found that they
	compress even better if I don't use luac first, but I've been too
	lazy to fix the Makefile.

	I then modified the preloader code to decompress the module when
	loading.  Note---only the modules written in Lua are compressed.