diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2012-12-15 16:32:50 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2012-12-17 10:11:06 +0100 |
commit | 36babe570b4b1718f1ae8e16940a033d896225ef (patch) | |
tree | a96353435191bfe864a978daa5ba665cb2072a7a | |
parent | a78969df5a9589ca51c17dfc20b3a2cfb3f50c46 (diff) | |
download | lem-36babe570b4b1718f1ae8e16940a033d896225ef.tar.gz lem-36babe570b4b1718f1ae8e16940a033d896225ef.tar.xz lem-36babe570b4b1718f1ae8e16940a033d896225ef.zip |
io: put connect and listen in tcp table
-rw-r--r-- | lem/hathaway.lua | 2 | ||||
-rw-r--r-- | lem/io/core.c | 16 | ||||
-rwxr-xr-x | test/ctest.lua | 2 | ||||
-rwxr-xr-x | test/httptest.lua | 4 | ||||
-rwxr-xr-x | test/stest.lua | 2 |
5 files changed, 15 insertions, 11 deletions
diff --git a/lem/hathaway.lua b/lem/hathaway.lua index 032a938..4e327ff 100644 --- a/lem/hathaway.lua +++ b/lem/hathaway.lua @@ -348,7 +348,7 @@ do end function M.Hathaway(...) - local server, err = io.tcp_listen(...) + local server, err = io.tcp.listen(...) if not server then M.debug(err) return nil, err end M.server = server diff --git a/lem/io/core.c b/lem/io/core.c index 72861db..672961f 100644 --- a/lem/io/core.c +++ b/lem/io/core.c @@ -362,14 +362,18 @@ luaopen_lem_io_core(lua_State *L) lua_pushcclosure(L, stream_popen, 1); lua_setfield(L, -2, "popen"); - /* insert the tcp_connect function */ - lua_getfield(L, -1, "Stream"); /* upvalue 1 = Stream */ + /* create tcp table */ + lua_createtable(L, 0, 0); + /* insert the connect function */ + lua_getfield(L, -2, "Stream"); /* upvalue 1 = Stream */ lua_pushcclosure(L, tcp_connect, 1); - lua_setfield(L, -2, "tcp_connect"); - /* insert the tcp_listen function */ - lua_getfield(L, -1, "Server"); /* upvalue 1 = Server */ + lua_setfield(L, -2, "connect"); + /* insert the listen function */ + lua_getfield(L, -2, "Server"); /* upvalue 1 = Server */ lua_pushcclosure(L, tcp_listen, 1); - lua_setfield(L, -2, "tcp_listen"); + lua_setfield(L, -2, "listen"); + /* insert the tcp table */ + lua_setfield(L, -2, "tcp"); /* create parser table */ lua_createtable(L, 0, 4); diff --git a/test/ctest.lua b/test/ctest.lua index ceebebe..b7d87f5 100755 --- a/test/ctest.lua +++ b/test/ctest.lua @@ -22,7 +22,7 @@ print('Entered ' .. arg[0]) local utils = require 'lem.utils' local io = require 'lem.io' -local conn = assert(io.tcp_connect('localhost', arg[1] or 8080)) +local conn = assert(io.tcp.connect('localhost', arg[1] or 8080)) for i = 1, 10 do assert(conn:write('ping\n')) diff --git a/test/httptest.lua b/test/httptest.lua index 1e88f28..0dea30c 100755 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -27,8 +27,8 @@ local concat = table.concat local done = false utils.spawn(function() - local conn = assert(io.tcp_connect('www.google.dk', 80)) - --local conn = assert(io.tcp_connect('127.0.0.1', 8080)) + local conn = assert(io.tcp.connect('www.google.dk', 80)) + --local conn = assert(io.tcp.connect('127.0.0.1', 8080)) print('\nConnected.') diff --git a/test/stest.lua b/test/stest.lua index f156ce7..e9499a1 100755 --- a/test/stest.lua +++ b/test/stest.lua @@ -22,7 +22,7 @@ print('Entered ' .. arg[0]) local utils = require 'lem.utils' local io = require 'lem.io' -local server = assert(io.tcp_listen('*', arg[1] or 8080)) +local server = assert(io.tcp.listen('*', arg[1] or 8080)) --timer(10, function() exit(0) end) utils.spawn(function() |