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
+32 -28
View File
@@ -190,7 +190,7 @@ static ENetPacket *read_packet(lua_State *l, int idx, enet_uint8 *channel_id) {
}
if (argc >= idx+1 && !lua_isnil(l, idx+1)) {
*channel_id = luaL_checkint(l, idx+1);
*channel_id = (int) luaL_checknumber(l, idx+1);
}
packet = enet_packet_create(data, size, flags);
@@ -226,13 +226,13 @@ static int host_create(lua_State *l) {
switch (lua_gettop(l)) {
case 5:
if (!lua_isnil(l, 5)) out_bandwidth = luaL_checkint(l, 5);
if (!lua_isnil(l, 5)) out_bandwidth = (int) luaL_checknumber(l, 5);
case 4:
if (!lua_isnil(l, 4)) in_bandwidth = luaL_checkint(l, 4);
if (!lua_isnil(l, 4)) in_bandwidth = (int) luaL_checknumber(l, 4);
case 3:
if (!lua_isnil(l, 3)) channel_count = luaL_checkint(l, 3);
if (!lua_isnil(l, 3)) channel_count = (int) luaL_checknumber(l, 3);
case 2:
if (!lua_isnil(l, 2)) peer_count = luaL_checkint(l, 2);
if (!lua_isnil(l, 2)) peer_count = (int) luaL_checknumber(l, 2);
}
// printf("host create, peers=%d, channels=%d, in=%d, out=%d\n",
@@ -279,7 +279,7 @@ static int host_service(lua_State *l) {
int timeout = 0, out;
if (lua_gettop(l) > 1)
timeout = luaL_checkint(l, 2);
timeout = (int) luaL_checknumber(l, 2);
out = enet_host_service(host, &event, timeout);
if (out == 0) return 0;
@@ -348,9 +348,9 @@ static int host_connect(lua_State *l) {
switch (lua_gettop(l)) {
case 4:
if (!lua_isnil(l, 4)) data = luaL_checkint(l, 4);
if (!lua_isnil(l, 4)) data = (int) luaL_checknumber(l, 4);
case 3:
if (!lua_isnil(l, 3)) channel_count = luaL_checkint(l, 3);
if (!lua_isnil(l, 3)) channel_count = (int) luaL_checknumber(l, 3);
}
// printf("host connect, channels=%d, data=%d\n", channel_count, data);
@@ -392,7 +392,7 @@ static int host_channel_limit(lua_State *l) {
if (!host) {
return luaL_error(l, "Tried to index a nil host!");
}
int limit = luaL_checkint(l, 2);
int limit = (int) luaL_checknumber(l, 2);
enet_host_channel_limit(host, limit);
return 0;
}
@@ -402,8 +402,8 @@ static int host_bandwidth_limit(lua_State *l) {
if (!host) {
return luaL_error(l, "Tried to index a nil host!");
}
enet_uint32 in_bandwidth = luaL_checkint(l, 2);
enet_uint32 out_bandwidth = luaL_checkint(l, 2);
enet_uint32 in_bandwidth = (int) luaL_checknumber(l, 2);
enet_uint32 out_bandwidth = (int) luaL_checknumber(l, 2);
enet_host_bandwidth_limit(host, in_bandwidth, out_bandwidth);
return 0;
}
@@ -473,7 +473,7 @@ static int host_get_peer(lua_State *l) {
return luaL_error(l, "Tried to index a nil host!");
}
int peer_index = luaL_checkint(l, 2) - 1;
int peer_index = (int) luaL_checknumber(l, 2) - 1;
if (peer_index < 0 || ((size_t) peer_index) >= host->peerCount) {
luaL_argerror (l, 2, "Invalid peer index");
@@ -517,9 +517,9 @@ static int peer_ping(lua_State *l) {
static int peer_throttle_configure(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
enet_uint32 interval = luaL_checkint(l, 2);
enet_uint32 acceleration = luaL_checkint(l, 3);
enet_uint32 deceleration = luaL_checkint(l, 4);
enet_uint32 interval = (int) luaL_checknumber(l, 2);
enet_uint32 acceleration = (int) luaL_checknumber(l, 3);
enet_uint32 deceleration = (int) luaL_checknumber(l, 4);
enet_peer_throttle_configure(peer, interval, acceleration, deceleration);
return 0;
@@ -529,7 +529,7 @@ static int peer_round_trip_time(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
if (lua_gettop(l) > 1) {
enet_uint32 round_trip_time = luaL_checkint(l, 2);
enet_uint32 round_trip_time = (int) luaL_checknumber(l, 2);
peer->roundTripTime = round_trip_time;
}
@@ -542,7 +542,7 @@ static int peer_last_round_trip_time(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
if (lua_gettop(l) > 1) {
enet_uint32 round_trip_time = luaL_checkint(l, 2);
enet_uint32 round_trip_time = (int) luaL_checknumber(l, 2);
peer->lastRoundTripTime = round_trip_time;
}
lua_pushinteger (l, peer->lastRoundTripTime);
@@ -554,7 +554,7 @@ static int peer_ping_interval(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
if (lua_gettop(l) > 1) {
enet_uint32 interval = luaL_checkint(l, 2);
enet_uint32 interval = (int) luaL_checknumber(l, 2);
enet_peer_ping_interval (peer, interval);
}
@@ -572,11 +572,11 @@ static int peer_timeout(lua_State *l) {
switch (lua_gettop(l)) {
case 4:
if (!lua_isnil(l, 4)) timeout_maximum = luaL_checkint(l, 4);
if (!lua_isnil(l, 4)) timeout_maximum = (int) luaL_checknumber(l, 4);
case 3:
if (!lua_isnil(l, 3)) timeout_minimum = luaL_checkint(l, 3);
if (!lua_isnil(l, 3)) timeout_minimum = (int) luaL_checknumber(l, 3);
case 2:
if (!lua_isnil(l, 2)) timeout_limit = luaL_checkint(l, 2);
if (!lua_isnil(l, 2)) timeout_limit = (int) luaL_checknumber(l, 2);
}
enet_peer_timeout (peer, timeout_limit, timeout_minimum, timeout_maximum);
@@ -591,7 +591,7 @@ static int peer_timeout(lua_State *l) {
static int peer_disconnect(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
enet_uint32 data = lua_gettop(l) > 1 ? luaL_checkint(l, 2) : 0;
enet_uint32 data = lua_gettop(l) > 1 ? (int) luaL_checknumber(l, 2) : 0;
enet_peer_disconnect(peer, data);
return 0;
}
@@ -599,7 +599,7 @@ static int peer_disconnect(lua_State *l) {
static int peer_disconnect_now(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
enet_uint32 data = lua_gettop(l) > 1 ? luaL_checkint(l, 2) : 0;
enet_uint32 data = lua_gettop(l) > 1 ? (int) luaL_checknumber(l, 2) : 0;
enet_peer_disconnect_now(peer, data);
return 0;
}
@@ -607,7 +607,7 @@ static int peer_disconnect_now(lua_State *l) {
static int peer_disconnect_later(lua_State *l) {
ENetPeer *peer = check_peer(l, 1);
enet_uint32 data = lua_gettop(l) > 1 ? luaL_checkint(l, 2) : 0;
enet_uint32 data = lua_gettop(l) > 1 ? (int) luaL_checknumber(l, 2) : 0;
enet_peer_disconnect_later(peer, data);
return 0;
}
@@ -683,7 +683,7 @@ static int peer_receive(lua_State *l) {
enet_uint8 channel_id = 0;
if (lua_gettop(l) > 1) {
channel_id = luaL_checkint(l, 2);
channel_id = (int) luaL_checknumber(l, 2);
}
packet = enet_peer_receive(peer, &channel_id);
@@ -770,6 +770,10 @@ static const struct luaL_Reg enet_peer_funcs [] = {
{NULL, NULL}
};
extern "C" {
void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
}
int luaopen_enet(lua_State *l) {
enet_initialize();
atexit(enet_deinitialize);
@@ -777,14 +781,14 @@ int luaopen_enet(lua_State *l) {
// create metatables
luaL_newmetatable(l, "enet_host");
lua_newtable(l); // index
luaL_register(l, NULL, enet_host_funcs);
luax_register(l, NULL, enet_host_funcs);
lua_setfield(l, -2, "__index");
lua_pushcfunction(l, host_gc);
lua_setfield(l, -2, "__gc");
luaL_newmetatable(l, "enet_peer");
lua_newtable(l);
luaL_register(l, NULL, enet_peer_funcs);
luax_register(l, NULL, enet_peer_funcs);
lua_setfield(l, -2, "__index");
lua_pushcfunction(l, peer_tostring);
lua_setfield(l, -2, "__tostring");
@@ -799,7 +803,7 @@ int luaopen_enet(lua_State *l) {
lua_setfield(l, LUA_REGISTRYINDEX, "enet_peers");
luaL_register(l, "enet", enet_funcs);
luax_register(l, "enet", enet_funcs);
// return the enet table created with luaL_register
return 1;
@@ -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;
}