{"id":24390272,"url":"https://github.com/sackosoft/zig-luajit","last_synced_at":"2025-04-19T20:26:58.060Z","repository":{"id":273135328,"uuid":"916702816","full_name":"sackosoft/zig-luajit","owner":"sackosoft","description":"Run Lua code in Zig apps! A package providing Zig language bindings to LuaJIT. ","archived":false,"fork":false,"pushed_at":"2025-03-12T00:58:06.000Z","size":324,"stargazers_count":39,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T12:51:26.412Z","etag":null,"topics":["bindings","language-bindings","lua","lua-bindings","luajit","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sackosoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2025-01-14T15:57:31.000Z","updated_at":"2025-03-24T06:58:43.000Z","dependencies_parsed_at":"2025-01-18T23:21:33.734Z","dependency_job_id":"9402e554-825e-401b-a04e-5304cda4f38c","html_url":"https://github.com/sackosoft/zig-luajit","commit_stats":null,"previous_names":["sackosoft/zig-luajit"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sackosoft%2Fzig-luajit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sackosoft%2Fzig-luajit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sackosoft%2Fzig-luajit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sackosoft%2Fzig-luajit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sackosoft","download_url":"https://codeload.github.com/sackosoft/zig-luajit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249793889,"owners_count":21326624,"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":["bindings","language-bindings","lua","lua-bindings","luajit","zig","zig-package"],"created_at":"2025-01-19T16:16:29.992Z","updated_at":"2025-04-19T20:26:58.039Z","avatar_url":"https://github.com/sackosoft.png","language":"Zig","readme":"\u003cdiv align=\"center\"\u003e\n\n# zig-luajit\n\n**Zig ⚡ language bindings for the [LuaJIT](https://luajit.org/) C API. Use `zig-luajit` to run [Lua scripts](https://www.lua.org/) within a Zig application.**\n\n![Ubuntu Regression Tests Badge](https://img.shields.io/github/actions/workflow/status/sackosoft/zig-luajit/tests-ubuntu.yml?label=Tests%20Ubuntu)\n![Windows Regression Tests Badge](https://img.shields.io/github/actions/workflow/status/sackosoft/zig-luajit/tests-windows.yml?label=Tests%20Windows)\n![GitHub License](https://img.shields.io/github/license/sackosoft/zig-luajit)\n\n\u003c!--\nTODO: Capture attention with a visualization, diagram, demo or other visual placeholder here.\n![Placeholder]()\n--\u003e\n\n\u003c/div\u003e\n\n## About\n\nThe goal of the `zig-luajit` project is to provide the most idiomatic Zig language bindings for the LuaJIT C API and C\nAPI Auxilary Library. Additionally the `zig-luajit` project emphasizes safety by making liberal use of runtime safety\nchecks in `Debug` and `ReleaseSafe` builds and provides full test coverage of the API.\n\n## Zig Version\n\nThe `main` branch targets recent builds of Zig's `master` branch (last tested with Zig `0.14.0`).\n\n## Installation \u0026 Usage\n\nIt is recommended that you install `zig-luajit` using `zig fetch`. This will add a `luajit` dependency to your `build.zig.zon` file.\n\n```bash\nzig fetch --save=luajit git+https://github.com/sackosoft/zig-luajit\n```\n\nNext, in order for your code to import `zig-luajit`, you'll need to update your `build.zig` to do the following:\n\n1. get a reference the `zig-luajit` dependency.\n2. get a reference to the `luajit` module, which contains the core Zig language bindings for LuaJIT.\n3. add the module as an import to your executable or library.\n\n```zig\n// (1) Get a reference to the `zig fetch`'ed dependency\nconst luajit_dep = b.dependency(\"luajit\", .{\n    .target = target,\n    .optimize = optimize,\n});\n\n// (2) Get a reference to the language bindings module.\nconst luajit = luajit_dep.module(\"luajit\");\n\n// Set up your library or executable\nconst lib = // ...\nconst exe = // ...\n\n// (3) Add the module as an import to your executable or library.\nmy_exe.root_module.addImport(\"luajit\", luajit);\nmy_lib.root_module.addImport(\"luajit\", luajit);\n```\n\nNow the code in your library or exectable can import and use the LuaJIT Zig API!\n\n```zig\nconst luajit = @import(\"luajit\");\nconst Lua = luajit.Lua;\n\nvar gpa = std.heap.GeneralPurposeAllocator(.{}){};\nconst lua = Lua.init(gpa.allocator());\ndefer lua.deinit();\n\nlua.openBaseLib();\nlua.doString(\n    \\\\ print(\"Hello, world!\")\n);\n```\n\n## Examples\n\nSome examples are provided in [examples/](./examples/) to aid users in learning to use `zig-luajit`. These\nsmall self-contained applications should always be working, please create an issue if they do not work for\nyou.\n\n\n## Language Binding Coverage Progress\n\n| API                         | Support                               |\n|-----------------------------|---------------------------------------|\n| Lua C API (`lua_*`)         | 🎉 100% coverage\u003csup\u003e†\u003c/sup\u003e (92/92)  |\n| Auxilary Library (`luaL_*`) | 🤩 100% coverage (48/48)              |\n| Debug API (`lua_Debug`)     | 🥳 100% coverage (12/12)              |\n| LuaJIT Extensions           | *No plans to implement.*              |\n\n*†: Coroutine yield/resume is not yet part of the public `zig-luajit` Zig API, see [#6][ISSUE-6].*\n\n## Coverage and Compatibility\n\nThis section describes the current status of Zig language bindings (\"the Zig API\").\n\n* ☑️ Fully Supported: Test coverage and runtime safety checks enabled in `Debug` or `ReleaseSafe` builds.\n* ➖ Internal: Used internally and intentionally hidden from the Zig API.\n* 🆖 Superseded: Has no direct Zig equivalent, but the functionality is provided by a different part of the Zig API.\n* 📢 Renamed: Renamed in a non-obvious way from the C API. Renaming is avoided but done in cases deemed required:\n    1. to conform to Zig idioms or patterns, such as the `init()` / `deinit()` pattern.\n    1. to avoid conflicts with Zig language keywords, such as the Zig `error` keyword.\n    1. to show that the Zig API has slightly different behavior than the C API, such as using `lua.setAllocator()`\n       instead of `lua.setAllocF()`; since the Zig API uses `std.mem.Allocator` instead of allocation functions.\n    1. to improve the clarity, discoverability or consistency of the symbol in the overall API surface.\n\n\n### Core C API Coverage (`lua_`)\n\n| C Type Definition          | Available in `zig-luajit`                                           |\n|----------------------------|---------------------------------------------------------------------|\n| `lua_State`                | ☑️ `Lua`                                                             |\n| `lua_Alloc`                | ➖ Hidden, please use `lua.setAllocator()` and `lua.getAllocator()` |\n| `lua_CFunction`            | ☑️ `lua.CFunction`                                                   |\n| `lua_Integer`              | ☑️ `Lua.Integer`                                                     |\n| `lua_Number`               | ☑️ `Lua.Number`                                                      |\n| `lua_Reader`               | ☑️ [`std.io.AnyReader`][ZIG-DOC-ANYREADER]                           |\n| `lua_Writer`               | ☑️ [`std.io.AnyWriter`][ZIG-DOC-ANYWRITER]                           |\n\n[ZIG-DOC-ANYREADER]: https://ziglang.org/documentation/master/std/#std.io.AnyReader\n[ZIG-DOC-ANYWRITER]: https://ziglang.org/documentation/master/std/#std.io.AnyWriter\n\n| C API Symbols              | Available in `zig-luajit`           |\n|----------------------------|-------------------------------------|\n| `lua_atpanic`              | ☑️ `lua.atPanic()`                   |\n| `lua_call`                 | ☑️ `lua.call()`                      |\n| `lua_pcall`                | ☑️📢 `lua.callProtected()`           |\n| `lua_cpcall`               | ☑️📢 `lua.callProtectedC()`          |\n| `lua_checkstack`           | ☑️ `lua.checkStack()`                |\n| `lua_close`                | ☑️📢 `lua.deinit()`                  |\n| `lua_concat`               | ☑️ `lua.concat()`                    |\n| `lua_createtable`          | ☑️ `lua.createTable()`               |\n| `lua_dump`                 | ☑️ `lua.dump()`                      |\n| `lua_equal`                | ☑️ `lua.equal()`                     |\n| `lua_error`                | ☑️📢 `lua.raiseError()`              |\n| `lua_gc`                   | ☑️ `lua.gc()` + `lua.gcIsRunning()`  |\n| `lua_getallocf`            | ☑️📢 `lua.getAllocator()`            |\n| `lua_getfenv`              | ☑️📢 `lua.getEnvironment()`          |\n| `lua_getfield`             | ☑️ `lua.getField()`                  |\n| `lua_getglobal`            | ☑️ `lua.getGlobal()`                 |\n| `lua_getmetatable`         | ☑️ `lua.getMetatable()`              |\n| `lua_gettable`             | ☑️ `lua.getTable()`                  |\n| `lua_gettop`               | ☑️ `lua.getTop()`                    |\n| `lua_insert`               | ☑️ `lua.insert()`                    |\n| `lua_isboolean`            | ☑️ `lua.isBoolean()`                 |\n| `lua_iscfunction`          | ☑️ `lua.isCFunction()`               |\n| `lua_isfunction`           | ☑️ `lua.isFunction()`                |\n| `lua_islightuserdata`      | ☑️ `lua.isLightUserdata()`           |\n| `lua_isnil`                | ☑️ `lua.isNil()`                     |\n| `lua_isnone`               | ☑️ `lua.isNone()`                    |\n| `lua_isnoneornil`          | ☑️ `lua.isNilOrNone()`               |\n| `lua_isnumber`             | ☑️ `lua.isNumber()`                  |\n| `lua_isstring`             | ☑️ `lua.isString()`                  |\n| `lua_istable`              | ☑️ `lua.isTable()`                   |\n| `lua_isthread`             | ☑️ `lua.isThread()`                  |\n| `lua_isuserdata`           | ☑️ `lua.isUserdata()`                |\n| `lua_lessthan`             | ☑️ `lua.lessThan()`                  |\n| `lua_load`                 | ☑️ `lua.load()`                      |\n| `lua_newstate`             | ☑️📢 `Lua.init()`                    |\n| `lua_newtable`             | ☑️ `lua.newTable()`                  |\n| `lua_newthread`            | ☑️ `lua.newThread()`                 |\n| `lua_newuserdata`          | ☑️ `lua.newUserdata()`               |\n| `lua_next`                 | ☑️ `lua.next()`                      |\n| `lua_objlen`               | ☑️📢 `lua.getLength()`               |\n| `lua_pop`                  | ☑️ `lua.pop()`                       |\n| `lua_pushboolean`          | ☑️ `lua.pushBoolean()`               |\n| `lua_pushcclosure`         | ☑️ `lua.pushCClosure()`              |\n| `lua_pushcfunction`        | ☑️ `lua.pushCFunction()`             |\n| `lua_pushfstring`          | ☑️ `lua.pushFString()`               |\n| `lua_pushinteger`          | ☑️ `lua.pushInteger()`               |\n| `lua_pushlightuserdata`    | ☑️ `lua.pushLightUserdata()`         |\n| `lua_pushliteral`          | 🆖 please use `lua.pushLString()`   |\n| `lua_pushlstring`          | ☑️ `lua.pushLString()`               |\n| `lua_pushnil`              | ☑️ `lua.pushNil()`                   |\n| `lua_pushnumber`           | ☑️ `lua.pushNumber()`                |\n| `lua_pushstring`           | ☑️ `lua.pushString()`                |\n| `lua_pushthread`           | ☑️ `lua.pushThread()`                |\n| `lua_pushvalue`            | ☑️ `lua.pushValue()`                 |\n| `lua_pushvfstring`         | 🆖 please use `lua.pushFString()`   |\n| `lua_rawequal`             | ☑️📢 `lua.equalRaw()`                |\n| `lua_rawgeti`              | ☑️📢 `lua.getTableIndexRaw()`        |\n| `lua_rawget`               | ☑️📢 `lua.getTableRaw()`             |\n| `lua_rawseti`              | ☑️📢 `lua.setTableIndexRaw()`        |\n| `lua_rawset`               | ☑️📢 `lua.setTableRaw()`             |\n| `lua_register`             | ☑️📢 `lua.registerFunction()`        |\n| `lua_remove`               | ☑️ `lua.remove()`                    |\n| `lua_replace`              | ☑️ `lua.replace()`                   |\n| `lua_resume`               | ➖ Hidden, see [Issue #6][ISSUE-6]  |\n| `lua_setallocf`            | ☑️📢 `lua.setAllocator()`            |\n| `lua_setfenv`              | ☑️📢 `lua.setEnvironment()`          |\n| `lua_setfield`             | ☑️ `lua.setField()`                  |\n| `lua_setglobal`            | ☑️ `lua.setGlobal()`                 |\n| `lua_setmetatable`         | ☑️ `lua.setMetatable()`              |\n| `lua_settable`             | ☑️ `lua.setTable()`                  |\n| `lua_settop`               | ☑️ `lua.setTop()`                    |\n| `lua_status`               | ☑️ `lua.status()`                    |\n| `lua_toboolean`            | ☑️ `lua.toBoolean()`                 |\n| `lua_tocfunction`          | ☑️ `lua.toCFunction()`               |\n| `lua_tointeger`            | ☑️ `lua.toInteger()`                 |\n| `lua_tolstring`            | ☑️ `lua.toLString()`                 |\n| `lua_tonumber`             | ☑️ `lua.toNumber()`                  |\n| `lua_topointer`            | ☑️ `lua.toPointer()`                 |\n| `lua_tostring`             | ☑️ `lua.toString()`                  |\n| `lua_tothread`             | ☑️ `lua.toThread()`                  |\n| `lua_touserdata`           | ☑️ `lua.toUserdata()`                |\n| `lua_type`                 | ☑️📢 `lua.getType()`                 |\n| `lua_typename`             | ☑️ `lua.getTypeName()`               |\n| `lua_xmove`                | ☑️ `lua.xmove()`                     |\n| `lua_yield`                | ➖ Hidden, see [Issue #6][ISSUE-6]  |\n\n[ISSUE-6]: https://github.com/sackosoft/zig-luajit/issues/6\n\n\n### Auxilary Library Coverage (`luaL_`)\n\n| C Type Definition          | Available in `zig-luajit`           |\n|----------------------------|-------------------------------------|\n| `luaL_Buffer`              | ☑️ `Lua.Buffer`                      |\n| `luaL_Reg`                 | ☑️ `Lua.Reg` and `Lua.RegEnd`        |\n\n| C API Symbol               | Available in `zig-luajit`           |\n|----------------------------|-------------------------------------|\n| `luaL_addchar`             | ☑️ `buffer.addChar()`|\n| `luaL_addsize`             | ☑️ `buffer.addSize()`|\n| `luaL_addlstring`          | ☑️ `buffer.addLString()`|\n| `luaL_addstring`           | ☑️ `buffer.addString()`|\n| `luaL_addvalue`            | ☑️ `buffer.addValue()`|\n| `luaL_argcheck`            | ☑️📢 `lua.checkArgument()` |\n| `luaL_argerror`            | ☑️📢 `lua.raiseErrorArgument()` |\n| `luaL_buffinit`            | ☑️📢 `lua.initBuffer()`|\n| `luaL_callmeta`            | ☑️ `lua.callMeta()`|\n| `luaL_checkany`            | ☑️ `lua.checkAny()`|\n| `luaL_checkinteger`        | ☑️ `lua.checkInteger()` |\n| `luaL_checkint`            | 🆖 please use `lua.checkInteger()` |\n| `luaL_checklong`           | 🆖 please use `lua.checkInteger()` |\n| `luaL_checklstring`        | ☑️ `lua.checkLString()` |\n| `luaL_checknumber`         | ☑️ `lua.checkNumber()` |\n| `luaL_checkoption`         | ☑️ `lua.checkOption()` |\n| `luaL_checkstack`          | ☑️📢 `lua.checkStackOrError()` |\n| `luaL_checkstring`         | ☑️ `lua.checkString()` |\n| `luaL_checktype`           | ☑️ `lua.checkType()` |\n| `luaL_checkudata`          | ☑️ `lua.checkUserdata()`|\n| `luaL_dofile`              | ☑️ `lua.doFile()` |\n| `luaL_dostring`            | ☑️ `lua.doString()` |\n| `luaL_error`               | ☑️📢 `lua.raiseErrorFormat()` |\n| `luaL_getmetafield`        | ☑️ `lua.getMetaField()` |\n| `luaL_getmetatable`        | ☑️📢 `lua.getMetatableRegistry()` |\n| `luaL_gsub`                | ☑️ `lua.gsub()` |\n| `luaL_loadbuffer`          | ☑️ `lua.loadBuffer()` |\n| `luaL_loadfile`            | ☑️ `lua.loadFile()` |\n| `luaL_loadstring`          | ☑️ `lua.loadString()` |\n| `luaL_newmetatable`        | ☑️ `lua.newMetatable()` |\n| `luaL_newstate`            | 🆖 please use `Lua.init()` |\n| `luaL_openlibs`            | ☑️ `lua.openLibs()` |\n| `luaL_optinteger`          | ☑️📢 `lua.checkIntegerOptional()` |\n| `luaL_optint`              | 🆖 please use `lua.checkIntegerOptional()` |\n| `luaL_optlong`             | 🆖 please use `lua.checkIntegerOptional()` |\n| `luaL_optlstring`          | ☑️📢 `lua.checkLStringOptional()` |\n| `luaL_optnumber`           | ☑️📢 `lua.checkNumberOptional()` |\n| `luaL_optstring`           | ☑️📢 `lua.checkStringOptional()` |\n| `luaL_prepbuffer`          | ☑️ `buffer.prepBuffer()` |\n| `luaL_pushresult`          | ☑️ `buffer.pushResult()` |\n| `luaL_ref`                 | ☑️ `lua.ref()` |\n| `luaL_unref`               | ☑️ `lua.unref()` |\n| `luaL_register`            | ☑️📢 `lua.registerLibrary()` |\n| `luaL_typename`            | ☑️ `lua.getTypeNameAt()` |\n| `luaL_typerror`            | ☑️📢 `lua.raiseErrorType()` |\n| `luaL_where`               | ☑️ `lua.where()` |\n\n### Debug API Coverage (`lua_Debug`)\n\n| C Type Definition          | Available in `zig-luajit`           |\n|----------------------------|-------------------------------------|\n| `lua_Debug`                | ☑️ `Lua.DebugInfo`                   |\n| `lua_Hook`                 | ☑️📢 `Lua.HookFunction`              |\n\n| C API Symbol               | Available in `zig-luajit`           |\n|----------------------------|-------------------------------------|\n| `lua_getinfo`              | ☑️ `lua.getInfo()`                   |\n| `lua_getstack`             | ☑️ `lua.getStack()`                  |\n| `lua_gethookcount`         | ☑️ `lua.getHookCount()`              |\n| `lua_gethookmask`          | ☑️ `lua.getHookMask()`               |\n| `lua_gethook`              | ☑️ `lua.getHook()`                   |\n| `lua_sethook`              | ☑️ `lua.setHook()`                   |\n| `lua_getlocal`             | ☑️ `lua.getLocal()`                  |\n| `lua_setlocal`             | ☑️ `lua.setLocal()`                  |\n| `lua_getupvalue`           | ☑️ `lua.getUpvalue()`                |\n| `lua_setupvalue`           | ☑️ `lua.setUpvalue()`                |\n\n\n## Additions to the API in `zig-luajit`\n\nThe following functions are added in `zig-luajit` and do not necessarily have a corresponding\nfunction or macro in the C API.\n\n| `zig-luajit` Extension Function | Description |\n|---------------------------------|-------------|\n| `lua.getInfoFunction()`         | A simplified version of `lua.getInfo()` for inspecting functions, that has a more idiomatic Zig result type. |\n| `lua.toNumberStrict()`          | Gets the value of a number on the stack, without doing type coersion (e.g. from string values). |\n| `lua.toIntegerStrict()`         | Gets the value of an integer on the stack, without doing type coersion (e.g. from string values). |\n| `lua.toBooleanStrict()`         | Gets the value of a boolean on the stack, without doing type coersion based on \"truthyness\" of the value. |\n| `lua.openBaseLib()`             | Opens the `Base` Lua standard library. |\n| `lua.openMathLib()`             | Opens the `Math` Lua standard library. |\n| `lua.openStringLib()`           | Opens the `String` Lua standard library. |\n| `lua.openTableLib()`            | Opens the `Table` Lua standard library. |\n| `lua.openIOLib()`               | Opens the `IO` Lua standard library. |\n| `lua.openOSLib()`               | Opens the `OS` Lua standard library. |\n| `lua.openPackageLib()`          | Opens the `Package` Lua standard library. |\n| `lua.openDebugLib()`            | Opens the `Debug` Lua standard library. |\n| `lua.openBitLib()`              | Opens the `Bit` LuaJIT standard library. |\n| `lua.openJITLib()`              | Opens the `JIT` LuaJIT standard library. |\n| `lua.openFFILib()`              | Opens the `FFI` LuaJIT standard library. |\n| `lua.openStringBufferLib()`     | Opens the `StringBuffer` LuaJIT standard library. |\n\n\n## Licensing\n\nThe `zig-luajit` Zig languge bindings are distributed under the terms of the AGPL-3.0 License. The terms of this\nlicense can be found in the [LICENSE](./LICENSE) file.\n\nThis project depends on source code and other artifacts from third parties. Information about their respective licenses\ncan be found in the [COPYRIGHT](./COPYRIGHT.md) file.\n* [The LuaJIT Project](https://luajit.org/)\n* [Lua](https://www.lua.org/)\n\n## Credits\n\nThis project was inspired by [natecraddock/ziglua](https://github.com/natecraddock/ziglua) which provides great\nfunctionality if you're looking to use Lua runtimes other than LuaJIT!\n","funding_links":[],"categories":["Zig","Interoperability"],"sub_categories":["FFI Bindings"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsackosoft%2Fzig-luajit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsackosoft%2Fzig-luajit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsackosoft%2Fzig-luajit/lists"}