{"id":13568076,"url":"https://github.com/greenfork/jzignet","last_synced_at":"2025-04-04T04:30:40.257Z","repository":{"id":130786438,"uuid":"430119589","full_name":"greenfork/jzignet","owner":"greenfork","description":"Zig library to connect Janet and Zig together","archived":false,"fork":false,"pushed_at":"2025-02-13T19:44:27.000Z","size":3540,"stargazers_count":55,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T20:45:01.904Z","etag":null,"topics":["janet","zig","zig-package"],"latest_commit_sha":null,"homepage":"https://git.sr.ht/~greenfork/jzignet","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greenfork.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-20T14:06:55.000Z","updated_at":"2025-03-07T18:38:11.000Z","dependencies_parsed_at":"2024-01-14T03:46:23.349Z","dependency_job_id":"7a4e0786-9641-4872-9194-40a0db1a32f1","html_url":"https://github.com/greenfork/jzignet","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfork%2Fjzignet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfork%2Fjzignet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfork%2Fjzignet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greenfork%2Fjzignet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greenfork","download_url":"https://codeload.github.com/greenfork/jzignet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247123071,"owners_count":20887259,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["janet","zig","zig-package"],"created_at":"2024-08-01T14:00:19.672Z","updated_at":"2025-04-04T04:30:40.242Z","avatar_url":"https://github.com/greenfork.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Jzignet\n\n[Zig](https://ziglang.org/) is a general-purpose programming language and\ntoolchain for maintaining robust, optimal, and reusable software.\n\n[Janet](https://janet-lang.org/) is a functional and imperative programming\nlanguage and bytecode interpreter. It is a lisp-like language, but lists are\nreplaced by other data structures (arrays, tables (hash table), struct\n(immutable hash table), tuples). The language also supports bridging to native\ncode written in C, meta-programming with macros, and bytecode assembly.\n\n[Jzignet](https://git.sr.ht/~greenfork/jzignet) - Zig library to connect Janet\nand Zig together.\n\nYou can:\n* Embed Janet programs into Zig\n* Write Janet modules in Zig\n* Write bindings in Zig for a C library to be used as a Janet module\n\nWhy use these bindings, besides obvious reasons such as connecting together two\nwonderful languages:\n* You don't need to care about conversion between Zig and C. But you have full\n  access to C internals if you need to.\n* Plenty of tests which are great examples and guarantee minimal regressions\n  when updating.\n* Idiomatic Zig code - everything is typed, names are properly cased,\n  operations on types use methods instead of prefixed global functions.\n\nCurrently supported versions:\n* Zig 0.13.0\n* Janet 1.37.1\n\nRepository is available at [sourcehut](https://git.sr.ht/~greenfork/jzignet)\nand at [GitHub](https://github.com/greenfork/jzignet).\n\n## How to use\n\nIf you want to just start using it, jump to the examples. Copy them or look\nat the source code, it is heavily commented.\n\n* [Embed Janet into Zig](examples/embed_janet.zig) --\n  run this example with `zig build run-embed_janet`.  \n  For a more in-depth overview of this use case you can take a look at\n  @iacore's [blog post](https://www.1a-insec.net/blog/16-buy-janet-get-gc-free/)\n  as well as the [example repository](https://git.envs.net/iacore/janet-zig-test).\n\nWARNING: examples are currently **not working**:\n\n* [Write Janet module in Zig](examples/zig_module) -- the template is broken\n  and needs some investigation on how to fix it.\n\nWrite bindings in Zig for a C library to be used as a Janet module - this\nis very close to \"Write Janet module in Zig\" example, you just need to\nknow how to wrap a C library in Zig, this repository is a perfect example\nfor this.\n\n## How to include as a dependency (with zon)\n\n1. Create a file named `build.zig.zon` with the following content. Put the\n   correct version for tar archive, and change the `.hash` value when you get\n   and error.\n\n```zig\n.{\n    .name = \"janet-zig-test\",\n    .version = \"0.0.1\",\n    .dependencies = .{\n        .jzignet = .{\n            .url = \"https://git.sr.ht/~greenfork/jzignet/archive/0.7.2.tar.gz\",\n            .hash = \"122087fa45b016bd8ce5fbadd17ef2bd84cd1389119edd3c345486870032ea2b7217\",\n        },\n    },\n}\n```\n\n2. Add this to `build.zig`.\n\n```zig\n    const jzignet = b.dependency(\"jzignet\", .{ .target=target, .optimize=optimize });\n\n    // your executable defined here\n    // const exe = ...;\n\n    exe.addModule(\"jzignet\", jzignet.module(\"jzignet\"));\n    exe.linkLibrary(jzignet.artifact(\"jzignet\"));\n```\n\n3. Use in your Zig code\n\n```zig\nconst jzignet = @import(\"jzignet\");\n```\n\n## How to include as a dependency (with git submodule)\n\nCurrently you can include jzignet as a git submodule. Janet is bundled as\na single C source amalgamation file and is compiled directly into this\nlibrary.\n\n1. Include git submodule into your library, assuming further that `libpath` is\n   the directory where this library is installed\n\n```shell\ngit submodule add https://github.com/greenfork/jzignet libpath\n```\n\n2. Include the library in `build.zig`\n\n```zig\n    const jzignet = b.anonymousDependency(\"lib/jzignet\", @import(\"lib/jzignet/build.zig\"), .{});\n\n    // your executable defined here\n    // const exe = ...;\n\n    exe.addModule(\"jzignet\", jzignet.module(\"jzignet\"));\n    exe.linkLibrary(jzignet.artifact(\"jzignet\"));\n```\n\n3. Use in your Zig code\n\n```zig\nconst jzignet = @import(\"jzignet\");\n```\n\n## Differences with C API\n\n### Naming\n* `janet_` prefix is mostly not present.\n* Every type is a Zig struct and corresponding functions are called as\n  methods, for example, `janet_table_get(table, key)` becomes `table.get(key)`.\n* **All** bindings have idiomatic Zig naming even when Janet uses different\n  ones, for example `arity` and `fixarity` are `arity` and `fixArity` in Zig.\n* Functions like `janet_table` are available as `Table.init`, please consult\n  the source code for that.\n\n### Semantics\n* Function return types return error sets as well as optional values where it\n  makes sense to do so, for example, `table.get` returns `?Janet` and `pcall`\n  returns `Signal.Error!void`.\n* All types are wrapped into structs. Most of the types support this natively\n  since they are structs in C too, others (Tuple, Struct, String, Keyword,\n  Symbol) cannot be represented as structs directly and they are wrappers\n  with a `ptr` or `slice` field containing the original value.\n* All functions that have a type at the end, for example, `janet_get_number`,\n  instead use this signature: `get(comptime T: type, ...)`. Currently these\n  functions exist: `get`, `opt`, `wrap`, `Janet.unwrap`.\n* When you need to supply a pointer to the array and a length in the C version,\n  in Zig version you need to supply just a slice since it has both the pointer\n  and the length, so it's one parameter instead of two. For example,\n  ```c\n  int janet_dobytes(JanetTable *env, const uint8_t *bytes, int32_t len, const char *sourcePath, Janet *out);\n  ```\n  \n  becomes\n  ```zig\n  pub fn doBytes(env: *Environment, bytes: []const u8, source_path: [:0]const u8) !Janet\n  ```\n* Abstracts are fully typed, no *void pointers to @ptrCast. Take a look at\n  tests for examples with abstracts, they are generally reworked to make\n  them easier to use.\n* All functions returning `Signal` instead return `void` on `OK` and return\n  error otherwise with the specified signal, signature is `Signal.Error!void`.\n* `doString` and `doBytes` are aliases and return `!Janet` directly instead of\n  accepting a reference for the return value.\n* `string`, `keyword`, `symbol`, `nil` top-level functions are the only ones to\n  create these types and they do what you want.\n* `Environment` type introduced which is internally a `Table` but allows\n  conceptually different operations such as defining values and executing code.\n\n## Completeness\n\nBindings are not complete 100% but all the generally useful things are there.\nIf you need any specific part of the API, feel free to contribute or just\nask (and you shall receive).\n\n## Q'n'A\n\nQ: What's with the name?\n\nA: \"janet\".replace(\"a\", \"zig\")\n\nQ: I hate that name.\n\nA: Yes, I know.\n\n## License\n\nMIT, see LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenfork%2Fjzignet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreenfork%2Fjzignet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreenfork%2Fjzignet/lists"}