Skip to content

Commit

Permalink
Merge pull request #1856 from MikuAuahDark/socket3.1
Browse files Browse the repository at this point in the history
Update LuaSocket to 3.1.0
  • Loading branch information
slime73 authored Oct 8, 2022
2 parents c924d94 + 857cf40 commit 7a85dc9
Show file tree
Hide file tree
Showing 60 changed files with 6,458 additions and 4,191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ libtool
stamp-h1
/src/love
/src/tags
.vs/
.vscode/
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,12 @@ set(LOVE_SRC_3P_LUASOCKET_LIBLUASOCKET
src/libraries/luasocket/libluasocket/udp.c
src/libraries/luasocket/libluasocket/udp.h
src/libraries/luasocket/libluasocket/url.lua.h
src/libraries/luasocket/libluasocket/unix.c
src/libraries/luasocket/libluasocket/unix.h
src/libraries/luasocket/libluasocket/unixdgram.c
src/libraries/luasocket/libluasocket/unixdgram.h
src/libraries/luasocket/libluasocket/unixstream.c
src/libraries/luasocket/libluasocket/unixstream.h
)

set(LOVE_LINK_L3P_LUASOCKET_LIBLUASOCKET)
Expand All @@ -1498,12 +1504,6 @@ else()
set(LOVE_SRC_3P_LUASOCKET_LIBLUASOCKET
${LOVE_SRC_3P_LUASOCKET_LIBLUASOCKET}
src/libraries/luasocket/libluasocket/serial.c
src/libraries/luasocket/libluasocket/unix.c
src/libraries/luasocket/libluasocket/unix.h
src/libraries/luasocket/libluasocket/unixtcp.c
src/libraries/luasocket/libluasocket/unixtcp.h
src/libraries/luasocket/libluasocket/unixudp.c
src/libraries/luasocket/libluasocket/unixudp.h
src/libraries/luasocket/libluasocket/usocket.c
src/libraries/luasocket/libluasocket/usocket.h
)
Expand Down
10 changes: 3 additions & 7 deletions src/libraries/luasocket/libluasocket/auxiliar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
* Auxiliar routines for class hierarchy manipulation
* LuaSocket toolkit
\*=========================================================================*/
#include "luasocket.h"
#include "auxiliar.h"
#include <string.h>
#include <stdio.h>

#include "auxiliar.h"

/*=========================================================================*\
* Exported functions
\*=========================================================================*/
/*-------------------------------------------------------------------------*\
* Initializes the module
\*-------------------------------------------------------------------------*/
Expand Down Expand Up @@ -143,7 +140,7 @@ void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx) {
* otherwise
\*-------------------------------------------------------------------------*/
void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) {
return luaL_checkudata(L, objidx, classname);
return luaL_testudata(L, objidx, classname);
}

/*-------------------------------------------------------------------------*\
Expand All @@ -155,4 +152,3 @@ int auxiliar_typeerror (lua_State *L, int narg, const char *tname) {
luaL_typename(L, narg));
return luaL_argerror(L, narg, msg);
}

20 changes: 13 additions & 7 deletions src/libraries/luasocket/libluasocket/auxiliar.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,26 @@
* reverse mapping are done using lauxlib.
\*=========================================================================*/

#include "lua.h"
#include "lauxlib.h"
#include "compat.h"
#include "luasocket.h"

#ifndef _WIN32
#pragma GCC visibility push(hidden)
#endif

int auxiliar_open(lua_State *L);
void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func);
int auxiliar_tostring(lua_State *L);
void auxiliar_add2group(lua_State *L, const char *classname, const char *group);
void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
int auxiliar_checkboolean(lua_State *L, int objidx);
void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx);
void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx);
void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx);
void auxiliar_setclass(lua_State *L, const char *classname, int objidx);
void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx);
int auxiliar_checkboolean(lua_State *L, int objidx);
int auxiliar_tostring(lua_State *L);
void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx);
int auxiliar_typeerror(lua_State *L, int narg, const char *tname);

#ifndef _WIN32
#pragma GCC visibility pop
#endif

#endif /* AUXILIAR_H */
10 changes: 5 additions & 5 deletions src/libraries/luasocket/libluasocket/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
* Input/Output interface for Lua programs
* LuaSocket toolkit
\*=========================================================================*/
#include "lua.h"
#include "lauxlib.h"
#include "compat.h"

#include "luasocket.h"
#include "buffer.h"

/*=========================================================================*\
Expand Down Expand Up @@ -106,11 +103,14 @@ int buffer_meth_send(lua_State *L, p_buffer buf) {
* object:receive() interface
\*-------------------------------------------------------------------------*/
int buffer_meth_receive(lua_State *L, p_buffer buf) {
int err = IO_DONE, top = lua_gettop(L);
int err = IO_DONE, top;
luaL_Buffer b;
size_t size;
const char *part = luaL_optlstring(L, 3, "", &size);
timeout_markstart(buf->tm);
/* make sure we don't confuse buffer stuff with arguments */
lua_settop(L, 3);
top = lua_gettop(L);
/* initialize buffer with optional extra prefix
* (useful for concatenating previous partial results) */
luaL_buffinit(L, &b);
Expand Down
15 changes: 11 additions & 4 deletions src/libraries/luasocket/libluasocket/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
* The module is built on top of the I/O abstraction defined in io.h and the
* timeout management is done with the timeout.h interface.
\*=========================================================================*/
#include "lua.h"

#include "luasocket.h"
#include "io.h"
#include "timeout.h"

Expand All @@ -34,12 +33,20 @@ typedef struct t_buffer_ {
} t_buffer;
typedef t_buffer *p_buffer;

#ifndef _WIN32
#pragma GCC visibility push(hidden)
#endif

int buffer_open(lua_State *L);
void buffer_init(p_buffer buf, p_io io, p_timeout tm);
int buffer_meth_send(lua_State *L, p_buffer buf);
int buffer_meth_receive(lua_State *L, p_buffer buf);
int buffer_meth_getstats(lua_State *L, p_buffer buf);
int buffer_meth_setstats(lua_State *L, p_buffer buf);
int buffer_meth_send(lua_State *L, p_buffer buf);
int buffer_meth_receive(lua_State *L, p_buffer buf);
int buffer_isempty(p_buffer buf);

#ifndef _WIN32
#pragma GCC visibility pop
#endif

#endif /* BUF_H */
22 changes: 21 additions & 1 deletion src/libraries/luasocket/libluasocket/compat.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include "luasocket.h"
#include "compat.h"

#if LUA_VERSION_NUM==501

/*
** Adapted from Lua 5.2
*/
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup+1, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
int i;
Expand All @@ -16,4 +18,22 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
}
lua_pop(L, nup); /* remove upvalues */
}

/*
** Duplicated from Lua 5.2
*/
void *luasocket_testudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
luaL_getmetatable(L, tname); /* get correct metatable */
if (!lua_rawequal(L, -1, -2)) /* not the same? */
p = NULL; /* value is a userdata with wrong metatable */
lua_pop(L, 2); /* remove both metatables */
return p;
}
}
return NULL; /* value is not a userdata with a metatable */
}

#endif
19 changes: 15 additions & 4 deletions src/libraries/luasocket/libluasocket/compat.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
#ifndef COMPAT_H
#define COMPAT_H

#include "lua.h"
#include "lauxlib.h"

#if LUA_VERSION_NUM==501
void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup);

#ifndef _WIN32
#pragma GCC visibility push(hidden)
#endif

void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup);
void *luasocket_testudata ( lua_State *L, int arg, const char *tname);

#ifndef _WIN32
#pragma GCC visibility pop
#endif

#define luaL_setfuncs luasocket_setfuncs
#define luaL_testudata luasocket_testudata

#endif

#endif
8 changes: 2 additions & 6 deletions src/libraries/luasocket/libluasocket/except.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@
* Simple exception support
* LuaSocket toolkit
\*=========================================================================*/
#include <stdio.h>

#include "lua.h"
#include "lauxlib.h"
#include "compat.h"

#include "luasocket.h"
#include "except.h"
#include <stdio.h>

#if LUA_VERSION_NUM < 502
#define lua_pcallk(L, na, nr, err, ctx, cont) \
Expand Down
10 changes: 9 additions & 1 deletion src/libraries/luasocket/libluasocket/except.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@
* exceptions on error, but that don't interrupt the user script.
\*=========================================================================*/

#include "lua.h"
#include "luasocket.h"

#ifndef _WIN32
#pragma GCC visibility push(hidden)
#endif

int except_open(lua_State *L);

#ifndef _WIN32
#pragma GCC visibility pop
#endif

#endif
14 changes: 7 additions & 7 deletions src/libraries/luasocket/libluasocket/ftp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ end

function metat.__index:login(user, password)
self.try(self.tp:command("user", user or _M.USER))
local code, reply = self.try(self.tp:check{"2..", 331})
local code, _ = self.try(self.tp:check{"2..", 331})
if code == 331 then
self.try(self.tp:command("pass", password or _M.PASSWORD))
self.try(self.tp:check("2.."))
Expand All @@ -66,7 +66,7 @@ end

function metat.__index:pasv()
self.try(self.tp:command("pasv"))
local code, reply = self.try(self.tp:check("2.."))
local _, reply = self.try(self.tp:check("2.."))
local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)"
local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern))
self.try(a and b and c and d and p1 and p2, reply)
Expand All @@ -83,9 +83,9 @@ end

function metat.__index:epsv()
self.try(self.tp:command("epsv"))
local code, reply = self.try(self.tp:check("229"))
local _, reply = self.try(self.tp:check("229"))
local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)"
local d, prt, address, port = string.match(reply, pattern)
local _, _, _, port = string.match(reply, pattern)
self.try(port, "invalid epsv response")
self.pasvt = {
address = self.tp:getpeername(),
Expand All @@ -102,7 +102,7 @@ end
function metat.__index:port(address, port)
self.pasvt = nil
if not address then
address, port = self.try(self.tp:getsockname())
address = self.try(self.tp:getsockname())
self.server = self.try(socket.bind(address, 0))
address, port = self.try(self.server:getsockname())
self.try(self.server:settimeout(_M.TIMEOUT))
Expand All @@ -118,7 +118,7 @@ end
function metat.__index:eprt(family, address, port)
self.pasvt = nil
if not address then
address, port = self.try(self.tp:getsockname())
address = self.try(self.tp:getsockname())
self.server = self.try(socket.bind(address, 0))
address, port = self.try(self.server:getsockname())
self.try(self.server:settimeout(_M.TIMEOUT))
Expand All @@ -142,7 +142,7 @@ function metat.__index:send(sendt)
local command = sendt.command or "stor"
-- send the transfer command and check the reply
self.try(self.tp:command(command, argument))
local code, reply = self.try(self.tp:check{"2..", "1.."})
local code, _ = self.try(self.tp:check{"2..", "1.."})
-- if there is not a pasvt table, then there is a server
-- and we already sent a PORT command
if not self.pasvt then self:portconnect() end
Expand Down
Loading

0 comments on commit 7a85dc9

Please sign in to comment.