summaryrefslogtreecommitdiff
path: root/src/honey.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/honey.c')
-rw-r--r--src/honey.c41
1 files changed, 10 insertions, 31 deletions
diff --git a/src/honey.c b/src/honey.c
index 0bd5b25..cfc5bc7 100644
--- a/src/honey.c
+++ b/src/honey.c
@@ -55,45 +55,24 @@ bool honey_parse_options(honey_options* options, int argc, char** argv)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-bool honey_setup(lua_State** L, honey_window* window)
+bool honey_setup(lua_State** L)
{
- /* set up glfw */
- glfwInit();
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
-
- *window = glfwCreateWindow(640, 480, "honey", NULL, NULL);
- if (*window == NULL) {
- fprintf(stderr, "[honey] ERROR: failed to create window!\n");
- glfwTerminate();
- return false;
- }
-
- glfwMakeContextCurrent(*window);
-
- if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress)) {
- fprintf(stderr, "[honey] ERROR: failed to initialize GLAD!\n");
- glfwTerminate();
- return false;
- }
-
- honey_setup_keyboard();
- glfwSetKeyCallback(*window, default_honey_keyboard_callback);
-
- // Enable blending
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-
/* set up lua and honey lua bindings */
*L = luaL_newstate();
luaL_openlibs(*L);
- glfwSetWindowUserPointer(*window, *L);
lua_createtable(*L, 0, 1);
+ if (!honey_setup_window(*L))
+ return false;
+
+ lua_getfield(*L, -1, "internal");
+ honey_window_information* info = lua_touserdata(*L, -1);
+ lua_pop(*L, 1);
+ lua_setfield(*L, -2, "window");
+
honey_setup_input(*L);
+ glfwSetKeyCallback(info->window, default_honey_keyboard_callback);
lua_setfield(*L, -2, "input");
lua_setglobal(*L, "honey");