aboutsummaryrefslogtreecommitdiff
path: root/src/read_config.cc
blob: 560b978273528d5b2064907b55012cac3f7d02d1 (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
extern "C" {
#include <luajit-2.1/lua.h>
#include <luajit-2.1/lauxlib.h>
#include <luajit-2.1/lualib.h>
}

#include <vars.hh>

void set_install_directories() {
  lua_State *L = lua_open();
  luaL_openlibs(L);

  if (luaL_loadfile(L, config_file.c_str()) || lua_pcall(L, 0, 0, 0)){
    std::cout << print_error << "cannot run configuration script: " << lua_tostring(L, -1) << "\n";
    return;
  }

  lua_getglobal(L, "install_directories");

  if (!lua_istable(L, -1)) {
    std::cout << print_error << "lua variable 'install_directories' is not a table.\n";
  }

  lua_pushnil(L);

  while (lua_next(L, -2) != 0) {
    const char *key = lua_tostring(L, -2);
    const char *value = lua_tostring(L, -1);

    install_dirs[key] = value;

    lua_pop(L, 1);
  }

  bin = install_dirs["bin"];
  lib = install_dirs["lib"];
  include = install_dirs["include"];
  pkgblds = install_dirs["pkgblds"];

}