lua-users home
lua-l archive

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


Do you know if there is anyway to call the C functions in LuaSocket
directly. Since LuaSocket is written in C I was just wondering if I
could use those functions that are included in socket.h in my C code.
Thanks for the help!

Ryan


On Wed, Oct 22, 2008 at 4:35 AM, Jerome Vuarand
<jerome.vuarand@gmail.com> wrote:
> 2008/10/22 Ryan Knotts <jknotts@gmail.com>:
>> I am trying to find some example source code of a luasocket being
>> created in C/C++. I will be using luasocket for some of my modules and
>> I don't want to include another socket library  (sys/socket.h) if I
>> can help it. If all of this is feasible are there any library
>> requirements (-l<some library>) when I go to build this code? I just
>> started learning Lua so I hope I am making sense in what I want to
>> accomplish here.
>
> You can call the module functions just like in Lua. For example to do:
>
> require 'socket'
> s = socket.tcp()
>
> you can write the following C code:
>
> lua_getglobal(L, "require");
> lua_pushstring(L, "socket");
> lua_call(L, 1, 0);
> lua_getglobal(L, "socket");
> lua_getfield(L, -1, "tcp");
> lua_replace(L, -2);
> lua_call(L, 0, 1);
> lua_setglobal(L, "s");
>