ona/src/main.zig

50 lines
1.1 KiB
Zig
Raw Normal View History

2022-09-22 23:03:25 +02:00
const ext = @cImport({
2022-08-10 15:52:16 +02:00
@cInclude("SDL2/SDL.h");
});
const io = @import("./io.zig");
const stack = @import("./stack.zig");
2022-08-10 15:52:16 +02:00
const std = @import("std");
2022-09-25 00:09:02 +02:00
const sys = @import("./sys.zig");
///
/// Entry point.
///
2022-08-10 15:52:16 +02:00
pub fn main() anyerror!void {
2022-10-15 12:38:22 +02:00
return nosuspend await async sys.runGraphics(anyerror, run);
}
2022-10-01 22:25:06 +02:00
test {
2022-10-03 23:58:38 +02:00
_ = io;
_ = stack;
_ = std;
_ = sys;
2022-10-01 22:25:06 +02:00
}
2022-10-10 11:15:45 +02:00
fn run(app: *sys.AppContext, graphics: *sys.GraphicsContext) anyerror!void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
{
var file_access = try (try app.data().joinedPath(&.{"ona.lua"})).open(.readonly);
2022-08-10 15:52:16 +02:00
defer file_access.close();
2022-08-10 15:52:16 +02:00
const file_size = try file_access.queryLength();
const allocator = gpa.allocator();
const buffer = try allocator.alloc(u8, file_size);
defer allocator.free(buffer);
if ((try file_access.read(buffer)) != file_size)
return error.ScriptLoadFailure;
sys.Log.debug.write(buffer);
}
while (graphics.poll()) |_| {
graphics.present();
2022-08-10 15:52:16 +02:00
}
}