mach/platform: check for App functions in all platforms

This commit is contained in:
iddev5 2022-05-30 13:36:27 +05:30 committed by Stephen Gutekanst
parent 21c49ff9be
commit ff126c0054
3 changed files with 13 additions and 4 deletions

6
src/platform/common.zig Normal file
View file

@ -0,0 +1,6 @@
pub fn checkApplication(comptime App: type) void {
// TODO: check signature
if (!@hasDecl(App, "init")) @compileError("App must export 'pub fn init(app: *App, engine: *mach.Engine) !void'");
if (!@hasDecl(App, "deinit")) @compileError("App must export 'pub fn deinit(app: *App, engine: *mach.Engine) void'");
if (!@hasDecl(App, "update")) @compileError("App must export 'pub fn update(app: *App, engine: *mach.Engine) !bool'");
}

View file

@ -390,11 +390,9 @@ pub const GpuDriver = struct {
pub const BackingTimer = std.time.Timer;
// TODO: check signatures
const common = @import("common.zig");
comptime {
if (!@hasDecl(App, "init")) @compileError("App must export 'pub fn init(app: *App, engine: *mach.Engine) !void'");
if (!@hasDecl(App, "deinit")) @compileError("App must export 'pub fn deinit(app: *App, engine: *mach.Engine) void'");
if (!@hasDecl(App, "update")) @compileError("App must export 'pub fn update(app: *App, engine: *mach.Engine) !bool'");
common.checkApplication(App);
}
pub fn main() !void {

View file

@ -110,6 +110,11 @@ pub const BackingTimer = struct {
}
};
const common = @import("common.zig");
comptime {
common.checkApplication(App);
}
var app: App = undefined;
var engine: Engine = undefined;