//! ---------------------------------------------------- //! ---------------------------------------------------- // // PRIVATE // const App = @import("app"); const Zla = @import("zla"); // // PUBLIC // /// ---------------------------------------------------- /// ---------------------------------------------------- pub const plugin: App.plugin.Plugin = .{ .name = "LUA", .build = build, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn build( _: *App.plugin.Plugin, app: *App, ) !void { // --- LIFETIME --- try app.schedules.addMany(App.stage.init, &.{init}); try app.schedules.addMany(App.stage.deinit, &.{ deinit, lua_deinit }); // --- EXEC --- try app.schedules.addManyAfter(App.stage.init, App.stage.init, &.{lua_init}); // --- FRAME --- try app.schedules.add(App.stage.inputs, lua_inputs); try app.schedules.add(App.stage.update, lua_update); try app.schedules.add(App.stage.draw, lua_draw); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn init(app: *App) !void { // --- ZLA --- _ = try app.resources.getOrSet( try Zla.init(app.alloc), ); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn deinit(app: *App) !void { // --- # --- const res = try app.resources.getMany(struct { zla: *Zla, }); // --- # --- res.zla.deinit(); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn lua_init(app: *App) !void { const res = try app.resources.getMany(struct { zla: *Zla }); try res.zla.execFromFile(void, "src/scripts/main.lua"); try res.zla.call(void, "init", .{}); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn lua_deinit(app: *App) !void { const res = try app.resources.getMany(struct { zla: *Zla }); try res.zla.call(void, "deinit", .{}); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn lua_inputs(app: *App) !void { const res = try app.resources.getMany(struct { zla: *Zla }); try res.zla.call(void, "inputs", .{}); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn lua_update(app: *App) !void { const res = try app.resources.getMany(struct { zla: *Zla }); try res.zla.call(void, "update", .{}); } /// ---------------------------------------------------- /// ---------------------------------------------------- fn lua_draw(app: *App) !void { const res = try app.resources.getMany(struct { zla: *Zla }); try res.zla.call(void, "draw", .{}); }