Skip to content

zoop

zoop.Fn

zig
pub fn Fn(comptime T: type) type

Function: Calculate all Method of T, refer to Fn principle

parameter:

Returns: A tuple containing all the methods returned by calling the Fn function of T and all its superclasses.

example:

zig
const SomeClass = struct {
    pub const extends = .{BaseClass}
    pub usingnamespace zoop.Fn(@This());
}

zoop.Api

zig
pub fn Api(comptime I: type) type

Function: Calculate all ApiMethod of I, refer to Api principle

parameter:

Returns: A tuple containing all ApiMethods returned by calling the Api functions of I and all its parent interfaces.

example:

zig
pub const ISome = struct {
    pub const extends = .{IBase}
    pub usingnamespace zoop.Api(@This());
}

zoop.DefVtable

zig
pub fn DefVtable(comptime I: type, comptime APIs: type) type

Function: Calculate the Vtable of I

parameter:

  • I: Interface
  • APIs: a zig struct containing pointers to the function interfaces defined by I

Returns: a zig struct containing pointer data of the function interface defined by I and its parent interface

example:

zig
pub const ISome = struct {
    pub const extends = .{IBase}
    pub const Vtable = zoop.DefVtable(@This(), struct {
        someFunc1: *fn const(*anyopaque) void,
        someFunc2: *fn const(*anyopaque) void,
    });
}

zoop.Mixin

zig
pub fn Mixin(comptime T: type) type

Function: Calculate the Mixin data type of T, refer to Mixin design

parameter:

Returns: the Mixin data type of T

example:

zig
const SomeClass = struct {
    mixin: zoop.Mixin(@This()),
}

zoop.Method

zig
pub const Method = tuple.Init;

Function: Same as tuple.Init

example:

zig
pub const Some = struct {
    pub fn Fn(comptime T: type) type {
        return zoop.Method(.{
            struct {
                pub fn someFunc(this: *T) void { _ = this; }
            },
        });
    }
}

zoop.Interfaces

zig
pub fn Interfaces(comptime T: type) type

Function: Get all interfaces implemented/inherited by T (excluding zoop.IObject)

parameter:

Returns: A tuple containing all interfaces implemented/inherited by T (excluding zoop.IObject)

zoop.SuperClasses

zig
pub fn SuperClasses(comptime T: type) type

Function: Get all direct or indirect parent classes of T

parameter:

Returns: a tuple containing all direct or indirect parent classes of T

zoop.DirectSuperClasses

zig
pub fn DirectSuperClasses(comptime T: type) type

Function: Get a tuple containing all direct parent classes of T

parameter:

Returns: a tuple containing all direct superclasses of T

zoop.SuperRoute

zig
pub fn SuperRoute(comptime T: type, comptime Target: type) type

Function: Calculate all classes from T to Target in the inheritance tree

parameter:

  • T: Starting point Class
  • Target: endpoint [Class] (principle#term)

Returns: a tuple containing all the classes from T to Target in the inheritance tree (the result contains Target but not T)

zoop.typeId

zig
pub fn typeId(any: anytype) u32

Function:Get the typeid of any

parameter:

Returns: typeid for any

zoop.typeInfo

zig
pub fn typeInfo(any: anytype) *const TypeInfo

Function: Get the TypeInfo of any

parameter:

Returns: TypeInfo for any

example:

zig
const t = std.testing;
var obj = try Some.new(t.allocator);
defer obj.destroy();
var iface = o.as(zoop.IObject).?;
try t.expect(zoop.typeInfo(obj) == zoop.typeInfo(iface));
try t.expect(zoop.typeInfo(obj) == zoop.typeInfo(Some));

zoop.metaInfo

zig
pub fn metaInfo(any: anytype) *const MetaInfo

Function: Get the MetaInfo of any

parameter:

Returns: MetaInfo of any

example:

zig
const t = std.testing;
var obj = try Some.new(t.allocator);
defer obj.destroy();
var iface = o.as(zoop.IObject).?;
try t.expect(zoop.metaInfo(obj) == zoop.metaInfo(iface));

zoop.isRootPtr

zig
pub inline fn isRootPtr(ptr: anytype) bool {

Function: Determine whether ptr is equal to rootptr

parameter:

  • ptr: Class instance pointer

Returns: ptr is equal to rootptr returns true otherwise false

example:

zig
const t = std.testing;
var sub = try SubClass.new(t.allocator);
defer sub.destroy();
var base = sub.cast(BaseClass);
try t.expect(zoop.isRootPtr(sub) == true);
try t.expect(zoop.isRootPtr(base) == false);

zoop.isInterface

zig
pub inline fn isInterface(comptime T: type) bool

Function: Determine whether T is an Interface

parameter:

  • T: any zig type

Returns: T is Interface returns true otherwise false

zoop.isClass

zig
pub inline fn isClass(comptime T: type) bool

Function: Determine whether T is Class

parameter:

  • T: any zig type

Returns: T is Class returns true otherwise false

zoop.mixinName

zig
pub fn mixinName(comptime T: type) []const u8

Function: Calculate the name of T in MixinData

parameter:

Returns: The name of T in MixinData

example:

zig
const t = std.testing;
try t.expectEqualStrings(zoop.mixinName(mymod.SomeClass), "mymod_SomeClass");

zoop.mixinName0

zig
pub fn mixinName0(comptime T: type) [:0]const u8

Function: Same as mixinName, except that it returns a string ending with 0.

zoop.setHook

zig
pub const HookFunc = *const fn (obj: IObject) void;
pub fn setHook(new_hook: ?HookFunc, destroy_hook: ?HookFunc) void

Function: Set the hook function for monitoring object creation and destruction

parameter:

  • new_hook: object creation hook function, passing in null will clear the previously set hook function
  • destroy_hook: object destruction hook function, passing in null will clear the previously set hook function

Released under the MIT License