~mil/mepo

64ad18520e6b4d5d6412b39f353a9508f32e554a — Miles Alan 2 years ago 691c05c
Add specs for all mepolang fns to ensure valid params passed/typechecked
M src/api/bind_button.zig => src/api/bind_button.zig +2 -2
@@ 5,8 5,8 @@ const sdl = @import("../sdlshim.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = types.MepoFnSpec{
    .args = (&[_]types.MepoArgTag{.Number, .Text, .Text})[0..],
pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Text, .Text })[0..],
};

pub fn f_bind_button(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {

M src/api/bind_click.zig => src/api/bind_click.zig +6 -0
@@ 3,8 3,14 @@ const types = @import("../types.zig");
const std = @import("std");
const sdl = @import("../sdlshim.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number, .Text })[0..],
};

pub fn f_bind_click(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const button = @floatToInt(u8, args[0].Number);
    const clicks = @floatToInt(i8, args[1].Number);
    const expression = args[2].Text;

M src/api/bind_gesture.zig => src/api/bind_gesture.zig +6 -0
@@ 3,8 3,14 @@ const types = @import("../types.zig");
const std = @import("std");
const sdl = @import("../sdlshim.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Text, .Number, .Number, .Text })[0..],
};

pub fn f_bind_gesture(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const action: types.GestureInputAction = if (std.mem.eql(u8, args[0].Text, "pan")) .Pan else .Rotate;
    const fingers: u8 = @floatToInt(u8, args[1].Number);
    const direction: types.GestureInputDirection = if (args[2].Number == 1) .In else .Out;

M src/api/bind_key.zig => src/api/bind_key.zig +6 -0
@@ 3,8 3,14 @@ const types = @import("../types.zig");
const std = @import("std");
const sdl = @import("../sdlshim.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Text, .Text, .Text })[0..],
};

pub fn f_bind_key(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const modifier = args[0].Text;
    const key = args[1].Text;
    const expression = args[2].Text;

M src/api/bind_signal.zig => src/api/bind_signal.zig +6 -0
@@ 3,8 3,14 @@ const types = @import("../types.zig");
const std = @import("std");
const sdl = @import("../sdlshim.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Text, .Text })[0..],
};

pub fn f_bind_signal(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const signo = args[0].Text;
    const expression = args[1].Text;
    try bind_signal(mepo, signo, expression);

M src/api/cache_dlbbox.zig => src/api/cache_dlbbox.zig +6 -0
@@ 4,9 4,15 @@ const types = @import("../types.zig");
const std = @import("std");
const utilconversion = @import("../util/utilconversion.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");
const config = @import("../config.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number, .Number, .Number, .Number, .Number })[0..],
};

pub fn f_cache_dlbbox(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const a_lat = args[0].Number;
    const a_lon = args[1].Number;
    const b_lat = args[2].Number;

M src/api/cache_dlradius.zig => src/api/cache_dlradius.zig +6 -0
@@ 4,9 4,15 @@ const types = @import("../types.zig");
const std = @import("std");
const utilconversion = @import("../util/utilconversion.zig");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");
const config = @import("../config.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number, .Number, .Number, .Number })[0..],
};

pub fn f_cache_dlradius(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const lat = args[0].Number;
    const lon = args[1].Number;
    const zoom_min = @floatToInt(i32, args[2].Number);

M src/api/center_on_coords.zig => src/api/center_on_coords.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number })[0..],
};

pub fn f_center_on_coords(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const lat = args[0].Number;
    const lon = args[1].Number;
    center_on_coords(mepo, lat, lon);

M src/api/fileload.zig => src/api/fileload.zig +6 -0
@@ 2,8 2,14 @@ const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilfile = @import("../util/utilfile.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{.Text})[0..],
};

pub fn f_fileload(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const filepath = args[0].Text;
    try fileload(mepo, filepath);
}

M src/api/move_relative.zig => src/api/move_relative.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number })[0..],
};

pub fn f_move_relative(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const rel_x = @floatToInt(i32, args[0].Number);
    const rel_y = @floatToInt(i32, args[1].Number);
    move_relative(mepo, rel_x, rel_y);

M src/api/pin_add.zig => src/api/pin_add.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number, .Number, .Number, .Text, .Text })[0..],
};

pub fn f_pin_add(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const group = @floatToInt(i32, args[0].Number);
    const is_structural = args[1].Number == 1;
    const lat = args[2].Number;

M src/api/pin_cycle.zig => src/api/pin_cycle.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Number })[0..],
};

pub fn f_pin_cycle(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const viewport_only = @floatToInt(i32, args[0].Number) == 1;
    const delta = @floatToInt(i32, args[1].Number);
    try pin_cycle(mepo, viewport_only, delta);

M src/api/pin_delete.zig => src/api/pin_delete.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{.Text})[0..],
};

pub fn f_pin_delete(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const handle = args[0].Text;
    try pin_delete(mepo, handle);
}

M src/api/pin_groupprefset.zig => src/api/pin_groupprefset.zig +6 -0
@@ 2,8 2,14 @@ const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const pin_cycle = @import("pin_cycle.zig").pin_cycle;
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Text })[0..],
};

pub fn f_pin_groupprefset(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const group_number = @floatToInt(usize, args[0].Number);
    const prefname = args[1].Text;


M src/api/pin_meta.zig => src/api/pin_meta.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Number, .Text, .Text, .Text })[0..],
};

pub fn f_pin_meta(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const group = @floatToInt(i32, args[0].Number);
    const handle = args[1].Text;
    const key = args[2].Text;

M src/api/prefinc.zig => src/api/prefinc.zig +6 -0
@@ 2,8 2,14 @@ const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{ .Text, .Number })[0..],
};

pub fn f_prefinc(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const name = args[0].Text;
    const delta = args[1].Number;


M src/api/prefset.zig => src/api/prefset.zig +3 -0
@@ 3,6 3,9 @@ const types = @import("../types.zig");
const std = @import("std");
const utildbg = @import("../util/utildbg.zig");

// TODO: dynamic usage of mepolang 2nd arg..
//       should there be prefset_number / prefset_text?

pub fn f_prefset(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    const name = args[0].Text;


M src/api/preftoggle.zig => src/api/preftoggle.zig +6 -0
@@ 2,8 2,14 @@ const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utildbg = @import("../util/utildbg.zig");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{.Text})[0..],
};

pub fn f_preftoggle(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const name = args[0].Text;

    for (&[_]struct { prop: []const u8, ptr: *bool }{

M src/api/shellpipe.zig => src/api/shellpipe.zig +6 -0
@@ 5,9 5,15 @@ const utilconversion = @import("../util/utilconversion.zig");
const utilplatform = @import("../util/utilplatform.zig");
const utildbg = @import("../util/utildbg.zig");
const utilsdl = @import("../util/utilsdl.zig");
const utilarg = @import("../util/utilarg.zig");
const sdl = @import("../sdlshim.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{.Text})[0..],
};

pub fn f_shellpipe(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const cmd = args[0].Text;
    try shellpipe(mepo, cmd);
}

M src/api/zoom_relative.zig => src/api/zoom_relative.zig +6 -0
@@ 1,8 1,14 @@
const Mepo = @import("../Mepo.zig");
const types = @import("../types.zig");
const std = @import("std");
const utilarg = @import("../util/utilarg.zig");

pub const spec = .{
    .args = (&[_]types.MepoArgTag{.Number})[0..],
};

pub fn f_zoom_relative(mepo: *Mepo, args: [types.MepoFnNargs]types.MepoArg) !void {
    _ = utilarg.validate_args(spec, args) catch |e| return e;
    const relative = @floatToInt(i32, args[0].Number);
    zoom_relative(mepo, relative);
}