-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlua_settings.c
More file actions
executable file
·51 lines (41 loc) · 1.28 KB
/
lua_settings.c
File metadata and controls
executable file
·51 lines (41 loc) · 1.28 KB
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
/* settings.c */
#include <stdio.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <raylib.h>
#include "luautil.h"
extern Color baizeColor;
void LoadSettings(int *windowWidth, int *windowHeight)
{
lua_State *L = luaL_newstate();
if (!L) {
fprintf(stderr, "ERROR: %s: could not create Lua state\n", __func__);
return;
}
luaL_openlibs(L);
if ( luaL_loadfile(L, "csol.settings.lua") || lua_pcall(L, 0, 0, 0) ) {
fprintf(stderr, "ERROR: %s: col.settings.lua: %s\n", __func__, lua_tostring(L, -1));
lua_pop(L, 1);
} else {
*windowWidth = LuaUtilGetGlobalInt("WindowWidth", 640);
*windowHeight = LuaUtilGetGlobalInt("WindowHeight", 480);
int typ = lua_getglobal(L, "BaizeColor");
if ( typ == LUA_TTABLE ) {
float r, g, b, a;
r = LuaUtilGetFieldFloat("red", 1);
g = LuaUtilGetFieldFloat("green", 1);
b = LuaUtilGetFieldFloat("blue", 1);
a = LuaUtilGetFieldFloat("alpha", 1);
baizeColor = (Color){.r=r*255, .g=g*255, .b=b*255, .a=a*255};
} else {
baizeColor = DARKGREEN;
}
lua_pop(L, 1); // remove global (table)
}
lua_close(L);
}
void SaveSettings(void)
{
}