Software /
code /
prosody
Comparison
util-src/table.c @ 12405:308ed64dc69b
util.table: Compatibility with Lua 5.1 lua_equals
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 18 Mar 2022 15:29:05 +0000 |
parent | 12402:8deb401a21f6 |
child | 12575:1f6f05a98fcd |
comparison
equal
deleted
inserted
replaced
12404:082f38e9de64 | 12405:308ed64dc69b |
---|---|
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) | |
7 #endif | 11 #endif |
8 | 12 |
9 static int Lcreate_table(lua_State *L) { | 13 static int Lcreate_table(lua_State *L) { |
10 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); | 14 lua_createtable(L, luaL_checkinteger(L, 1), luaL_checkinteger(L, 2)); |
11 return 1; | 15 return 1; |
41 luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, | 45 luaL_argcheck(L, f > 0 || e < LUA_MAXINTEGER + f, 3, |
42 "too many elements to move"); | 46 "too many elements to move"); |
43 n = e - f + 1; /* number of elements to move */ | 47 n = e - f + 1; /* number of elements to move */ |
44 luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, | 48 luaL_argcheck(L, t <= LUA_MAXINTEGER - n + 1, 4, |
45 "destination wrap around"); | 49 "destination wrap around"); |
46 if (t > e || t <= f || (tt != 1 && !lua_compare(L, 1, tt, LUA_OPEQ))) { | 50 if (t > e || t <= f || (tt != 1 && !lua_equal(L, 1, tt))) { |
47 for (i = 0; i < n; i++) { | 51 for (i = 0; i < n; i++) { |
48 lua_rawgeti(L, 1, f + i); | 52 lua_rawgeti(L, 1, f + i); |
49 lua_rawseti(L, tt, t + i); | 53 lua_rawseti(L, tt, t + i); |
50 } | 54 } |
51 } else { | 55 } else { |