You can easily port the Gly Engine to any platform by following a few straight forward steps. The main requirement is to create interfaces that connect with the native graphics libraries and hardware specific to your platform. Here’s how to get started:
By following these steps, you can effectively port the Gly Engine to any platform of your choice.
Using the
Lua C API, you must expose these functions to your Lua VM, so that the engine can communicate with the low-level resources of the system.
API Level 0
Even if you have nothing to do in draw
or loop
of a game, these functions will be called to the microengine to know the start and end of the intention to paint each frame.
API Level 1
void native_draw_color(int color)
void native_draw_clear(int color)
void native_draw_rect(int mode, double x, double y, double width, double heigth)
API Level 2
void native_draw_line(double x1, double y1, double x1, double y1)
void native_draw_text(double x, double y, char* text)
void native_draw_font(int size)
void native_draw_font(char* name, int size)
API Level 1
void native_callback_loop(double dt)
void native_callback_draw()
void native_callback_keyboard(char* key, bool value)
void native_callback_init(width, height, game_lua)
API Level 2
void native_callback_resize(double width, double height)
native_draw_line in SDL2
static int native_draw_line(lua_State *L) {
assert(lua_gettop(L) == 4);
float x1 = luaL_checknumber(L, 1);
float y1 = luaL_checknumber(L, 2);
float x2 = luaL_checknumber(L, 3);
float y2 = luaL_checknumber(L, 4);
SDL_RenderDrawLineF(renderer, x1, y1, x2, y2);
lua_pop(L, 4);
return 0;
}
micro-engine start
void gly_engine_start()
{
luaL_loadbuffer(L, engine_bytecode_lua, engine_bytecode_lua_len, "");
lua_pcall(L, 0, 0, 0);
lua_getglobal(L, "native_callback_init");
lua_pushnumber(L, 1280);
lua_pushnumber(L, 720);
luaL_loadbuffer(L, game_bytecode_lua, game_bytecode_lua_len, "");
lua_pcall(L, 0, 1, 0);
lua_pcall(L, 3, 0, 0);
}
micro-engine loop
void gly_engine_loop()
{
lua_getglobal(L, "native_callback_loop");
lua_pushnumber(L, 16);
lua_pcall(L, 1, 0, 0);
lua_getglobal(L, "native_callback_draw");
lua_pushnumber(L, 16);
lua_pcall(L, 1, 0, 0);
usleep(16000);
}