[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Compiling lua statically with luasockets.
- From: <adimurthy.sriramulu@...>
- Date: Mon, 28 Jul 2008 20:27:26 +0530
Fyi..
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Diego Nehab
Sent: Tuesday, July 15, 2008 10:18 AM
To: Lua list
Subject: RE: Compiling lua statically with luasockets.
Hi,
Please take the time to read and understand
http://loop.luaforge.net/release/preload.html.
Generate a .c/.h file for each .lua file in the list
ftp.lua
http.lua
smtp.lua
tp.lua
ltn12.lua
mime.lua
socket.lua
url.lua
You should now have one C function that is equivalent to each of these
Lua modules. Make sure they have the following names:
ltn12.lua -> luaopen_ltn12
mime.lua -> luaopen_mime
socket.lua -> luaopen_socket
url.lua -> luaopen_socket_url
ftp.lua -> luaopen_socket_ftp
http.lua -> luaopen_socket_http
smtp.lua -> luaopen_socket_smtp
tp.lua -> luaopen_socket_tp
Include the .h files and create the following table in your
lua.c:
static luaL_Reg pre = {
{"socket.core", luaopen_socket_core},
{"mime.core", luaopen_mime_core},
{"socket", luaopen_socket},
{"socket.smtp", luaopen_socket_smtp},
{"socket.http", luaopen_socket_http},
{"socket.ftp", luaopen_socket_ftp},
{"socket.tp", luaopen_socket_tp},
{"socket.url", luaopen_socket_url},
{"mime", luaopen_mime},
{"ltn12", luaopen_mime}
{NULL, NULL}
};
Call this function right after the call to luaL_openlibs in
lua.c:
void initpre(lua_State *L) {
const luaL_Reg *lib = pre;
luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload",
sizeof(pre)/sizeof(pre[0])-1);
for (; pre->func; pre++) {
lua_pushstring(L, pre->name);
lua_pushcfunction(L, pre->func);
lua_rawset(L, -3);
}
lua_pop(L, 1);
}
Compile everything together in a big mush. Voila.
Regards,
Diego
Disclamer: It's late and I didn't test this code, but the idea should
work.
Please do not print this email unless it is absolutely necessary.
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.
WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
www.wipro.com