项目作者: nfisher1226

项目描述 :
Zig wrappers and convenience functions around the Vte and Gtk+ libraries
高级语言: Zig
项目地址: git://github.com/nfisher1226/zig-vte.git
创建时间: 2021-06-21T01:43:32Z
项目社区:https://github.com/nfisher1226/zig-vte

开源协议:

下载


zig-gtk3

This package contains some convenience functions and wrappers around the C api
of both the Gtk+ and Vte libraries for developing Gui applications using Zig.

Usage

We track zig-master, so you will need the current master compiler. In your
build.zig file, add the package path:

  1. const exe = b.addExecutable("exe-name", "path-to-source.zig");
  2. exe.addPackagePath("zig-gtk3", "path/to/zig-vte/lib.zig");
  3. exe.linkLibC();
  4. exe.linkSystemLibrary("gtk+-3.0");
  5. exe.linkSystemLibrary("vte-2.91");

The Gtk wrappers are namespaced to gtk, the C functions to c, and Vte to vte.

  1. const GTK = @import("zig-vte");
  2. const c = GTK.c;
  3. const gtk = GTK.gtk;
  4. const vte = GTK.vte;
  5. const std = @import("std");
  6. const Gui = struct {
  7. window: gtk.Window,
  8. term: vte.Terminal,
  9. fn init(app: *c.GtkApplication) Gui {
  10. ...

There are several gtk examples and one vte example in the examples subdirectory.

Rationale

It is entirely possible to call C functions directly from Zig. However, Zig’s
translate-c function, which is used to import C code into Zig, is still somewhat
immature and tends to fail with heavily macro dependent code. This happens for
certain parts of Gtk+ that make working around it quite difficult.

Additionally, the C Api to Gtk (and Vte), due to limitations of the language, can
be incredibly verbose as well as quite clumsy at times. A better Api is both
possible and desireable in a language such as Zig.