Meta type ‣ isArgumentClampedArray(T, arg_index) ᴾᴴᴾ - chung-leong/zigar GitHub Wiki

JavaScript | PHP


Determine whether an argument to a callback function should be a U8ClampedArray.

Usage:

const std = @import("std");

const Callback = fn ([]const u8) void;
pub fn call(cb: *const Callback) void {
    cb("hello");
}

pub const @"meta(zigar)" = struct {
    pub fn isArgumentClampedArray(comptime T: type, comptime arg_index: usize) bool {
        return T == Callback and arg_index == 0;
    }
};
<?php

$m = zigar_use(__DIR__ . '/meta-type-clamped-array-example-3.zig');

$m->call(function($arg) {
    print_r($arg);
});
Uint8ClampedArray Object
(
    [ITEMS](/chung-leong/zigar/wiki/ITEMS) => Array
        (
            [0] => 104
            [1] => 101
            [2] => 108
            [3] => 108
            [4] => 111
        )

    [buffer] => ArrayBuffer Object
        (
            [byteLength] => 5
            [detached] => 
            [readOnly] => 1
        )

    [byteLength] => 5
    [byteOffset] => 0
    [length] => 5
)

Arguments:

  • T - Callback function type
  • arg_index - Index of argument in question

Meta types | Clamped array