]>
git.ipfire.org Git - location/libloc.git/blob - src/lua/compat.h
2 libloc - A library to determine the location of someone on the Internet
4 Copyright (C) 2024 IPFire Development Team <info@ipfire.org>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
17 #ifndef LUA_LOCATION_COMPAT_H
18 #define LUA_LOCATION_COMPAT_H
23 #if LUA_VERSION_RELEASE_NUM < 502
25 static inline void luaL_setmetatable(lua_State
* L
, const char* name
) {
26 luaL_checkstack(L
, 1, "not enough stack slots");
27 luaL_getmetatable(L
, name
);
28 lua_setmetatable(L
, -2);
31 static inline void luaL_setfuncs(lua_State
* L
, const luaL_Reg
* l
, int nup
) {
34 luaL_checkstack(L
, nup
+1, "too many upvalues");
36 for (; l
->name
!= NULL
; l
++) {
37 lua_pushstring(L
, l
->name
);
39 for (i
= 0; i
< nup
; i
++)
40 lua_pushvalue(L
, -(nup
+ 1));
42 lua_pushcclosure(L
, l
->func
, nup
);
43 lua_settable(L
, -(nup
+ 3));
49 static inline void luaL_newlib(lua_State
* L
, const luaL_Reg
* l
) {
51 luaL_setfuncs(L
, l
, 0);
54 #endif /* Lua < 5.2 */
56 #endif /* LUA_LOCATION_COMPAT_H */