Add basic lua 5.3 support

This commit is contained in:
Bart van Strien
2015-06-16 10:25:41 +02:00
parent df1bd42dec
commit 3cb777e2b7
39 changed files with 252 additions and 187 deletions
@@ -11,6 +11,8 @@
#include "except.h"
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Internal function prototypes.
\*=========================================================================*/
@@ -94,6 +96,6 @@ static int global_protect(lua_State *L) {
* Init module
\*-------------------------------------------------------------------------*/
int except_open(lua_State *L) {
luaL_openlib(L, NULL, func, 0);
luax_register(L, NULL, func);
return 0;
}
+3 -1
View File
@@ -12,6 +12,8 @@
#include "inet.h"
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Internal function prototypes.
\*=========================================================================*/
@@ -38,7 +40,7 @@ int inet_open(lua_State *L)
{
lua_pushstring(L, "dns");
lua_newtable(L);
luaL_openlib(L, NULL, func, 0);
luax_register(L, NULL, func);
lua_settable(L, -3);
return 0;
}
@@ -37,6 +37,8 @@
#include "udp.h"
#include "select.h"
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*-------------------------------------------------------------------------*\
* Internal function prototypes
\*-------------------------------------------------------------------------*/
@@ -69,7 +71,7 @@ static luaL_reg func[] = {
* Skip a few arguments
\*-------------------------------------------------------------------------*/
static int global_skip(lua_State *L) {
int amount = luaL_checkint(L, 1);
int amount = (int) luaL_checknumber(L, 1);
int ret = lua_gettop(L) - amount - 1;
return ret >= 0 ? ret : 0;
}
@@ -89,7 +91,7 @@ static int global_unload(lua_State *L) {
static int base_open(lua_State *L) {
if (socket_open()) {
/* export functions (and leave namespace table on top of stack) */
luaL_openlib(L, "socket", func, 0);
luax_register(L, "socket", func);
#ifdef LUASOCKET_DEBUG
lua_pushstring(L, "_DEBUG");
lua_pushboolean(L, 1);
+4 -2
View File
@@ -15,6 +15,8 @@
#include "mime.h"
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Don't want to trust escape character constants
\*=========================================================================*/
@@ -83,7 +85,7 @@ static UC b64unbase[256];
\*-------------------------------------------------------------------------*/
MIME_API int luaopen_mime_core(lua_State *L)
{
luaL_openlib(L, "mime", func, 0);
luax_register(L, "mime", func);
/* make version string available to scripts */
lua_pushstring(L, "_VERSION");
lua_pushstring(L, MIME_VERSION);
@@ -644,7 +646,7 @@ static int eolprocess(int c, int last, const char *marker,
\*-------------------------------------------------------------------------*/
static int mime_global_eol(lua_State *L)
{
int ctx = luaL_checkint(L, 1);
int ctx = (int) luaL_checknumber(L, 1);
size_t isize = 0;
const char *input = luaL_optlstring(L, 2, NULL, &isize);
const char *last = input + isize;
@@ -13,6 +13,8 @@
#include "timeout.h"
#include "select.h"
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Internal function prototypes.
\*=========================================================================*/
@@ -39,7 +41,7 @@ static luaL_reg func[] = {
* Initializes module
\*-------------------------------------------------------------------------*/
int select_open(lua_State *L) {
luaL_openlib(L, NULL, func, 0);
luax_register(L, NULL, func);
return 0;
}
+3 -1
View File
@@ -15,6 +15,8 @@
#include "options.h"
#include "tcp.h"
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Internal function prototypes
\*=========================================================================*/
@@ -92,7 +94,7 @@ int tcp_open(lua_State *L)
auxiliar_add2group(L, "tcp{client}", "tcp{any}");
auxiliar_add2group(L, "tcp{server}", "tcp{any}");
/* define library functions */
luaL_openlib(L, NULL, func, 0);
luax_register(L, NULL, func);
return 0;
}
@@ -27,6 +27,8 @@
#define MAX(x, y) ((x) > (y) ? x : y)
#endif
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Internal function prototypes
\*=========================================================================*/
@@ -144,7 +146,7 @@ double timeout_gettime(void) {
* Initializes module
\*-------------------------------------------------------------------------*/
int timeout_open(lua_State *L) {
luaL_openlib(L, NULL, func, 0);
luax_register(L, NULL, func);
return 0;
}
+3 -1
View File
@@ -23,6 +23,8 @@
#define MAX(x, y) ((x) > (y) ? x : y)
#endif
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
/*=========================================================================*\
* Internal function prototypes
\*=========================================================================*/
@@ -95,7 +97,7 @@ int udp_open(lua_State *L)
auxiliar_add2group(L, "udp{connected}", "select{able}");
auxiliar_add2group(L, "udp{unconnected}", "select{able}");
/* define library functions */
luaL_openlib(L, NULL, func, 0);
luax_register(L, NULL, func);
return 0;
}
+10 -3
View File
@@ -15,6 +15,9 @@
#include "unix.h"
#include <sys/un.h>
extern void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
extern int luax_c_insistglobal(lua_State *L, const char *k);
/*=========================================================================*\
* Internal function prototypes
\*=========================================================================*/
@@ -90,10 +93,14 @@ int luaopen_socket_unix(lua_State *L) {
auxiliar_add2group(L, "unix{client}", "unix{any}");
auxiliar_add2group(L, "unix{server}", "unix{any}");
/* make sure the function ends up in the package table */
luaL_openlib(L, "socket", func, 0);
/* return the function instead of the 'socket' table */
lua_pushcfunction(L, global_create);
luax_c_insistglobal(L, "socket");
lua_pushstring(L, "unix");
lua_gettable(L, -2);
lua_pushvalue(L, -3);
lua_settable(L, -3);
/* return the function instead of the 'socket' table */
return 1;
}