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

JavaScript | PHP


Determine whether a struct/union field should be a typed array.

Usage:

const std = @import("std");

const Struct = struct {
    field: []const u8 = "hello",
};
pub const structure: Struct = .{};

pub const @"meta(zigar)" = struct {
    pub fn isFieldTypedArray(comptime T: type, comptime name: std.meta.FieldEnum(T)) bool {
        return T == Struct and name == .field;
    }
};
<?php

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

print_r($m->structure->field);
Uint8Array 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 - Struct/union type in question
  • name - Name of the field represented by an enum

Meta types | Typed array