Changeset

12575:1f6f05a98fcd

util-src: Remove Lua 5.1 compat macros Part of #1600
author Kim Alvefur <zash@zash.se>
date Fri, 01 Jul 2022 21:21:21 +0200
parents 12574:18d33668c5fa
children 12576:d1aacc6a81ac
files util-src/crand.c util-src/encodings.c util-src/hashes.c util-src/net.c util-src/poll.c util-src/pposix.c util-src/ringbuffer.c util-src/signal.c util-src/strbitop.c util-src/struct.c util-src/table.c util-src/windows.c
diffstat 12 files changed, 2 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/util-src/crand.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/crand.c	Fri Jul 01 21:21:21 2022 +0200
@@ -124,9 +124,7 @@
 }
 
 int luaopen_util_crand(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 
 	lua_createtable(L, 0, 2);
 	lua_pushcfunction(L, Lrandom);
--- a/util-src/encodings.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/encodings.c	Fri Jul 01 21:21:21 2022 +0200
@@ -21,9 +21,6 @@
 #include "lua.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 #if (LUA_VERSION_NUM < 504)
 #define luaL_pushfail lua_pushnil
 #endif
@@ -616,9 +613,7 @@
 /***************** end *****************/
 
 LUALIB_API int luaopen_util_encodings(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 #ifdef USE_STRINGPREP_ICU
 	init_icu();
 #endif
--- a/util-src/hashes.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/hashes.c	Fri Jul 01 21:21:21 2022 +0200
@@ -30,9 +30,6 @@
 #include <openssl/evp.h>
 #include <openssl/err.h>
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 
 static const char *hex_tab = "0123456789abcdef";
 static void toHex(const unsigned char *in, int length, unsigned char *out) {
@@ -258,9 +255,7 @@
 };
 
 LUALIB_API int luaopen_util_hashes(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 	lua_newtable(L);
 	luaL_setfuncs(L, Reg, 0);
 	lua_pushliteral(L, "-3.14");
--- a/util-src/net.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/net.c	Fri Jul 01 21:21:21 2022 +0200
@@ -30,9 +30,6 @@
 #include <lua.h>
 #include <lauxlib.h>
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 #if (LUA_VERSION_NUM < 504)
 #define luaL_pushfail lua_pushnil
 #endif
@@ -193,9 +190,7 @@
 }
 
 int luaopen_util_net(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 	luaL_Reg exports[] = {
 		{ "local_addresses", lc_local_addresses },
 		{ "pton", lc_pton },
--- a/util-src/poll.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/poll.c	Fri Jul 01 21:21:21 2022 +0200
@@ -44,9 +44,6 @@
 
 #define STATE_MT "util.poll<" POLL_BACKEND ">"
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setmetatable(L, tname) luaL_getmetatable(L, tname); lua_setmetatable(L, -2)
-#endif
 #if (LUA_VERSION_NUM < 504)
 #define luaL_pushfail lua_pushnil
 #endif
@@ -564,9 +561,7 @@
  * Open library
  */
 int luaopen_util_poll(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 
 	luaL_newmetatable(L, STATE_MT);
 	{
--- a/util-src/pposix.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/pposix.c	Fri Jul 01 21:21:21 2022 +0200
@@ -58,9 +58,6 @@
 #include "lualib.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 #if (LUA_VERSION_NUM < 503)
 #define lua_isinteger(L, n) lua_isnumber(L, n)
 #endif
@@ -829,9 +826,7 @@
 /* Register functions */
 
 int luaopen_util_pposix(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 	luaL_Reg exports[] = {
 		{ "abort", lc_abort },
 
--- a/util-src/ringbuffer.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/ringbuffer.c	Fri Jul 01 21:21:21 2022 +0200
@@ -314,9 +314,7 @@
 }
 
 int luaopen_util_ringbuffer(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 
 	if(luaL_newmetatable(L, "ringbuffer_mt")) {
 		lua_pushcfunction(L, rb_tostring);
--- a/util-src/signal.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/signal.c	Fri Jul 01 21:21:21 2022 +0200
@@ -36,9 +36,6 @@
 #include "lua.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 #if (LUA_VERSION_NUM < 503)
 #define lua_isinteger(L, n) lua_isnumber(L, n)
 #endif
@@ -381,9 +378,7 @@
 };
 
 int luaopen_util_signal(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 	int i = 0;
 
 	/* add the library */
--- a/util-src/strbitop.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/strbitop.c	Fri Jul 01 21:21:21 2022 +0200
@@ -8,9 +8,6 @@
 #include <lua.h>
 #include <lauxlib.h>
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 
 /* TODO Deduplicate code somehow */
 
--- a/util-src/struct.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/struct.c	Fri Jul 01 21:21:21 2022 +0200
@@ -36,12 +36,6 @@
 #include "lauxlib.h"
 
 
-#if (LUA_VERSION_NUM >= 502)
-
-#define luaL_register(L,n,f)	luaL_newlib(L,f)
-
-#endif
-
 
 /* basic integer type */
 #if !defined(STRUCT_INT)
@@ -392,7 +386,7 @@
 LUALIB_API int luaopen_util_struct (lua_State *L);
 
 LUALIB_API int luaopen_util_struct (lua_State *L) {
-  luaL_register(L, "struct", thislib);
+  luaL_newlib(L, thislib);
   return 1;
 }
 
--- a/util-src/table.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/table.c	Fri Jul 01 21:21:21 2022 +0200
@@ -6,10 +6,6 @@
 #define LUA_MAXINTEGER PTRDIFF_MAX
 #endif
 
-#if (LUA_VERSION_NUM > 501)
-#define lua_equal(L, A, B) lua_compare(L, A, B, LUA_OPEQ)
-#endif
-
 static int Lcreate_table(lua_State *L) {
 	lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2));
 	return 1;
@@ -47,7 +43,7 @@
 		n = e - f + 1;  /* number of elements to move */
 		luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4,
 		"destination wrap around");
-		if (t > e || t <= f || (tt != 1 && !lua_equal(L, 1, tt))) {
+		if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) {
 			for (i = 0; i < n; i++) {
 				lua_rawgeti(L, 1, f + i);
 				lua_rawseti(L, tt, t + i);
@@ -65,9 +61,7 @@
 }
 
 int luaopen_util_table(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 	lua_createtable(L, 0, 2);
 	lua_pushcfunction(L, Lcreate_table);
 	lua_setfield(L, -2, "create");
--- a/util-src/windows.c	Sat Jul 02 17:30:06 2022 +0200
+++ b/util-src/windows.c	Fri Jul 01 21:21:21 2022 +0200
@@ -19,9 +19,6 @@
 #include "lua.h"
 #include "lauxlib.h"
 
-#if (LUA_VERSION_NUM == 501)
-#define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R)
-#endif
 #if (LUA_VERSION_NUM < 504)
 #define luaL_pushfail lua_pushnil
 #endif
@@ -106,9 +103,7 @@
 };
 
 LUALIB_API int luaopen_util_windows(lua_State *L) {
-#if (LUA_VERSION_NUM > 501)
 	luaL_checkversion(L);
-#endif
 	lua_newtable(L);
 	luaL_setfuncs(L, Reg, 0);
 	lua_pushliteral(L, "-3.14");