summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-01-04 12:17:02 -0600
committersanine <sanine.not@pm.me>2022-01-04 12:17:02 -0600
commit0e84036b1b727356d433373b017204a8d575d2e4 (patch)
tree580ba1cf6f3f1a0f984a1f21511ea7d36814394a /src
parentcb4f641884ae6104f44967949f9b52a9a72f7baf (diff)
add lua logging
Diffstat (limited to 'src')
-rw-r--r--src/argent.c3
-rw-r--r--src/bindings.c31
-rw-r--r--src/bindings.h2
-rwxr-xr-x[-rw-r--r--]src/lua-script/cify.lua6
-rw-r--r--src/lua-script/script.h41
-rw-r--r--src/lua-script/script.lua41
6 files changed, 109 insertions, 15 deletions
diff --git a/src/argent.c b/src/argent.c
index 0d0dca2..97d6862 100644
--- a/src/argent.c
+++ b/src/argent.c
@@ -46,7 +46,8 @@ int main(int argc, char **argv)
hs_str_cfunc("markdown", markdown),
hs_str_cfunc("scanDirectory", scan_directory),
hs_str_cfunc("createDirectory", create_directory),
- hs_str_cfunc("copyFile", copy_file)
+ hs_str_cfunc("copyFile", copy_file),
+ hs_str_cfunc("log", argent_log_lua)
);
lua_setglobal(L, "argent");
diff --git a/src/bindings.c b/src/bindings.c
index 8e7d4d5..1e24570 100644
--- a/src/bindings.c
+++ b/src/bindings.c
@@ -321,3 +321,34 @@ int copy_file(lua_State *L)
return 0;
}
+
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+int argent_log_lua(lua_State *L)
+{
+ char *level_string, *message;
+ hs_parse_args(L, hs_str(level_string), hs_str(message));
+
+ int level;
+
+ if(strcmp(level_string, "fatal") == 0)
+ level = FATAL;
+ else if (strcmp(level_string, "error") == 0)
+ level = ERROR;
+ else if (strcmp(level_string, "warn") == 0)
+ level = WARN;
+ else if (strcmp(level_string, "info") == 0)
+ level = INFO;
+ else if (strcmp(level_string, "debug") == 0)
+ level = DEBUG;
+ else if (strcmp(level_string, "trace") == 0)
+ level = TRACE;
+ else {
+ argent_log(WARN, "level '%s' is invalid; defaulting to 'info'", level_string);
+ level = INFO;
+ }
+
+ argent_log(level, message);
+ return 0;
+}
diff --git a/src/bindings.h b/src/bindings.h
index 847baa7..02f33c6 100644
--- a/src/bindings.h
+++ b/src/bindings.h
@@ -13,4 +13,6 @@ int create_directory(lua_State *L);
int copy_file(lua_State *L);
+int argent_log_lua(lua_State *L);
+
#endif
diff --git a/src/lua-script/cify.lua b/src/lua-script/cify.lua
index 153feb3..a2fbcbe 100644..100755
--- a/src/lua-script/cify.lua
+++ b/src/lua-script/cify.lua
@@ -1,11 +1,13 @@
+#!/usr/bin/lua
+
-- "C"-ify a lua program
-output_file = io.open(arg[2], 'w')
+output_file = io.open('script.h', 'w')
output_file:write('const char *argent_script =\n')
-for line in io.lines(arg[1]) do
+for line in io.lines('script.lua') do
output_file:write(' "'..line..'\\n"\n')
end
diff --git a/src/lua-script/script.h b/src/lua-script/script.h
index e419923..fe92cef 100644
--- a/src/lua-script/script.h
+++ b/src/lua-script/script.h
@@ -11,7 +11,7 @@ const char *argent_script =
" if type(array) ~= 'table' then return nil end\n"
"\n"
" local transform = transform or function(x) return x end\n"
- " \n"
+ "\n"
" local set = {}\n"
" for _, element in ipairs(array) do\n"
" set[transform(element)] = true\n"
@@ -19,6 +19,19 @@ const char *argent_script =
" return set\n"
" end\n"
"\n"
+ " function set_tostring(set)\n"
+ " local str = '[empty]'\n"
+ " for element in pairs(set) do\n"
+ " if str == '[empty]' then\n"
+ " str = tostring(element)\n"
+ " else\n"
+ " str = str .. '; '.. tostring(element)\n"
+ " end\n"
+ " end\n"
+ "\n"
+ " return str\n"
+ " end\n"
+ "\n"
"\n"
" function add_end_slash(str)\n"
" if type(str) ~= 'string' then return nil end\n"
@@ -34,11 +47,14 @@ const char *argent_script =
"\n"
"\n"
" function setup(config)\n"
+ " argent.log('debug', 'begin setup')\n"
+ " local fmt = string.format\n"
+ "\n"
" argent.config = {\n"
" site_directory = add_end_slash(config.site_directory) or 'site/',\n"
" output_directory = add_end_slash(config.output_directory) or 'public/',\n"
- " layout_directory = add_end_slash(config.layout_directory) or 'layouts/',\n"
- " plugin_directory = add_end_slash(config.layout_directory) or 'plugins/',\n"
+ " layout_directory = add_end_slash(config.layout_directory) or nil,\n"
+ " plugin_directory = add_end_slash(config.layout_directory) or nil,\n"
" exclude = Set(config.exclude, strip_end_slash) or {},\n"
" include = Set(config.include, strip_end_slash) or {},\n"
" keep = Set(config.keep, strip_end_slash) or {},\n"
@@ -46,7 +62,21 @@ const char *argent_script =
" rss_include = Set(config.rss_include, strip_end_slash) or {},\n"
" }\n"
"\n"
- " package.path = argent.config.plugin_directory..'?.lua;'..package.path\n"
+ " argent.log('info', fmt('site directory: %s', argent.config.site_directory))\n"
+ " argent.log('info', fmt('output directory: %s', argent.config.output_directory))\n"
+ " argent.log('info', fmt('layout directory: %s', tostring(argent.config.layout_directory)))\n"
+ " argent.log('info', fmt('plugin directory: %s', tostring(argent.config.plugin_directory)))\n"
+ "\n"
+ " argent.log('info', 'exclusions: '..set_tostring(argent.config.exclude))\n"
+ " argent.log('info', 'inclusions: '..set_tostring(argent.config.include))\n"
+ " argent.log('info', 'files to keep: '..set_tostring(argent.config.keep))\n"
+ " argent.log('info', 'noprocess: '..set_tostring(argent.config.noprocess))\n"
+ " argent.log('info', 'rss files: '..set_tostring(argent.config.rss_include))\n"
+ "\n"
+ " if argent.config.plugin_directory then\n"
+ " package.path = argent.config.plugin_directory..'?.lua;'..package.path\n"
+ " end\n"
+ " argent.log('debug', 'end setup')\n"
" end\n"
"\n"
"\n"
@@ -106,7 +136,7 @@ const char *argent_script =
" function obliterate_directory(dirname, parent)\n"
" local dirname = add_end_slash(dirname) or ''\n"
" local parent = parent or ''\n"
- " \n"
+ "\n"
" if argent.config.keep[dirname] then return true end\n"
"\n"
" local keep_self = (dirname == '')\n"
@@ -205,5 +235,4 @@ const char *argent_script =
" end\n"
" process_directory()\n"
"end\n"
- "\n"
; \ No newline at end of file
diff --git a/src/lua-script/script.lua b/src/lua-script/script.lua
index 733c494..ef2ef8f 100644
--- a/src/lua-script/script.lua
+++ b/src/lua-script/script.lua
@@ -10,7 +10,7 @@ return function(config)
if type(array) ~= 'table' then return nil end
local transform = transform or function(x) return x end
-
+
local set = {}
for _, element in ipairs(array) do
set[transform(element)] = true
@@ -18,6 +18,19 @@ return function(config)
return set
end
+ function set_tostring(set)
+ local str = '[empty]'
+ for element in pairs(set) do
+ if str == '[empty]' then
+ str = tostring(element)
+ else
+ str = str .. '; '.. tostring(element)
+ end
+ end
+
+ return str
+ end
+
function add_end_slash(str)
if type(str) ~= 'string' then return nil end
@@ -33,11 +46,14 @@ return function(config)
function setup(config)
+ argent.log('debug', 'begin setup')
+ local fmt = string.format
+
argent.config = {
site_directory = add_end_slash(config.site_directory) or 'site/',
output_directory = add_end_slash(config.output_directory) or 'public/',
- layout_directory = add_end_slash(config.layout_directory) or 'layouts/',
- plugin_directory = add_end_slash(config.layout_directory) or 'plugins/',
+ layout_directory = add_end_slash(config.layout_directory) or nil,
+ plugin_directory = add_end_slash(config.layout_directory) or nil,
exclude = Set(config.exclude, strip_end_slash) or {},
include = Set(config.include, strip_end_slash) or {},
keep = Set(config.keep, strip_end_slash) or {},
@@ -45,7 +61,21 @@ return function(config)
rss_include = Set(config.rss_include, strip_end_slash) or {},
}
- package.path = argent.config.plugin_directory..'?.lua;'..package.path
+ argent.log('info', fmt('site directory: %s', argent.config.site_directory))
+ argent.log('info', fmt('output directory: %s', argent.config.output_directory))
+ argent.log('info', fmt('layout directory: %s', tostring(argent.config.layout_directory)))
+ argent.log('info', fmt('plugin directory: %s', tostring(argent.config.plugin_directory)))
+
+ argent.log('info', 'exclusions: '..set_tostring(argent.config.exclude))
+ argent.log('info', 'inclusions: '..set_tostring(argent.config.include))
+ argent.log('info', 'files to keep: '..set_tostring(argent.config.keep))
+ argent.log('info', 'noprocess: '..set_tostring(argent.config.noprocess))
+ argent.log('info', 'rss files: '..set_tostring(argent.config.rss_include))
+
+ if argent.config.plugin_directory then
+ package.path = argent.config.plugin_directory..'?.lua;'..package.path
+ end
+ argent.log('debug', 'end setup')
end
@@ -105,7 +135,7 @@ return function(config)
function obliterate_directory(dirname, parent)
local dirname = add_end_slash(dirname) or ''
local parent = parent or ''
-
+
if argent.config.keep[dirname] then return true end
local keep_self = (dirname == '')
@@ -204,4 +234,3 @@ return function(config)
end
process_directory()
end
-