lua-users home
lua-l archive

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


Diego Nehab wrote:

Hi,

i was looking for a way to create lua stand alone
with luasocket as a single binary. my search
has returned nil so far.

any pointers or links would be most helpful.


There are two independent issues to that.

One is how to get require"foo" to find a package "foo" that was linked
statically to the executable,  instead of trying to load it from the
disk. The standard way to do this is via the Lua package proposal, by
means of the package.preload table.

Placing a function in package.preload["foo"] will instruct require"foo"
to use that function as the loader instead of trying to find it
automatically by other means.

The other issue is how to get the many Lua modules in LuaSocket to get
linked statically to your executable. For that, you should use luac and
bin2c, both available from the Lua distribution.

Once you are familiar with these two issues, it's just a matter of placing all the loaders into package.preload during the initialization of your binary.

Regards,
Diego.

I have done this as I have commented before and there was a problem
where socket.lua did a require("lsocket"). This meant that if you pre loaded
the C library :- lsocket which actually imports into the "socket" namespace then the lua code is never loaded. My fix to this was to import the C functions into
the "lsocket" namespace and assign the functions

socket.<x> = lsocket.<x>

when the socket lua module is loaded. Has the behaviour of the compat-5.1
module changed so that this no longer is a problem?

/Brian