aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
blob: 33d59b827664ea35906c7075ff2734c3d3bcbd5a (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
#include "config.h"

#include "lauxlib.h"

int open_config(pow_config *cfg, char *path) {
  int err;

  cfg->L = luaL_newstate();

  if (!cfg->L) {
    return 1;
  }

  lua_State *L = cfg->L; // just easier to access

  err = luaL_loadfile(L, path);

  if (err) {
    return 1;
  }

  err = lua_pcall(L, 0, 0, 0);

  if (err) {
    printf("%s\n", lua_tostring(L, -1));

    return 1;
  }

  return 0;
}