#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

void load(char *filename, char *width, char *height);
void error (lua_State *L, const char *fmt, ...);

int main (void) {
	char width[100];
	char height[100];
	char *w = width;
	char *h = height;
	load("fake.txt", w, h);
	printf("Height: %s Width: %s\n",height, width);
  return 0;
}

void load(char *filename, char  *width, char *height){

	lua_State *L = luaL_newstate();
	luaL_openlibs(L);

	if (luaL_loadfile(L, filename) || lua_pcall(L, 0, 0, 0))
		error(L, "cannot run configuration file: %s",
				lua_tostring(L, -1));

	lua_getglobal(L, "width");
	lua_getglobal(L, "height");
	
	strcpy(height, lua_tostring(L, -1));
	strcpy(width, lua_tostring(L, -2));
	
	lua_close(L);
}

void error (lua_State *L, const char *fmt, ...) {
  va_list argp;
  va_start(argp, fmt);
  vfprintf(stderr,fmt, argp);
  va_end(argp);
  lua_close(L);
  exit(EXIT_FAILURE);
}