#include #include #include #include "termbox_render.h" #include "oct_termbox_sprite.h" #define TB_IMPL lua_State *L; int initialize_everything(); int deinitialize_everything(); int main(int argc, char* argv[]) { if (!initialize_everything()) { fprintf(stderr, "Couldn't initialize Open Card Table"); } struct tb_event ev; int finish = 0; while (!finish) { tb_clear(); tb_peek_event(&ev, 10); if (ev.key == TB_KEY_ESC) { finish = 1; } lua_getglobal(L, "oct_loop"); lua_pushinteger(L, ev.key); lua_pushinteger(L, ev.ch); lua_call(L, 2, 0); for (uint32_t i=0; i < oct_tb_sprite_list.new_index; i++) { oct_render_termbox_sprite(oct_tb_sprite_list.sprite_list[i]); } tb_present(); } deinitialize_everything(); return EXIT_SUCCESS; } int initialize_everything() { if (!oct_tb_sprite_list_initialize()) { return 0; } L = luaL_newstate(); if (L == NULL) { fprintf(stderr, "Can't initialize Lua\n"); return 0; } luaL_openlibs(L); oct_tb_initialize_lua(L); luaL_dofile(L, "pong.lua"); lua_getglobal(L, "oct_init"); lua_call(L, 0, 0); tb_init(); return 1; } int deinitialize_everything() { tb_shutdown(); lua_close(L); oct_tb_sprite_list_deinitialize(); return 1; }