Explorar el Código

Add basic lua 5.3 support

Bart van Strien hace 10 años
padre
commit
3cb777e2b7
Se han modificado 39 ficheros con 252 adiciones y 187 borrados
  1. 6 5
      platform/unix/configure.ac
  2. 30 3
      src/common/runtime.cpp
  3. 10 0
      src/common/runtime.h
  4. 32 28
      src/libraries/enet/enet.cpp
  5. 3 1
      src/libraries/luasocket/libluasocket/except.c
  6. 3 1
      src/libraries/luasocket/libluasocket/inet.c
  7. 4 2
      src/libraries/luasocket/libluasocket/luasocket.c
  8. 4 2
      src/libraries/luasocket/libluasocket/mime.c
  9. 3 1
      src/libraries/luasocket/libluasocket/select.c
  10. 3 1
      src/libraries/luasocket/libluasocket/tcp.c
  11. 3 1
      src/libraries/luasocket/libluasocket/timeout.c
  12. 3 1
      src/libraries/luasocket/libluasocket/udp.c
  13. 10 3
      src/libraries/luasocket/libluasocket/unix.c
  14. 4 4
      src/modules/font/wrap_Font.cpp
  15. 4 4
      src/modules/graphics/opengl/wrap_Canvas.cpp
  16. 40 40
      src/modules/graphics/opengl/wrap_Graphics.cpp
  17. 4 4
      src/modules/graphics/opengl/wrap_Image.cpp
  18. 4 4
      src/modules/graphics/opengl/wrap_Mesh.cpp
  19. 3 3
      src/modules/graphics/opengl/wrap_ParticleSystem.cpp
  20. 6 6
      src/modules/graphics/opengl/wrap_Shader.cpp
  21. 2 2
      src/modules/graphics/opengl/wrap_SpriteBatch.cpp
  22. 3 3
      src/modules/image/wrap_CompressedImageData.cpp
  23. 2 2
      src/modules/image/wrap_Image.cpp
  24. 10 10
      src/modules/image/wrap_ImageData.cpp
  25. 3 3
      src/modules/joystick/wrap_Joystick.cpp
  26. 3 3
      src/modules/joystick/wrap_JoystickModule.cpp
  27. 3 3
      src/modules/love/love.cpp
  28. 5 5
      src/modules/math/wrap_BezierCurve.cpp
  29. 5 5
      src/modules/math/wrap_Math.cpp
  30. 3 3
      src/modules/math/wrap_RandomGenerator.cpp
  31. 3 3
      src/modules/mouse/wrap_Mouse.cpp
  32. 2 2
      src/modules/physics/box2d/Fixture.cpp
  33. 2 2
      src/modules/physics/box2d/Physics.cpp
  34. 2 2
      src/modules/physics/box2d/Shape.cpp
  35. 2 2
      src/modules/physics/box2d/wrap_ChainShape.cpp
  36. 4 4
      src/modules/physics/box2d/wrap_Fixture.cpp
  37. 1 1
      src/modules/physics/box2d/wrap_Physics.cpp
  38. 5 5
      src/modules/sound/wrap_Sound.cpp
  39. 13 13
      src/modules/window/wrap_Window.cpp

+ 6 - 5
platform/unix/configure.ac

@@ -53,8 +53,10 @@ AC_ARG_WITH([luaversion], [AS_HELP_STRING([--with-luaversion], [Select the lua v
 
 # pkg-config libraries
 AM_PATH_SDL2([], [], [LOVE_MSG_ERROR([SDL 2])])
+with_clean_luaversion=`printf ${with_luaversion} | sed 's/\.//g'`
 PKG_CHECK_MODULES([lua], [${with_lua}${with_luaversion}], [lua_found=yes],
-				  [PKG_CHECK_MODULES([lua], [${with_lua}], [lua_found=yes], [lua_found=no])])
+	[PKG_CHECK_MODULES([lua], [${with_lua}${with_clean_luaversion}], [lua_found=yes],
+	[PKG_CHECK_MODULES([lua], [${with_lua}], [lua_found=yes], [lua_found=no])])])
 PKG_CHECK_MODULES([freetype2], [freetype2], [], [LOVE_MSG_ERROR([FreeType2])])
 PKG_CHECK_MODULES([openal], [openal], [], [LOVE_MSG_ERROR([OpenAL])])
 PKG_CHECK_MODULES([libmodplug], [libmodplug], [], [LOVE_MSG_ERROR([libmodplug])])
@@ -66,17 +68,16 @@ AC_SEARCH_LIBS([sqrt], [m], [], [LOVE_MSG_ERROR([the C math library])])
 AC_SEARCH_LIBS([PHYSFS_init], [physfs], [], [LOVE_MSG_ERROR([PhysicsFS])])
 
 # Lua, treated seperately because of --with-lua
-AS_VAR_IF([with_luaversion], [5.2], [luatest=lua_version], [luatest=lua_pcall]) # use lua_version for 5.2
 AS_VAR_IF([lua_found], [yes],
 		  #if
 		  [
 		   luaheaders_found=yes
-		   AC_MSG_CHECKING([for library containing ${luatest}])
+		   AC_MSG_CHECKING([for library containing lua_call])
 		   AC_MSG_RESULT([${lua_LIBS}])],
 		  #else
 		  [
-		   AC_MSG_WARN([Could not find pkg-config definition for ${with_lua}${with_luaversion} or ${with_lua}, falling back to manual detection])
-		   AC_SEARCH_LIBS([$luatest], ["${with_lua}${with_luaversion}" "${with_lua}"], [],
+		   AC_MSG_WARN([Could not find pkg-config definition for ${with_lua}${with_luaversion} or ${with_lua}${with_clean_luaversion}${with_lua}, falling back to manual detection])
+		   AC_SEARCH_LIBS([lua_call], ["${with_lua}${with_luaversion}" "${with_lua}"], [],
 						  [LOVE_MSG_ERROR([$with_lua])])
 		   luaheaders_found=no
 		   AC_CHECK_HEADER(["${with_lua}${with_luaversion}/lua.h"], [luaheaders_found=yes includes="$includes -I/usr/include/${with_lua}${with_luaversion}"], [])

+ 30 - 3
src/common/runtime.cpp

@@ -342,13 +342,13 @@ int luax_table_insert(lua_State *L, int tindex, int vindex, int pos)
 	if (pos == -1)
 	{
 		lua_pushvalue(L, vindex);
-		lua_rawseti(L, tindex, (int) lua_objlen(L, tindex)+1);
+		lua_rawseti(L, tindex, (int) luax_objlen(L, tindex)+1);
 		return 0;
 	}
 	else if (pos < 0)
-		pos = (int) lua_objlen(L, tindex)+1+pos;
+		pos = (int) luax_objlen(L, tindex)+1+pos;
 
-	for (int i = (int) lua_objlen(L, tindex)+1; i > pos; i--)
+	for (int i = (int) luax_objlen(L, tindex)+1; i > pos; i--)
 	{
 		lua_rawgeti(L, tindex, i-1);
 		lua_rawseti(L, tindex, i);
@@ -556,6 +556,11 @@ int luax_insistglobal(lua_State *L, const char *k)
 	return 1;
 }
 
+int luax_c_insistglobal(lua_State *L, const char *k)
+{
+	return luax_insistglobal(L, k);
+}
+
 int luax_insistlove(lua_State *L, const char *k)
 {
 	luax_insistglobal(L, "love");
@@ -640,6 +645,28 @@ extern "C" int luax_typerror(lua_State *L, int narg, const char *tname)
 	return luaL_argerror(L, narg, msg);
 }
 
+int luax_objlen(lua_State *L, int ndx)
+{
+#if LUA_VERSION_NUM == 501
+	return lua_objlen(L, ndx);
+#else
+	return lua_rawlen(L, ndx);
+#endif
+}
+
+void luax_register(lua_State *L, const char *name, const luaL_Reg *l)
+{
+	if (name)
+		lua_newtable(L);
+
+	luax_setfuncs(L, l);
+	if (name)
+	{
+		lua_pushvalue(L, -1);
+		lua_setglobal(L, name);
+	}
+}
+
 Type luax_type(lua_State *L, int idx)
 {
 	Type t = INVALID_ID;

+ 10 - 0
src/common/runtime.h

@@ -394,6 +394,16 @@ extern "C" { // Also called from luasocket
 	int luax_typerror(lua_State *L, int narg, const char *tname);
 }
 
+/**
+ * Calls luax_objlen/lua_rawlen depending on version
+ **/
+int luax_objlen(lua_State *L, int ndx);
+
+extern "C" { // Called by enet and luasocket
+	void luax_register(lua_State *L, const char *name, const luaL_Reg *l);
+	int luax_c_insistglobal(lua_State *L, const char *k);
+}
+
 /**
  * Like luax_totype, but causes an error if the value at idx is not Proxy,
  * or is not the specified type.

+ 32 - 28
src/libraries/enet/enet.cpp

@@ -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;

+ 3 - 1
src/libraries/luasocket/libluasocket/except.c

@@ -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
src/libraries/luasocket/libluasocket/inet.c

@@ -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;
 }

+ 4 - 2
src/libraries/luasocket/libluasocket/luasocket.c

@@ -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
src/libraries/luasocket/libluasocket/mime.c

@@ -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;

+ 3 - 1
src/libraries/luasocket/libluasocket/select.c

@@ -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
src/libraries/luasocket/libluasocket/tcp.c

@@ -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;
 }
 

+ 3 - 1
src/libraries/luasocket/libluasocket/timeout.c

@@ -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
src/libraries/luasocket/libluasocket/udp.c

@@ -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
src/libraries/luasocket/libluasocket/unix.c

@@ -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;
 }
 

+ 4 - 4
src/modules/font/wrap_Font.cpp

@@ -72,7 +72,7 @@ int w_newTrueTypeRasterizer(lua_State *L)
 	if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1))
 	{
 		// First argument is a number: use the default TrueType font.
-		int size = luaL_optint(L, 1, 12);
+		int size = (int) luaL_optnumber(L, 1, 12);
 
 		const char *hintstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2);
 		if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
@@ -89,7 +89,7 @@ int w_newTrueTypeRasterizer(lua_State *L)
 		else
 			d = filesystem::luax_getfiledata(L, 1);
 
-		int size = luaL_optint(L, 2, 12);
+		int size = (int) luaL_optnumber(L, 2, 12);
 
 		const char *hintstr = lua_isnoneornil(L, 3) ? nullptr : luaL_checkstring(L, 3);
 		if (hintstr && !TrueTypeRasterizer::getConstant(hintstr, hinting))
@@ -121,7 +121,7 @@ int w_newBMFontRasterizer(lua_State *L)
 
 	if (lua_istable(L, 2))
 	{
-		for (int i = 1; i <= (int) lua_objlen(L, 2); i++)
+		for (int i = 1; i <= (int) luax_objlen(L, 2); i++)
 		{
 			lua_rawgeti(L, 2, i);
 
@@ -162,7 +162,7 @@ int w_newImageRasterizer(lua_State *L)
 
 	image::ImageData *d = luax_checktype<image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
 	std::string glyphs = luax_checkstring(L, 2);
-	int extraspacing = luaL_optint(L, 3, 0);
+	int extraspacing = (int) luaL_optnumber(L, 3, 0);
 
 	luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing); });
 

+ 4 - 4
src/modules/graphics/opengl/wrap_Canvas.cpp

@@ -66,10 +66,10 @@ int w_Canvas_newImageData(lua_State *L)
 {
 	Canvas *canvas = luax_checkcanvas(L, 1);
 	love::image::Image *image = luax_getmodule<love::image::Image>(L, MODULE_IMAGE_ID);
-	int x = luaL_optint(L, 2, 0);
-	int y = luaL_optint(L, 3, 0);
-	int w = luaL_optint(L, 4, canvas->getWidth());
-	int h = luaL_optint(L, 5, canvas->getHeight());
+	int x = (int) luaL_optnumber(L, 2, 0);
+	int y = (int) luaL_optnumber(L, 3, 0);
+	int w = (int) luaL_optnumber(L, 4, canvas->getWidth());
+	int h = (int) luaL_optnumber(L, 5, canvas->getHeight());
 
 	love::image::ImageData *img = nullptr;
 	luax_catchexcept(L, [&](){ img = canvas->newImageData(image, x, y, w, h); });

+ 40 - 40
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -94,7 +94,7 @@ int w_discard(lua_State *L)
 
 	if (lua_istable(L, 1))
 	{
-		for (size_t i = 1; i <= lua_objlen(L, 1); i++)
+		for (size_t i = 1; i <= luax_objlen(L, 1); i++)
 		{
 			lua_rawgeti(L, 1, i);
 			colorbuffers.push_back(luax_optboolean(L, -1, true));
@@ -161,10 +161,10 @@ int w_setScissor(lua_State *L)
 		return 0;
 	}
 
-	int x = luaL_checkint(L, 1);
-	int y = luaL_checkint(L, 2);
-	int w = luaL_checkint(L, 3);
-	int h = luaL_checkint(L, 4);
+	int x = (int) luaL_checknumber(L, 1);
+	int y = (int) luaL_checknumber(L, 2);
+	int w = (int) luaL_checknumber(L, 3);
+	int h = (int) luaL_checknumber(L, 4);
 
 	if (w < 0 || h < 0)
 		return luaL_error(L, "Can't set scissor with negative width and/or height.");
@@ -392,7 +392,7 @@ int w_newImageFont(lua_State *L)
 int w_newSpriteBatch(lua_State *L)
 {
 	Texture *texture = luax_checktexture(L, 1);
-	int size = luaL_optint(L, 2, 1000);
+	int size = (int) luaL_optnumber(L, 2, 1000);
 	Mesh::Usage usage = Mesh::USAGE_DYNAMIC;
 	if (lua_gettop(L) > 2)
 	{
@@ -431,10 +431,10 @@ int w_newParticleSystem(lua_State *L)
 int w_newCanvas(lua_State *L)
 {
 	// check if width and height are given. else default to screen dimensions.
-	int width       = luaL_optint(L, 1, instance()->getWidth());
-	int height      = luaL_optint(L, 2, instance()->getHeight());
+	int width       = (int) luaL_optnumber(L, 1, instance()->getWidth());
+	int height      = (int) luaL_optnumber(L, 2, instance()->getHeight());
 	const char *str = luaL_optstring(L, 3, "normal");
-	int msaa        = luaL_optint(L, 4, 0);
+	int msaa        = (int) luaL_optnumber(L, 4, 0);
 
 	Canvas::Format format;
 	if (!Canvas::getConstant(str, format))
@@ -600,7 +600,7 @@ static Mesh *newStandardMesh(lua_State *L)
 	// standard vertices.
 	if (lua_istable(L, 1))
 	{
-		size_t vertexcount = lua_objlen(L, 1);
+		size_t vertexcount = luax_objlen(L, 1);
 		std::vector<Vertex> vertices;
 		vertices.reserve(vertexcount);
 
@@ -637,7 +637,7 @@ static Mesh *newStandardMesh(lua_State *L)
 	}
 	else
 	{
-		int count = luaL_checkint(L, 1);
+		int count = (int) luaL_checknumber(L, 1);
 		luax_catchexcept(L, [&](){ t = instance()->newMesh(count, drawmode, usage); });
 	}
 
@@ -664,7 +664,7 @@ static Mesh *newCustomMesh(lua_State *L)
 	lua_pop(L, 1);
 
 	// Per-vertex attribute formats.
-	for (int i = 1; i <= (int) lua_objlen(L, 1); i++)
+	for (int i = 1; i <= (int) luax_objlen(L, 1); i++)
 	{
 		lua_rawgeti(L, 1, i);
 
@@ -682,7 +682,7 @@ static Mesh *newCustomMesh(lua_State *L)
 			return nullptr;
 		}
 
-		format.components = luaL_checkint(L, -1);
+		format.components = (int) luaL_checknumber(L, -1);
 		if (format.components <= 0 || format.components > 4)
 		{
 			luaL_error(L, "Number of vertex attribute components must be between 1 and 4 (got %d)", format.components);
@@ -695,7 +695,7 @@ static Mesh *newCustomMesh(lua_State *L)
 
 	if (lua_isnumber(L, 2))
 	{
-		int vertexcount = luaL_checkint(L, 2);
+		int vertexcount = (int) luaL_checknumber(L, 2);
 		luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, vertexcount, drawmode, usage); });
 	}
 	else if (luax_istype(L, 2, DATA_ID))
@@ -719,7 +719,7 @@ static Mesh *newCustomMesh(lua_State *L)
 		for (const Mesh::AttribFormat &format : vertexformat)
 			vertexcomponents += format.components;
 
-		size_t numvertices = lua_objlen(L, 2);
+		size_t numvertices = luax_objlen(L, 2);
 
 		luax_catchexcept(L, [&](){ t = instance()->newMesh(vertexformat, numvertices, drawmode, usage); });
 
@@ -732,11 +732,11 @@ static Mesh *newCustomMesh(lua_State *L)
 			lua_rawgeti(L, 2, vertindex + 1);
 			luaL_checktype(L, -1, LUA_TTABLE);
 
-			if ((int) lua_objlen(L, -1) < vertexcomponents)
+			if ((int) luax_objlen(L, -1) < vertexcomponents)
 			{
 				t->release();
 				const char *err = "Invalid number of components in vertex #%d (expected %d components, got %d)";
-				luaL_error(L, err, vertindex+1, vertexcomponents, lua_objlen(L, -1));
+				luaL_error(L, err, vertindex+1, vertexcomponents, luax_objlen(L, -1));
 				return nullptr;
 			}
 
@@ -827,19 +827,19 @@ int w_setColor(lua_State *L)
 		for (int i = 1; i <= 4; i++)
 			lua_rawgeti(L, 1, i);
 
-		c.r = (unsigned char)luaL_checkint(L, -4);
-		c.g = (unsigned char)luaL_checkint(L, -3);
-		c.b = (unsigned char)luaL_checkint(L, -2);
-		c.a = (unsigned char)luaL_optint(L, -1, 255);
+		c.r = (unsigned char) luaL_checknumber(L, -4);
+		c.g = (unsigned char) luaL_checknumber(L, -3);
+		c.b = (unsigned char) luaL_checknumber(L, -2);
+		c.a = (unsigned char) luaL_optnumber(L, -1, 255);
 
 		lua_pop(L, 4);
 	}
 	else
 	{
-		c.r = (unsigned char)luaL_checkint(L, 1);
-		c.g = (unsigned char)luaL_checkint(L, 2);
-		c.b = (unsigned char)luaL_checkint(L, 3);
-		c.a = (unsigned char)luaL_optint(L, 4, 255);
+		c.r = (unsigned char) luaL_checknumber(L, 1);
+		c.g = (unsigned char) luaL_checknumber(L, 2);
+		c.b = (unsigned char) luaL_checknumber(L, 3);
+		c.a = (unsigned char) luaL_optnumber(L, 4, 255);
 	}
 	instance()->setColor(c);
 	return 0;
@@ -863,19 +863,19 @@ int w_setBackgroundColor(lua_State *L)
 		for (int i = 1; i <= 4; i++)
 			lua_rawgeti(L, 1, i);
 
-		c.r = (unsigned char)luaL_checkint(L, -4);
-		c.g = (unsigned char)luaL_checkint(L, -3);
-		c.b = (unsigned char)luaL_checkint(L, -2);
-		c.a = (unsigned char)luaL_optint(L, -1, 255);
+		c.r = (unsigned char) luaL_checknumber(L, -4);
+		c.g = (unsigned char) luaL_checknumber(L, -3);
+		c.b = (unsigned char) luaL_checknumber(L, -2);
+		c.a = (unsigned char) luaL_optnumber(L, -1, 255);
 
 		lua_pop(L, 4);
 	}
 	else
 	{
-		c.r = (unsigned char)luaL_checkint(L, 1);
-		c.g = (unsigned char)luaL_checkint(L, 2);
-		c.b = (unsigned char)luaL_checkint(L, 3);
-		c.a = (unsigned char)luaL_optint(L, 4, 255);
+		c.r = (unsigned char) luaL_checknumber(L, 1);
+		c.g = (unsigned char) luaL_checknumber(L, 2);
+		c.b = (unsigned char) luaL_checknumber(L, 3);
+		c.a = (unsigned char) luaL_optnumber(L, 4, 255);
 	}
 	instance()->setBackgroundColor(c);
 	return 0;
@@ -1153,7 +1153,7 @@ int w_setCanvas(lua_State *L)
 
 	if (is_table)
 	{
-		for (int i = 1; i <= (int) lua_objlen(L, 1); i++)
+		for (int i = 1; i <= (int) luax_objlen(L, 1); i++)
 		{
 			lua_rawgeti(L, 1, i);
 			canvases.push_back(luax_checkcanvas(L, -1));
@@ -1490,7 +1490,7 @@ int w_line(lua_State *L)
 	bool is_table = false;
 	if (args == 1 && lua_istable(L, 1))
 	{
-		args = (int) lua_objlen(L, 1);
+		args = (int) luax_objlen(L, 1);
 		is_table = true;
 	}
 
@@ -1551,7 +1551,7 @@ int w_rectangle(lua_State *L)
 	if (lua_isnoneornil(L, 8))
 		points = std::max(rx, ry) > 20.0 ? (int)(std::max(rx, ry) / 2) : 10;
 	else
-		points = luaL_checkint(L, 8);
+		points = (int) luaL_checknumber(L, 8);
 
 	instance()->rectangle(mode, x, y, w, h, rx, ry, points);
 	return 0;
@@ -1571,7 +1571,7 @@ int w_circle(lua_State *L)
 	if (lua_isnoneornil(L, 5))
 		points = radius > 10 ? (int)(radius) : 10;
 	else
-		points = luaL_checkint(L, 5);
+		points = (int) luaL_checknumber(L, 5);
 
 	instance()->circle(mode, x, y, radius, points);
 	return 0;
@@ -1593,7 +1593,7 @@ int w_ellipse(lua_State *L)
 	if (lua_isnoneornil(L, 6))
 		points = a + b > 30 ? (int)((a + b) / 2) : 15;
 	else
-		points = luaL_checkint(L, 6);
+		points = (int) luaL_checknumber(L, 6);
 
 	instance()->ellipse(mode, x, y, a, b, points);
 	return 0;
@@ -1615,7 +1615,7 @@ int w_arc(lua_State *L)
 	if (lua_isnoneornil(L, 7))
 		points = radius > 10 ? (int)(radius) : 10;
 	else
-		points = luaL_checkint(L, 7);
+		points = (int) luaL_checknumber(L, 7);
 
 	instance()->arc(mode, x, y, radius, angle1, angle2, points);
 	return 0;
@@ -1634,7 +1634,7 @@ int w_polygon(lua_State *L)
 	float *coords;
 	if (args == 1 && lua_istable(L, 2))
 	{
-		args = (int) lua_objlen(L, 2);
+		args = (int) luax_objlen(L, 2);
 		is_table = true;
 	}
 

+ 4 - 4
src/modules/graphics/opengl/wrap_Image.cpp

@@ -80,10 +80,10 @@ int w_Image_refresh(lua_State *L)
 {
 	Image *i = luax_checkimage(L, 1);
 
-	int xoffset = luaL_optint(L, 2, 0);
-	int yoffset = luaL_optint(L, 3, 0);
-	int w = luaL_optint(L, 4, i->getWidth());
-	int h = luaL_optint(L, 5, i->getHeight());
+	int xoffset = (int) luaL_optnumber(L, 2, 0);
+	int yoffset = (int) luaL_optnumber(L, 3, 0);
+	int w = (int) luaL_optnumber(L, 4, i->getWidth());
+	int h = (int) luaL_optnumber(L, 5, i->getHeight());
 
 	luax_catchexcept(L, [&](){ i->refresh(xoffset, yoffset, w, h); });
 	return 0;

+ 4 - 4
src/modules/graphics/opengl/wrap_Mesh.cpp

@@ -90,7 +90,7 @@ int w_Mesh_setVertices(lua_State *L)
 	Mesh *t = luax_checkmesh(L, 1);
 	luaL_checktype(L, 2, LUA_TTABLE);
 
-	size_t nvertices = lua_objlen(L, 2);
+	size_t nvertices = luax_objlen(L, 2);
 	if (nvertices != t->getVertexCount())
 		return luaL_error(L, "Invalid number of vertices (expected %d, got %d)", (int) t->getVertexCount(), (int) nvertices);
 
@@ -312,7 +312,7 @@ int w_Mesh_setVertexMap(lua_State *L)
 	Mesh *t = luax_checkmesh(L, 1);
 
 	bool is_table = lua_istable(L, 2);
-	int nargs = is_table ? (int) lua_objlen(L, 2) : lua_gettop(L) - 1;
+	int nargs = is_table ? (int) luax_objlen(L, 2) : lua_gettop(L) - 1;
 
 	std::vector<uint32> vertexmap;
 	vertexmap.reserve(nargs);
@@ -424,8 +424,8 @@ int w_Mesh_setDrawRange(lua_State *L)
 		t->setDrawRange();
 	else
 	{
-		int rangemin = luaL_checkint(L, 2) - 1;
-		int rangemax = luaL_checkint(L, 3) - 1;
+		int rangemin = (int) luaL_checknumber(L, 2) - 1;
+		int rangemax = (int) luaL_checknumber(L, 3) - 1;
 		luax_catchexcept(L, [&](){ t->setDrawRange(rangemin, rangemax); });
 	}
 

+ 3 - 3
src/modules/graphics/opengl/wrap_ParticleSystem.cpp

@@ -505,7 +505,7 @@ int w_ParticleSystem_setColors(lua_State *L)
 		{
 			luaL_checktype(L, i + 2, LUA_TTABLE);
 
-			if (lua_objlen(L, i + 2) < 3)
+			if (luax_objlen(L, i + 2) < 3)
 				return luaL_argerror(L, i + 2, "expected 4 color components");
 
 			for (int j = 0; j < 4; j++)
@@ -592,7 +592,7 @@ int w_ParticleSystem_setQuads(lua_State *L)
 
 	if (lua_istable(L, 2))
 	{
-		for (int i = 1; i <= (int) lua_objlen(L, 2); i++)
+		for (int i = 1; i <= (int) luax_objlen(L, 2); i++)
 		{
 			lua_rawgeti(L, 2, i);
 
@@ -683,7 +683,7 @@ int w_ParticleSystem_reset(lua_State *L)
 int w_ParticleSystem_emit(lua_State *L)
 {
 	ParticleSystem *t = luax_checkparticlesystem(L, 1);
-	int num = luaL_checkint(L, 2);
+	int num = (int) luaL_checknumber(L, 2);
 	t->emit(num);
 	return 0;
 }

+ 6 - 6
src/modules/graphics/opengl/wrap_Shader.cpp

@@ -68,7 +68,7 @@ static T *_getScalars(lua_State *L, int count, size_t &dimension)
 template <typename T>
 static T *_getVectors(lua_State *L, int count, size_t &dimension)
 {
-	dimension = lua_objlen(L, 3);
+	dimension = luax_objlen(L, 3);
 	T *values = new T[count * dimension];
 
 	for (int i = 0; i < count; ++i)
@@ -79,11 +79,11 @@ static T *_getVectors(lua_State *L, int count, size_t &dimension)
 			luax_typerror(L, 3 + i, "table");
 			return 0;
 		}
-		if (lua_objlen(L, 3 + i) != dimension)
+		if (luax_objlen(L, 3 + i) != dimension)
 		{
 			delete[] values;
 			luaL_error(L, "Error in argument %d: Expected table size %d, got %d.",
-						   3+i, dimension, lua_objlen(L, 3+i));
+						   3+i, dimension, luax_objlen(L, 3+i));
 			return 0;
 		}
 
@@ -258,19 +258,19 @@ static void w_convertMatrices(lua_State *L, int idx)
 	for (int matrix = idx; matrix < idx + matrixcount; matrix++)
 	{
 		luaL_checktype(L, matrix, LUA_TTABLE);
-		int dimension = (int) lua_objlen(L, matrix);
+		int dimension = (int) luax_objlen(L, matrix);
 
 		int newi = 1;
 		lua_createtable(L, dimension * dimension, 0);
 
 		// Collapse {{a,b,c}, {d,e,f}, ...} to {a,b,c, d,e,f, ...}
-		for (int i = 1; i <= (int) lua_objlen(L, matrix); i++)
+		for (int i = 1; i <= (int) luax_objlen(L, matrix); i++)
 		{
 			// Push args[matrix][i] onto the stack.
 			lua_rawgeti(L, matrix, i);
 			luaL_checktype(L, -1, LUA_TTABLE);
 
-			for (int j = 1; j <= (int) lua_objlen(L, -1); j++)
+			for (int j = 1; j <= (int) luax_objlen(L, -1); j++)
 			{
 				// Push args[matrix[i][j] onto the stack.
 				lua_rawgeti(L, -1, j);

+ 2 - 2
src/modules/graphics/opengl/wrap_SpriteBatch.cpp

@@ -78,7 +78,7 @@ int w_SpriteBatch_add(lua_State *L)
 int w_SpriteBatch_set(lua_State *L)
 {
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
-	int id = luaL_checkint(L, 2);
+	int id = (int) luaL_checknumber(L, 2);
 
 	Quad *quad = nullptr;
 	int startidx = 3;
@@ -211,7 +211,7 @@ int w_SpriteBatch_getCount(lua_State *L)
 int w_SpriteBatch_setBufferSize(lua_State *L)
 {
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
-	int size = luaL_checkint(L, 2);
+	int size = (int) luaL_checknumber(L, 2);
 	luax_catchexcept(L, [&]() {t->setBufferSize(size); });
 	return 0;
 }

+ 3 - 3
src/modules/image/wrap_CompressedImageData.cpp

@@ -34,7 +34,7 @@ CompressedImageData *luax_checkcompressedimagedata(lua_State *L, int idx)
 int w_CompressedImageData_getWidth(lua_State *L)
 {
 	CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
-	int miplevel = luaL_optint(L, 2, 1);
+	int miplevel = (int) luaL_optnumber(L, 2, 1);
 	int width = 0;
 
 	luax_catchexcept(L, [&](){ width = t->getWidth(miplevel - 1); });
@@ -46,7 +46,7 @@ int w_CompressedImageData_getWidth(lua_State *L)
 int w_CompressedImageData_getHeight(lua_State *L)
 {
 	CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
-	int miplevel = luaL_optint(L, 2, 1);
+	int miplevel = (int) luaL_optnumber(L, 2, 1);
 	int height = 0;
 
 	luax_catchexcept(L, [&](){ height = t->getHeight(miplevel - 1); });
@@ -58,7 +58,7 @@ int w_CompressedImageData_getHeight(lua_State *L)
 int w_CompressedImageData_getDimensions(lua_State *L)
 {
 	CompressedImageData *t = luax_checkcompressedimagedata(L, 1);
-	int miplevel = luaL_optint(L, 2, 1);
+	int miplevel = (int) luaL_optnumber(L, 2, 1);
 	int width = 0, height = 0;
 
 	luax_catchexcept(L, [&]()

+ 2 - 2
src/modules/image/wrap_Image.cpp

@@ -39,8 +39,8 @@ int w_newImageData(lua_State *L)
 	// Case 1: Integers.
 	if (lua_isnumber(L, 1))
 	{
-		int w = luaL_checkint(L, 1);
-		int h = luaL_checkint(L, 2);
+		int w = (int) luaL_checknumber(L, 1);
+		int h = (int) luaL_checknumber(L, 2);
 		if (w <= 0 || h <= 0)
 			return luaL_error(L, "Invalid image size.");
 

+ 10 - 10
src/modules/image/wrap_ImageData.cpp

@@ -68,8 +68,8 @@ int w_ImageData_getDimensions(lua_State *L)
 int w_ImageData_getPixel(lua_State *L)
 {
 	ImageData *t = luax_checkimagedata(L, 1);
-	int x = luaL_checkint(L, 2);
-	int y = luaL_checkint(L, 3);
+	int x = (int) luaL_checknumber(L, 2);
+	int y = (int) luaL_checknumber(L, 3);
 	pixel c;
 
 	luax_catchexcept(L, [&](){ c = t->getPixel(x, y); });
@@ -84,8 +84,8 @@ int w_ImageData_getPixel(lua_State *L)
 int w_ImageData_setPixel(lua_State *L)
 {
 	ImageData *t = luax_checkimagedata(L, 1);
-	int x = luaL_checkint(L, 2);
-	int y = luaL_checkint(L, 3);
+	int x = (int) luaL_checknumber(L, 2);
+	int y = (int) luaL_checknumber(L, 3);
 	pixel c;
 
 	if (lua_istable(L, 4))
@@ -205,12 +205,12 @@ int w_ImageData_paste(lua_State *L)
 {
 	ImageData *t = luax_checkimagedata(L, 1);
 	ImageData *src = luax_checkimagedata(L, 2);
-	int dx = luaL_checkint(L, 3);
-	int dy = luaL_checkint(L, 4);
-	int sx = luaL_optint(L, 5, 0);
-	int sy = luaL_optint(L, 6, 0);
-	int sw = luaL_optint(L, 7, src->getWidth());
-	int sh = luaL_optint(L, 8, src->getHeight());
+	int dx = (int) luaL_checknumber(L, 3);
+	int dy = (int) luaL_checknumber(L, 4);
+	int sx = (int) luaL_optnumber(L, 5, 0);
+	int sy = (int) luaL_optnumber(L, 6, 0);
+	int sw = (int) luaL_optnumber(L, 7, src->getWidth());
+	int sh = (int) luaL_optnumber(L, 8, src->getHeight());
 	t->paste((love::image::ImageData *)src, dx, dy, sx, sy, sw, sh);
 	return 0;
 }

+ 3 - 3
src/modules/joystick/wrap_Joystick.cpp

@@ -95,7 +95,7 @@ int w_Joystick_getHatCount(lua_State *L)
 int w_Joystick_getAxis(lua_State *L)
 {
 	Joystick *j = luax_checkjoystick(L, 1);
-	int axisindex = luaL_checkint(L, 2) - 1;
+	int axisindex = (int) luaL_checknumber(L, 2) - 1;
 	lua_pushnumber(L, j->getAxis(axisindex));
 	return 1;
 }
@@ -114,7 +114,7 @@ int w_Joystick_getAxes(lua_State *L)
 int w_Joystick_getHat(lua_State *L)
 {
 	Joystick *j = luax_checkjoystick(L, 1);
-	int hatindex = luaL_checkint(L, 2) - 1;
+	int hatindex = (int) luaL_checknumber(L, 2) - 1;
 
 	Joystick::Hat h = j->getHat(hatindex);
 
@@ -133,7 +133,7 @@ int w_Joystick_isDown(lua_State *L)
 
 	std::vector<int> buttons;
 	for (int i = 2; i <= lua_gettop(L); i++)
-		buttons.push_back(luaL_checkint(L, i) - 1);
+		buttons.push_back((int) luaL_checknumber(L, i) - 1);
 
 	luax_pushboolean(L, j->isDown(buttons));
 	return 1;

+ 3 - 3
src/modules/joystick/wrap_JoystickModule.cpp

@@ -91,14 +91,14 @@ int w_setGamepadMapping(lua_State *L)
 	switch (jinput.type)
 	{
 	case Joystick::INPUT_TYPE_AXIS:
-		jinput.axis = luaL_checkint(L, 4) - 1;
+		jinput.axis = (int) luaL_checknumber(L, 4) - 1;
 		break;
 	case Joystick::INPUT_TYPE_BUTTON:
-		jinput.button = luaL_checkint(L, 4) - 1;
+		jinput.button = (int) luaL_checknumber(L, 4) - 1;
 		break;
 	case Joystick::INPUT_TYPE_HAT:
 		// Hats need both a hat index and a hat value.
-		jinput.hat.index = luaL_checkint(L, 4) - 1;
+		jinput.hat.index = (int) luaL_checknumber(L, 4) - 1;
 		hatstr = luaL_checkstring(L, 5);
 		if (!Joystick::getConstant(hatstr, jinput.hat.value))
 			return luaL_error(L, "Invalid joystick hat: %s", hatstr);

+ 3 - 3
src/modules/love/love.cpp

@@ -213,9 +213,9 @@ static int w_love_isVersionCompatible(lua_State *L)
 		version = luaL_checkstring(L, 1);
 	else
 	{
-		int major = luaL_checkint(L, 1);
-		int minor = luaL_checkint(L, 2);
-		int rev   = luaL_checkint(L, 3);
+		int major = (int) luaL_checknumber(L, 1);
+		int minor = (int) luaL_checknumber(L, 2);
+		int rev   = (int) luaL_checknumber(L, 3);
 
 		// Convert the numbers to a string, since VERSION_COMPATIBILITY is an
 		// array of version strings.

+ 5 - 5
src/modules/math/wrap_BezierCurve.cpp

@@ -52,7 +52,7 @@ int w_BezierCurve_getDerivative(lua_State *L)
 int w_BezierCurve_getControlPoint(lua_State *L)
 {
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
-	int idx = luaL_checkint(L, 2);
+	int idx = (int) luaL_checknumber(L, 2);
 
 	if (idx > 0) // 1-indexing
 		idx--;
@@ -69,7 +69,7 @@ int w_BezierCurve_getControlPoint(lua_State *L)
 int w_BezierCurve_setControlPoint(lua_State *L)
 {
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
-	int idx = luaL_checkint(L, 2);
+	int idx = (int) luaL_checknumber(L, 2);
 	float vx = (float) luaL_checknumber(L, 3);
 	float vy = (float) luaL_checknumber(L, 4);
 
@@ -85,7 +85,7 @@ int w_BezierCurve_insertControlPoint(lua_State *L)
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
 	float vx = (float) luaL_checknumber(L, 2);
 	float vy = (float) luaL_checknumber(L, 3);
-	int idx = luaL_optint(L, 4, -1);
+	int idx = (int) luaL_optnumber(L, 4, -1);
 
 	if (idx > 0) // 1-indexing
 		idx--;
@@ -97,7 +97,7 @@ int w_BezierCurve_insertControlPoint(lua_State *L)
 int w_BezierCurve_removeControlPoint(lua_State *L)
 {
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
-	int idx = luaL_checkint(L, 2);
+	int idx = (int) luaL_checknumber(L, 2);
 
 	if (idx > 0) // 1-indexing
 		idx--;
@@ -174,7 +174,7 @@ int w_BezierCurve_getSegment(lua_State *L)
 int w_BezierCurve_render(lua_State *L)
 {
 	BezierCurve *curve = luax_checkbeziercurve(L, 1);
-	int accuracy = luaL_optint(L, 2, 5);
+	int accuracy = (int) luaL_optnumber(L, 2, 5);
 
 	std::vector<Vector> points;
 	luax_catchexcept(L, [&](){ points = curve->render(accuracy); });

+ 5 - 5
src/modules/math/wrap_Math.cpp

@@ -111,7 +111,7 @@ int w_newBezierCurve(lua_State *L)
 	std::vector<Vector> points;
 	if (lua_istable(L, 1))
 	{
-		int top = (int) lua_objlen(L, 1);
+		int top = (int) luax_objlen(L, 1);
 		points.reserve(top / 2);
 		for (int i = 1; i <= top; i += 2)
 		{
@@ -150,7 +150,7 @@ int w_triangulate(lua_State *L)
 	std::vector<Vertex> vertices;
 	if (lua_istable(L, 1))
 	{
-		int top = (int) lua_objlen(L, 1);
+		int top = (int) luax_objlen(L, 1);
 		vertices.reserve(top / 2);
 		for (int i = 1; i <= top; i += 2)
 		{
@@ -220,7 +220,7 @@ int w_isConvex(lua_State *L)
 	std::vector<Vertex> vertices;
 	if (lua_istable(L, 1))
 	{
-		int top = (int) lua_objlen(L, 1);
+		int top = (int) luax_objlen(L, 1);
 		vertices.reserve(top / 2);
 		for (int i = 1; i <= top; i += 2)
 		{
@@ -258,7 +258,7 @@ static int getGammaArgs(lua_State *L, float color[4])
 
 	if (lua_istable(L, 1))
 	{
-		int n = (int) lua_objlen(L, 1);
+		int n = (int) luax_objlen(L, 1);
 		for (int i = 1; i <= n && i <= 4; i++)
 		{
 			lua_rawgeti(L, 1, i);
@@ -360,7 +360,7 @@ int w_compress(lua_State *L)
 	if (fstr && !Compressor::getConstant(fstr, format))
 		return luaL_error(L, "Invalid compressed format: %s", fstr);
 
-	int level = luaL_optint(L, 3, -1);
+	int level = (int) luaL_optnumber(L, 3, -1);
 
 	CompressedData *cdata = nullptr;
 	if (lua_isstring(L, 1))

+ 3 - 3
src/modules/math/wrap_RandomGenerator.cpp

@@ -66,13 +66,13 @@ int luax_getrandom(lua_State *L, int startidx, double r)
 		lua_pushnumber(L, r);
 		break;
 	case 1:
-		u = luaL_checkint(L, startidx);
+		u = (int) luaL_checknumber(L, startidx);
 		luaL_argcheck(L, 1 <= u, startidx, "interval is empty");
 		lua_pushnumber(L, floor(r * u) + 1);
 		break;
 	case 2:
-		l = luaL_checkint(L, startidx);
-		u = luaL_checkint(L, startidx + 1);
+		l = (int) luaL_checknumber(L, startidx);
+		u = (int) luaL_checknumber(L, startidx + 1);
 		luaL_argcheck(L, l <= u, startidx + 1, "interval is empty");
 		lua_pushnumber(L, floor(r * (u - l + 1)) + l);
 		break;

+ 3 - 3
src/modules/mouse/wrap_Mouse.cpp

@@ -40,8 +40,8 @@ int w_newCursor(lua_State *L)
 		luax_convobj(L, 1, "image", "newImageData");
 
 	love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
-	int hotx = luaL_optint(L, 2, 0);
-	int hoty = luaL_optint(L, 3, 0);
+	int hotx = (int) luaL_optnumber(L, 2, 0);
+	int hoty = (int) luaL_optnumber(L, 3, 0);
 
 	luax_catchexcept(L, [&](){ cursor = instance()->newCursor(data, hotx, hoty); });
 
@@ -147,7 +147,7 @@ int w_isDown(lua_State *L)
 	buttons.reserve(num);
 
 	for (int i = 0; i < num; i++)
-		buttons.push_back(luaL_checkint(L, i + 1));
+		buttons.push_back((int) luaL_checknumber(L, i + 1));
 
 	luax_pushboolean(L, instance()->isDown(buttons));
 	return 1;

+ 2 - 2
src/modules/physics/box2d/Fixture.cpp

@@ -263,7 +263,7 @@ int Fixture::rayCast(lua_State *L) const
 	float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
 	float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
 	float maxFraction = (float)luaL_checknumber(L, 5);
-	int childIndex = (int)luaL_optint(L, 6, 1) - 1; // Convert from 1-based index
+	int childIndex = (int) luaL_optnumber(L, 6, 1) - 1; // Convert from 1-based index
 	b2RayCastInput input;
 	input.p1.Set(p1x, p1y);
 	input.p2.Set(p2x, p2y);
@@ -279,7 +279,7 @@ int Fixture::rayCast(lua_State *L) const
 
 int Fixture::getBoundingBox(lua_State *L) const
 {
-	int childIndex = (int)luaL_optint(L, 1, 1) - 1; // Convert from 1-based index
+	int childIndex = (int) luaL_optnumber(L, 1, 1) - 1; // Convert from 1-based index
 	b2AABB box = fixture->GetAABB(childIndex);
 	box = Physics::scaleUp(box);
 	lua_pushnumber(L, box.lowerBound.x);

+ 2 - 2
src/modules/physics/box2d/Physics.cpp

@@ -97,7 +97,7 @@ int Physics::newPolygonShape(lua_State *L)
 	bool istable = lua_istable(L, 1);
 
 	if (istable)
-		argc = (int) lua_objlen(L, 1);
+		argc = (int) luax_objlen(L, 1);
 
 	if (argc % 2 != 0)
 		return luaL_error(L, "Number of vertex components must be a multiple of two.");
@@ -158,7 +158,7 @@ int Physics::newChainShape(lua_State *L)
 	bool istable = lua_istable(L, 2);
 
 	if (istable)
-		argc = (int) lua_objlen(L, 2);
+		argc = (int) luax_objlen(L, 2);
 
 	if (argc % 2 != 0)
 		return luaL_error(L, "Number of vertex components must be a multiple of two.");

+ 2 - 2
src/modules/physics/box2d/Shape.cpp

@@ -105,7 +105,7 @@ int Shape::rayCast(lua_State *L) const
 	float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
 	float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
 	float r = (float)luaL_checknumber(L, 8);
-	int childIndex = (int)luaL_optint(L, 9, 1) - 1; // Convert from 1-based index
+	int childIndex = (int) luaL_optnumber(L, 9, 1) - 1; // Convert from 1-based index
 	b2RayCastInput input;
 	input.p1.Set(p1x, p1y);
 	input.p2.Set(p2x, p2y);
@@ -125,7 +125,7 @@ int Shape::computeAABB(lua_State *L) const
 	float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
 	float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
 	float r = (float)luaL_checknumber(L, 3);
-	int childIndex = (int)luaL_optint(L, 4, 1) - 1; // Convert from 1-based index
+	int childIndex = (int) luaL_optnumber(L, 4, 1) - 1; // Convert from 1-based index
 	b2Transform transform(b2Vec2(x, y), b2Rot(r));
 	b2AABB box;
 	shape->ComputeAABB(&box, transform, childIndex);

+ 2 - 2
src/modules/physics/box2d/wrap_ChainShape.cpp

@@ -55,7 +55,7 @@ int w_ChainShape_setPreviousVertex(lua_State *L)
 int w_ChainShape_getChildEdge(lua_State *L)
 {
 	ChainShape *c = luax_checkchainshape(L, 1);
-	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
+	int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
 	EdgeShape *e = 0;
 	luax_catchexcept(L, [&](){ e = c->getChildEdge(index); });
 	luax_pushtype(L, PHYSICS_EDGE_SHAPE_ID, e);
@@ -74,7 +74,7 @@ int w_ChainShape_getVertexCount(lua_State *L)
 int w_ChainShape_getPoint(lua_State *L)
 {
 	ChainShape *c = luax_checkchainshape(L, 1);
-	int index = luaL_checkint(L, 2) - 1; // Convert from 1-based index
+	int index = (int) luaL_checknumber(L, 2) - 1; // Convert from 1-based index
 	b2Vec2 v;
 	luax_catchexcept(L, [&](){ v = c->getPoint(index); });
 	lua_pushnumber(L, v.x);

+ 4 - 4
src/modules/physics/box2d/wrap_Fixture.cpp

@@ -165,9 +165,9 @@ int w_Fixture_setFilterData(lua_State *L)
 {
 	Fixture *t = luax_checkfixture(L, 1);
 	int v[3];
-	v[0] = luaL_checkint(L, 2);
-	v[1] = luaL_checkint(L, 3);
-	v[2] = luaL_checkint(L, 4);
+	v[0] = (int) luaL_checknumber(L, 2);
+	v[1] = (int) luaL_checknumber(L, 3);
+	v[2] = (int) luaL_checknumber(L, 4);
 	t->setFilterData(v);
 	return 0;
 }
@@ -250,7 +250,7 @@ int w_Fixture_getGroupIndex(lua_State *L)
 int w_Fixture_setGroupIndex(lua_State *L)
 {
 	Fixture *t = luax_checkfixture(L, 1);
-	int i = luaL_checkint(L, 2);
+	int i = (int) luaL_checknumber(L, 2);
 	t->setGroupIndex(i);
 	return 0;
 }

+ 1 - 1
src/modules/physics/box2d/wrap_Physics.cpp

@@ -439,7 +439,7 @@ int w_getDistance(lua_State *L)
 
 int w_setMeter(lua_State *L)
 {
-	int arg1 = luaL_checkint(L, 1);
+	int arg1 = (int) luaL_checknumber(L, 1);
 	luax_catchexcept(L, [&](){ Physics::setMeter(arg1); });
 	return 0;
 

+ 5 - 5
src/modules/sound/wrap_Sound.cpp

@@ -38,10 +38,10 @@ int w_newSoundData(lua_State *L)
 
 	if (lua_isnumber(L, 1))
 	{
-		int samples = luaL_checkint(L, 1);
-		int sampleRate = luaL_optint(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
-		int bitDepth = luaL_optint(L, 3, Decoder::DEFAULT_BIT_DEPTH);
-		int channels = luaL_optint(L, 4, Decoder::DEFAULT_CHANNELS);
+		int samples = (int) luaL_checknumber(L, 1);
+		int sampleRate = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_SAMPLE_RATE);
+		int bitDepth = (int) luaL_optnumber(L, 3, Decoder::DEFAULT_BIT_DEPTH);
+		int channels = (int) luaL_optnumber(L, 4, Decoder::DEFAULT_CHANNELS);
 
 		luax_catchexcept(L, [&](){ t = instance()->newSoundData(samples, sampleRate, bitDepth, channels); });
 	}
@@ -66,7 +66,7 @@ int w_newSoundData(lua_State *L)
 int w_newDecoder(lua_State *L)
 {
 	love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);
-	int bufferSize = luaL_optint(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
+	int bufferSize = (int) luaL_optnumber(L, 2, Decoder::DEFAULT_BUFFER_SIZE);
 
 	Decoder *t = nullptr;
 	luax_catchexcept(L,

+ 13 - 13
src/modules/window/wrap_Window.cpp

@@ -36,7 +36,7 @@ int w_getDisplayCount(lua_State *L)
 
 int w_getDisplayName(lua_State *L)
 {
-	int index = luaL_checkint(L, 1) - 1;
+	int index = (int) luaL_checknumber(L, 1) - 1;
 
 	const char *name = nullptr;
 	luax_catchexcept(L, [&](){ name = instance()->getDisplayName(index); });
@@ -54,8 +54,8 @@ static const char *settingName(Window::Setting setting)
 
 int w_setMode(lua_State *L)
 {
-	int w = luaL_checkint(L, 1);
-	int h = luaL_checkint(L, 2);
+	int w = (int) luaL_checknumber(L, 1);
+	int h = (int) luaL_checknumber(L, 2);
 
 	if (lua_isnoneornil(L, 3))
 	{
@@ -114,8 +114,8 @@ int w_setMode(lua_State *L)
 	settings.useposition = !(lua_isnoneornil(L, -2) && lua_isnoneornil(L, -1));
 	if (settings.useposition)
 	{
-		settings.x = luaL_optint(L, -2, 0);
-		settings.y = luaL_optint(L, -1, 0);
+		settings.x = (int) luaL_optnumber(L, -2, 0);
+		settings.y = (int) luaL_optnumber(L, -1, 0);
 	}
 	lua_pop(L, 2);
 
@@ -194,7 +194,7 @@ int w_getFullscreenModes(lua_State *L)
 {
 	int displayindex = 0;
 	if (!lua_isnoneornil(L, 1))
-		displayindex = luaL_checkint(L, 1);
+		displayindex = (int) luaL_checknumber(L, 1);
 	else
 	{
 		int x, y;
@@ -271,7 +271,7 @@ int w_getDesktopDimensions(lua_State *L)
 	int width = 0, height = 0;
 	int displayindex = 0;
 	if (!lua_isnoneornil(L, 1))
-		displayindex = luaL_checkint(L, 1);
+		displayindex = (int) luaL_checknumber(L, 1);
 	else
 	{
 		int x, y;
@@ -285,12 +285,12 @@ int w_getDesktopDimensions(lua_State *L)
 
 int w_setPosition(lua_State *L)
 {
-	int x = luaL_checkint(L, 1);
-	int y = luaL_checkint(L, 2);
+	int x = (int) luaL_checknumber(L, 1);
+	int y = (int) luaL_checknumber(L, 2);
 
 	int displayindex = 0;
 	if (!lua_isnoneornil(L, 3))
-		displayindex = luaL_checkint(L, 3);
+		displayindex = (int) luaL_checknumber(L, 3);
 	else
 	{
 		int x_unused, y_unused;
@@ -430,7 +430,7 @@ int w_showMessageBox(lua_State *L)
 	// means we should use the more complex message box API.
 	if (lua_istable(L, 3))
 	{
-		size_t numbuttons = lua_objlen(L, 3);
+		size_t numbuttons = luax_objlen(L, 3);
 		if (numbuttons == 0)
 			return luaL_error(L, "Must have at least one messagebox button.");
 
@@ -445,7 +445,7 @@ int w_showMessageBox(lua_State *L)
 		// Optional table entry specifying the button to use when enter is pressed.
 		lua_getfield(L, 3, "enterbutton");
 		if (!lua_isnoneornil(L, -1))
-			data.enterButtonIndex = luaL_checkint(L, -1) - 1;
+			data.enterButtonIndex = (int) luaL_checknumber(L, -1) - 1;
 		else
 			data.enterButtonIndex = 0;
 		lua_pop(L, 1);
@@ -453,7 +453,7 @@ int w_showMessageBox(lua_State *L)
 		// Optional table entry specifying the button to use when esc is pressed.
 		lua_getfield(L, 3, "escapebutton");
 		if (!lua_isnoneornil(L, -1))
-			data.escapeButtonIndex = luaL_checkint(L, -1) - 1;
+			data.escapeButtonIndex = (int) luaL_checknumber(L, -1) - 1;
 		else
 			data.escapeButtonIndex = (int) data.buttons.size() - 1;
 		lua_pop(L, 1);