mach: check application signature
This commit is contained in:
parent
c831840094
commit
ff69efea52
1 changed files with 25 additions and 4 deletions
|
|
@ -1,6 +1,27 @@
|
||||||
|
const Engine = @import("../Engine.zig");
|
||||||
|
|
||||||
pub fn checkApplication(comptime App: type) void {
|
pub fn checkApplication(comptime App: type) void {
|
||||||
// TODO: check signature
|
if (@hasDecl(App, "init")) {
|
||||||
if (!@hasDecl(App, "init")) @compileError("App must export 'pub fn init(app: *App, engine: *mach.Engine) !void'");
|
const InitFn = @TypeOf(@field(App, "init"));
|
||||||
if (!@hasDecl(App, "deinit")) @compileError("App must export 'pub fn deinit(app: *App, engine: *mach.Engine) void'");
|
if (InitFn != fn (app: *App, engine: *Engine) @typeInfo(@typeInfo(InitFn).Fn.return_type.?).ErrorUnion.error_set!void)
|
||||||
if (!@hasDecl(App, "update")) @compileError("App must export 'pub fn update(app: *App, engine: *mach.Engine) !void'");
|
@compileError("expected 'pub fn init(app: *App, engine: *mach.Engine) !void' found '" ++ @typeName(InitFn) ++ "'");
|
||||||
|
} else {
|
||||||
|
@compileError("App must export 'pub fn init(app: *App, engine: *mach.Engine) !void'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (@hasDecl(App, "update")) {
|
||||||
|
const UpdateFn = @TypeOf(@field(App, "update"));
|
||||||
|
if (UpdateFn != fn (app: *App, engine: *Engine) @typeInfo(@typeInfo(UpdateFn).Fn.return_type.?).ErrorUnion.error_set!void)
|
||||||
|
@compileError("expected 'pub fn update(app: *App, engine: *mach.Engine) !void' found '" ++ @typeName(UpdateFn) ++ "'");
|
||||||
|
} else {
|
||||||
|
@compileError("App must export 'pub fn update(app: *App, engine: *mach.Engine) !void'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (@hasDecl(App, "deinit")) {
|
||||||
|
const DeinitFn = @TypeOf(@field(App, "deinit"));
|
||||||
|
if (DeinitFn != fn (app: *App, engine: *Engine) void)
|
||||||
|
@compileError("expected 'pub fn deinit(app: *App, engine: *mach.Engine) void' found '" ++ @typeName(DeinitFn) ++ "'");
|
||||||
|
} else {
|
||||||
|
@compileError("App must export 'pub fn deinit(app: *App, engine: *mach.Engine) void'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue