static rpmlua globalLuaState = NULL;
+static char *(*nextFileFunc)(void *) = NULL;
+static void *nextFileFuncParam = NULL;
+
static int luaopen_rpm(lua_State *L);
static int rpm_print(lua_State *L);
return ret;
}
+void rpmluaSetNextFileFunc(char *(*func)(void *), void *funcParam)
+{
+ nextFileFunc = func;
+ nextFileFuncParam = funcParam;
+}
+
void rpmluaSetVar(rpmlua _lua, rpmluav var)
{
INITSTATE(_lua, lua);
int ret = 0;
if (name == NULL)
name = "<lua>";
+ if (script == NULL)
+ script = "";
if (luaL_loadbuffer(L, script, strlen(script), name) != 0) {
rpmlog(RPMLOG_ERR, _("invalid syntax in lua script: %s\n"),
lua_tostring(L, -1));
static int rpm_expand(lua_State *L)
{
const char *str = luaL_checkstring(L, 1);
- char *val = rpmExpand(str, NULL);
+ char *val = NULL;
+ if (rpmExpandMacros(NULL, str, &val, 0) < 0)
+ return luaL_error(L, "error expanding macro");
lua_pushstring(L, val);
free(val);
return 1;
static int rpm_define(lua_State *L)
{
const char *str = luaL_checkstring(L, 1);
- (void) rpmDefineMacro(NULL, str, 0);
+ if (rpmDefineMacro(NULL, str, 0))
+ return luaL_error(L, "error defining macro");
+ return 0;
+}
+
+static int rpm_undefine(lua_State *L)
+{
+ const char *str = luaL_checkstring(L, 1);
+ rpmPopMacro(NULL, str);
return 0;
}
+static int rpm_load(lua_State *L)
+{
+ const char *str = luaL_checkstring(L, 1);
+ int rc = rpmLoadMacroFile(NULL, str);
+ lua_pushnumber(L, rc);
+ return 1;
+}
+
static int rpm_interactive(lua_State *L)
{
_rpmluaInteractive(L);
return 0;
}
+static int rpm_next_file(lua_State *L)
+{
+ if (nextFileFunc)
+ lua_pushstring(L, nextFileFunc(nextFileFuncParam));
+ else
+ lua_pushstring(L, NULL);
+
+ return 1;
+}
+
typedef struct rpmluaHookData_s {
lua_State *L;
int funcRef;
{"b64decode", rpm_b64decode},
{"expand", rpm_expand},
{"define", rpm_define},
+ {"undefine", rpm_undefine},
+ {"load", rpm_load},
{"register", rpm_register},
{"unregister", rpm_unregister},
{"call", rpm_call},
{"interactive", rpm_interactive},
+ {"next_file", rpm_next_file},
{NULL, NULL}
};