lua-users home
lua-l archive

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


2010/2/4 sagasw <sagasw@gmail.com>:
> I want to implement the function like embedding the socket function in my
> Lua build.
> So I don't need to copy socket.core.dll any more (just for fun).
>
> I search the maillist, and see some guys discuss the topic,
> http://lua-users.org/lists/lua-l/2005-10/msg00269.html
>
> But I have question for the details steps, who could give me a detailed
> steps for changing the lua and luasocket code to make them work together
> (not with dll method).
>
> I tried these steps in windows xp with VC2008:
> 1) copy luasocket code to Lua project.
> 2) add some code
> static const luaL_Reg lualibs[] = {
>   {"", luaopen_base},
>   {LUA_LOADLIBNAME, luaopen_package},
>   {LUA_TABLIBNAME, luaopen_table},
>   {LUA_IOLIBNAME, luaopen_io},
>   {LUA_OSLIBNAME, luaopen_os},
>   {LUA_STRLIBNAME, luaopen_string},
>   {LUA_MATHLIBNAME, luaopen_math},
>   {LUA_DBLIBNAME, luaopen_debug},
>   {LUA_SOCKETLIBNAME, luaopen_socket_core}, // add this line
>   {LUA_MIMELIBNAME, luaopen_socket_core}, // add this line
>   {NULL, NULL}
> };
>
> 3) build the project, and run it.
> When I type “print(socket._VERSION)", it shows "luasocket 2.0.2", it is
> correct.
> When I type "print(socket.dns.toip("localhost"))", it shows "127.0.0.1
> table: 00480AD0", it is correct too.
>
> But when I try to use other features, for example bind, it can't work.
> Who could tell me the reason, thanks,

As opposed to standard modules, LuaSocket is an hybrid Lua/C package.
As the name implies, the luaopen_socket_core functions implements the
socket.core module, not socket. The socket module is implemented in
Lua (in socket.lua).

So you need to make sure luaopen_socket_core is loaded as
"socket.core" (that is the value of LUA_SOCKETLIBNAME), and you need
to embed the socket.lua file and load it somehow.