optflags: set _FORTIFY_SOURCE for preproc
[platform/upstream/rpm.git] / lib / rpmliblua.c
1 #include "system.h"
2
3 #ifdef WITH_LUA
4 #include <lua.h>
5 #include <lauxlib.h>
6 #include <rpm/rpmlib.h>
7
8 #define _RPMLUA_INTERNAL
9 #include "rpmio/rpmlua.h"
10 #include "lib/rpmliblua.h"
11
12 static int rpm_vercmp(lua_State *L)
13 {
14     const char *v1, *v2;
15     int rc = 0;
16
17     v1 = luaL_checkstring(L, 1);
18     v2 = luaL_checkstring(L, 2);
19     if (v1 && v2) {
20         lua_pushinteger(L, rpmvercmp(v1, v2));
21         rc = 1;
22     }
23     return rc;
24 }
25
26 static const luaL_Reg luarpmlib_f[] = {
27     {"vercmp", rpm_vercmp},
28     {NULL, NULL}
29 };
30
31 #ifndef lua_pushglobaltable
32 #define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
33 #endif
34
35 void rpmLuaInit(void)
36 {
37     rpmlua lua = rpmluaGetGlobalState();
38     lua_pushglobaltable(lua->L);
39 #if (LUA_VERSION_NUM < 502) || defined(LUA_COMPAT_MODULE)
40     luaL_register(lua->L, "rpm", luarpmlib_f);
41 #else
42     luaL_pushmodule(lua->L, "rpm", 1);
43     lua_insert(lua->L, -1);
44     luaL_setfuncs(lua->L, luarpmlib_f, 0);
45 #endif
46     return;
47 }
48
49 void rpmLuaFree(void)
50 {
51     rpmlua lua = rpmluaGetGlobalState();
52     rpmluaFree(lua);
53 }
54
55 #endif /* WITH_LUA */