summaryrefslogtreecommitdiff
path: root/src/argent.c
blob: b83f851ee5705f09f271ea70c9ff171c9eebfaef (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
55
56
57
58
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

#include "honeysuckle.h"

#include "options.h"
#include "bindings.h"
#include "logging.h"


struct settings {
   const char *template_dir;
};


int main(int argc, char **argv)
{
   argent_log(DEBUG, "parse command-line options");
   struct argent_options opts;
   int error = parse_options(&opts, argc, argv);
   if (error)
      return 1;

   argent_log(INFO, "log level: %s", level_string(argent_log_level));
   argent_log(INFO, "configuration file: %s", opts.conf_filename);
   argent_log(INFO, "output directory: %s", opts.output_dir);

   argent_log(DEBUG, "create lua state");
   lua_State *L = luaL_newstate();
   luaL_openlibs(L);

   argent_log(DEBUG, "create argent table");
   hs_create_table
      (L,
       hs_str_cfunc("markdown", markdown)
       );
   lua_setglobal(L, "argent");

   argent_log(DEBUG, "load configuration file");
   error = luaL_loadfile(L, opts.conf_filename);
   if (error != 0) {
      argent_log(FATAL, "lua error: %s", lua_tostring(L, -1));
      lua_close(L);
      return error;
   }
   argent_log(DEBUG, "run configuration file");
   error = hs_call(L, 0, 1);
   if (error != 0) {
      argent_log(FATAL, "lua error: %s", lua_tostring(L, -1));
      lua_close(L);
      return error;
   }

   argent_log(DEBUG, "close lua state");
   lua_close(L);
   return 0;
}