lua-users home
lua-l archive

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

2008/10/22 Ryan Knotts <>:
> 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");