zig init
This commit is contained in:
parent
7fd97746a6
commit
0bae4381c8
6 changed files with 221 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -8,3 +8,6 @@ NVL/out
|
|||
vs
|
||||
**/.DS_STORE
|
||||
.gitconfig
|
||||
|
||||
.zig-cache
|
||||
zig-out
|
||||
|
|
52
build.zig
Normal file
52
build.zig
Normal file
|
@ -0,0 +1,52 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
const lib_mod = b.createModule(.{
|
||||
.root_source_file = b.path("src/NouVeL.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const exe_mod = b.createModule(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
exe_mod.addImport("NouVeL_lib", lib_mod);
|
||||
|
||||
const lib = b.addLibrary(.{
|
||||
.linkage = .static,
|
||||
.name = "NouVeL",
|
||||
.root_module = lib_mod,
|
||||
});
|
||||
|
||||
b.installArtifact(lib);
|
||||
|
||||
const sdl_dep = b.dependency("sdl", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const sdl_lib = sdl_dep.artifact("SDL3");
|
||||
exe_mod.linkLibrary(sdl_lib);
|
||||
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "NouVeL",
|
||||
.root_module = exe_mod,
|
||||
});
|
||||
|
||||
b.installArtifact(exe);
|
||||
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
52
build.zig.zon
Normal file
52
build.zig.zon
Normal file
|
@ -0,0 +1,52 @@
|
|||
.{
|
||||
// This is the default name used by packages depending on this one. For
|
||||
// example, when a user runs `zig fetch --save <url>`, this field is used
|
||||
// as the key in the `dependencies` table. Although the user can choose a
|
||||
// different name, most users will stick with this provided value.
|
||||
//
|
||||
// It is redundant to include "zig" in this name because it is already
|
||||
// within the Zig package namespace.
|
||||
.name = .NouVeL,
|
||||
|
||||
// This is a [Semantic Version](https://semver.org/).
|
||||
// In a future version of Zig it will be used for package deduplication.
|
||||
.version = "0.0.0",
|
||||
|
||||
// Together with name, this represents a globally unique package
|
||||
// identifier. This field is generated by the Zig toolchain when the
|
||||
// package is first created, and then *never changes*. This allows
|
||||
// unambiguous detection of one package being an updated version of
|
||||
// another.
|
||||
//
|
||||
// When forking a Zig project, this id should be regenerated (delete the
|
||||
// field and run `zig build`) if the upstream project is still maintained.
|
||||
// Otherwise, the fork is *hostile*, attempting to take control over the
|
||||
// original project's identity. Thus it is recommended to leave the comment
|
||||
// on the following line intact, so that it shows up in code reviews that
|
||||
// modify the field.
|
||||
.fingerprint = 0xccc2bad62f8e579f, // Changing this has security and trust implications.
|
||||
|
||||
// Tracks the earliest Zig version that the package considers to be a
|
||||
// supported use case.
|
||||
.minimum_zig_version = "0.14.0",
|
||||
|
||||
// This field is optional.
|
||||
// Each dependency must either provide a `url` and `hash`, or a `path`.
|
||||
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
|
||||
// Once all dependencies are fetched, `zig build` no longer requires
|
||||
// internet connectivity.
|
||||
.dependencies = .{
|
||||
.sdl = .{
|
||||
.url = "git+https://github.com/castholm/SDL.git#f6bbe8ac5e7b901db69ba62f017596090c362d84",
|
||||
.hash = "sdl-0.2.1+3.2.10-7uIn9PLkfQHKJO7TvSXbVa0VnySCHbLz28PDZIlKWF4Y",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
// For example...
|
||||
//"LICENSE",
|
||||
//"README.md",
|
||||
},
|
||||
}
|
6
src/NouVeL.zig
Normal file
6
src/NouVeL.zig
Normal file
|
@ -0,0 +1,6 @@
|
|||
const std = @import("std");
|
||||
const parser = @import("parser.zig");
|
||||
|
||||
pub export fn add(a: i32, b: i32) i32 {
|
||||
return a + b;
|
||||
}
|
65
src/main.zig
Normal file
65
src/main.zig
Normal file
|
@ -0,0 +1,65 @@
|
|||
const lib = @import("NouVeL_lib");
|
||||
const c = @cImport({
|
||||
@cDefine("SDL_DISABLE_OLD_NAMES", {});
|
||||
@cInclude("SDL3/SDL.h");
|
||||
@cInclude("SDL3/SDL_revision.h");
|
||||
@cDefine("SDL_MAIN_HANDLED", {});
|
||||
@cInclude("SDL3/SDL_main.h");
|
||||
});
|
||||
|
||||
|
||||
pub fn main() u8 {
|
||||
c.SDL_SetMainReady();
|
||||
const status = c.SDL_EnterAppMainCallbacks(0, null, init, iterate, on_event, quit);
|
||||
|
||||
return @bitCast(@as(i8, @truncate(status)));
|
||||
}
|
||||
|
||||
var window: ?*c.SDL_Window = null;
|
||||
var renderer: ?*c.SDL_Renderer = null;
|
||||
|
||||
fn init(appstate: ?*?*anyopaque, argc: c_int, argv: ?[*:null]?[*:0]u8) callconv(.c) c.SDL_AppResult {
|
||||
_ = appstate;
|
||||
_ = argc;
|
||||
_ = argv;
|
||||
_ = c.SDL_SetAppMetadata("Example", "1.0", "com.example.what");
|
||||
|
||||
if (!c.SDL_Init(c.SDL_INIT_VIDEO)) {
|
||||
c.SDL_Log("Couldn't initialize SDL: %s", c.SDL_GetError());
|
||||
return c.SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
if (!c.SDL_CreateWindowAndRenderer("zig sdl test", 1280, 720, 0, &window, &renderer)) {
|
||||
c.SDL_Log("Couldn't create window/renderer: %s", c.SDL_GetError());
|
||||
return c.SDL_APP_FAILURE;
|
||||
}
|
||||
return c.SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
fn on_event(appstate: ?*anyopaque, event: ?*c.SDL_Event) callconv(.c) c.SDL_AppResult {
|
||||
_ = appstate;
|
||||
if (event.?.type == c.SDL_EVENT_QUIT) {
|
||||
return c.SDL_APP_SUCCESS;
|
||||
}
|
||||
return c.SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
fn iterate(appstate: ?*anyopaque) callconv(.c) c.SDL_AppResult {
|
||||
_ = appstate;
|
||||
|
||||
_ = c.SDL_SetRenderDrawColor(renderer, 0, 0, 0, c.SDL_ALPHA_OPAQUE);
|
||||
_ = c.SDL_RenderClear(renderer);
|
||||
|
||||
|
||||
_ = c.SDL_SetRenderScale(renderer, 4.0, 4.0);
|
||||
_ = c.SDL_SetRenderDrawColor(renderer, 255, 255, 255, c.SDL_ALPHA_OPAQUE);
|
||||
_ = c.SDL_RenderDebugText(renderer, 50, 50, "asdfasdf");
|
||||
|
||||
_ = c.SDL_RenderPresent(renderer);
|
||||
return c.SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
fn quit(appstate: ?*anyopaque, result: c.SDL_AppResult) callconv(.c) void {
|
||||
_ = appstate;
|
||||
_ = result;
|
||||
}
|
43
src/parser.zig
Normal file
43
src/parser.zig
Normal file
|
@ -0,0 +1,43 @@
|
|||
const Object = union(enum) {
|
||||
symbol: []u8,
|
||||
number: f32,
|
||||
string: []u8,
|
||||
array: []Object,
|
||||
};
|
||||
|
||||
const numeric = "1234567890";
|
||||
const decimal_dot = ".";
|
||||
const negative = "-";
|
||||
const alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
const array_open = "[";
|
||||
const array_close = "]";
|
||||
const array_delim = ",";
|
||||
const group_open = "(";
|
||||
const group_close = ")";
|
||||
const quote = "\\";
|
||||
const comment_begin = "#";
|
||||
const dialogue_open = "<<-";
|
||||
const dialogue_close = "->>";
|
||||
const begin = "BEGIN";
|
||||
const end = "END";
|
||||
const symbol = alpha ++ numeric ++ "_";
|
||||
const special_symbols = .{ "+", "-", "*", "/", "=?", ">?", "<?", "<=?", ">=?" };
|
||||
const ws = " \t\r\n"; // there was also \v and \f in C++
|
||||
const separator = ws ++ array_open ++ array_close ++ group_open ++ group_close ++ array_delim ++ comment_begin;
|
||||
const newline = "\n";
|
||||
const escaped = "\\\"";
|
||||
const escape = "\\";
|
||||
|
||||
// Dialogue mode matches
|
||||
const markup_open = "[";
|
||||
const markup_close = "]";
|
||||
const speaker_open = "[";
|
||||
const speaker_close = "]";
|
||||
const markup_text_open = "{";
|
||||
const markup_text_close = "}";
|
||||
const template_ind = "$";
|
||||
const template_open = "{";
|
||||
const template_close = "}";
|
||||
|
||||
const command_escape = "*!";
|
||||
const dialogue_escaped_single = escape ++ markup_open ++ markup_close ++ markup_text_open ++ markup_text_close ++ template_ind;
|
Loading…
Add table
Add a link
Reference in a new issue