filter and format lua func

This commit is contained in:
damage 2025-01-18 21:11:39 +01:00
parent 753944ac9c
commit 4c05853c0d
2 changed files with 36 additions and 4 deletions

View File

@ -47,19 +47,47 @@ int main(int argc, char *argv[]) {
}
while ((read = getline(&line, &len, fp)) != -1) {
int filter;
size_t formatLen;
const char *formatLine;
trim(line);
lua_getglobal(L, "filter");
lua_pushlstring(L, line, read);
if (lua_pcall(L, 1, 1, 0) != 0) {
fprintf(stderr, "Error running LUA function 'filter': %s\n", lua_tostring(L, -1));
return EXIT_LUAFILE_HANDLING;
}
if (!lua_isboolean(L, -1)) {
fprintf(stderr, "LUA function 'filter' did not return a boolean");
return EXIT_LUAFILE_HANDLING;
}
filter = lua_toboolean(L, -1);
lua_pop(L, 1);
if (filter) {
continue;
}
lua_getglobal(L, "format");
lua_pushlstring(L, line, read);
if (lua_pcall(L, 1, 1, 0) != 0) {
fprintf(stderr, "Error running LUA function 'format': %s\n", lua_tostring(L, -1));
return EXIT_LUAFILE_HANDLING;
}
printf("%s\n", lua_tostring(L, -1));
lua_pop(L, 1);
if (!lua_isstring(L, -1)) {
fprintf(stderr, "LUA function 'format' did not return a string");
return EXIT_LUAFILE_HANDLING;
}
formatLine = lua_tolstring(L, -1 , &formatLen);
printf("(%zu) %s\n", formatLen, formatLine);
}
if (errno) {
fprintf(stderr, "Error readling file %s: %s\n", logfile, strerror(errno));
fprintf(stderr, "Error reading file %s: %s\n", logfile, strerror(errno));
return EXIT_LOGFILE_HANDLING;
}

View File

@ -1,3 +1,7 @@
function filter (line)
return line:find("Unknown kernel command line parameters") == nil
end
function format (line)
return line:gsub(" ", "\n");
return line:match("\"([^\"]+)\"")
end