luapage/main.c

41 lines
1,007 B
C
Raw Normal View History

2021-04-27 21:37:32 +03:00
#include <stdio.h>
2021-05-02 15:07:43 +03:00
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <luajit.h>
2021-04-27 21:37:32 +03:00
2021-05-02 17:24:40 +03:00
#include "ui.h"
#include "lua.h"
2021-05-02 15:07:43 +03:00
2021-05-02 17:24:40 +03:00
static void activate(GtkApplication* app, struct application_state* state) {
printf("gtk: ready\n");
page_application_init(state);
int status = lua_init_state(state->L, state);
if (status != 0) {
2021-05-03 14:51:05 +03:00
fprintf(stderr, "error: lua_init_state failed with non-zero error code %d\n", status);
return;
2021-05-02 17:24:40 +03:00
}
page_application_show(state);
lua_close(state->L);
}
2021-05-02 15:07:43 +03:00
2021-05-02 17:24:40 +03:00
int main(int argc, char** argv) {
lua_State* L;
int status = 1;
2021-05-02 15:07:43 +03:00
2021-05-02 17:24:40 +03:00
L = luaL_newstate();
2021-05-02 15:07:43 +03:00
if (!L) {
fprintf(stderr, "error: failed to create lua state");
return -1;
}
2021-05-02 17:24:40 +03:00
struct application_state* state = page_application_new();
state->L = L;
2021-05-02 15:07:43 +03:00
2021-05-02 17:24:40 +03:00
g_signal_connect(state->gapp, "activate", G_CALLBACK(activate), state);
status = g_application_run(G_APPLICATION(state->gapp), argc, argv);
g_object_unref(state->gapp);
2021-05-02 15:07:43 +03:00
return status;
}