Mercurial > prosody-hg
comparison util-src/table.c @ 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 | 308ed64dc69b |
| children | 494577d883ff |
comparison
equal
deleted
inserted
replaced
| 12574:18d33668c5fa | 12575:1f6f05a98fcd |
|---|---|
| 2 #include <lauxlib.h> | 2 #include <lauxlib.h> |
| 3 | 3 |
| 4 #ifndef LUA_MAXINTEGER | 4 #ifndef LUA_MAXINTEGER |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 #define LUA_MAXINTEGER PTRDIFF_MAX | 6 #define LUA_MAXINTEGER PTRDIFF_MAX |
| 7 #endif | |
| 8 | |
| 9 #if (LUA_VERSION_NUM > 501) | |
| 10 #define lua_equal(L, A, B) lua_compare(L, A, B, LUA_OPEQ) | |
| 11 #endif | 7 #endif |
| 12 | 8 |
| 13 static int Lcreate_table(lua_State *L) { | 9 static int Lcreate_table(lua_State *L) { |
| 14 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); | 10 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); |
| 15 return 1; | 11 return 1; |
| 45 luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, | 41 luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, |
| 46 "too many elements to move"); | 42 "too many elements to move"); |
| 47 n = e - f + 1; /* number of elements to move */ | 43 n = e - f + 1; /* number of elements to move */ |
| 48 luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, | 44 luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, |
| 49 "destination wrap around"); | 45 "destination wrap around"); |
| 50 if (t > e || t <= f || (tt != 1 && !lua_equal(L, 1, tt))) { | 46 if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) { |
| 51 for (i = 0; i < n; i++) { | 47 for (i = 0; i < n; i++) { |
| 52 lua_rawgeti(L, 1, f + i); | 48 lua_rawgeti(L, 1, f + i); |
| 53 lua_rawseti(L, tt, t + i); | 49 lua_rawseti(L, tt, t + i); |
| 54 } | 50 } |
| 55 } else { | 51 } else { |
| 63 lua_pushvalue(L, tt); /* return destination table */ | 59 lua_pushvalue(L, tt); /* return destination table */ |
| 64 return 1; | 60 return 1; |
| 65 } | 61 } |
| 66 | 62 |
| 67 int luaopen_util_table(lua_State *L) { | 63 int luaopen_util_table(lua_State *L) { |
| 68 #if (LUA_VERSION_NUM > 501) | |
| 69 luaL_checkversion(L); | 64 luaL_checkversion(L); |
| 70 #endif | |
| 71 lua_createtable(L, 0, 2); | 65 lua_createtable(L, 0, 2); |
| 72 lua_pushcfunction(L, Lcreate_table); | 66 lua_pushcfunction(L, Lcreate_table); |
| 73 lua_setfield(L, -2, "create"); | 67 lua_setfield(L, -2, "create"); |
| 74 lua_pushcfunction(L, Lpack); | 68 lua_pushcfunction(L, Lpack); |
| 75 lua_setfield(L, -2, "pack"); | 69 lua_setfield(L, -2, "pack"); |
