summaryrefslogtreecommitdiff
path: root/build/speclua.c
blob: 2ed73a62c7ea0c49c5df121352d389f0900fa359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#include "system.h"

#include <lua.h>

#include "rpmio/rpmlua.h"
#include "build/rpmbuild_internal.h"

#include "debug.h"

static const char * luavars[] = { "patches", "sources",
			       "patch_nums", "source_nums", NULL, };

void * specLuaInit(rpmSpec spec)
{
    rpmlua lua = rpmluaGetGlobalState();
    lua_State *L = rpmluaGetLua(lua);
    for (const char **vp = luavars; vp && *vp; vp++) {
	lua_newtable(L);
	lua_setglobal(L, *vp);
    }

    return lua;
}

void * specLuaFini(rpmSpec spec)
{
    rpmlua lua = rpmluaGetGlobalState();
    lua_State *L = rpmluaGetLua(lua);
    for (const char **vp = luavars; vp && *vp; vp++) {
	lua_pushnil(L);
	lua_setglobal(L, *vp);
    }
    return NULL;
}

void addLuaSource(const struct Source *p)
{
    rpmlua lua = rpmluaGetGlobalState();
    lua_State *L = rpmluaGetLua(lua);
    const char * what = (p->flags & RPMBUILD_ISPATCH) ? "patches" : "sources";

    lua_getglobal(L, what);
    lua_pushstring(L, p->path);
    lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
    lua_pop(L, 1);

    what = (p->flags & RPMBUILD_ISPATCH) ? "patch_nums" : "source_nums";
    lua_getglobal(L, what);
    lua_pushinteger(L, p->num);
    lua_rawseti(L, -2, lua_rawlen(L, -2) + 1);
    lua_pop(L, 1);
}