You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes the linking code, and adds a new option to the build function to
link Ziglua as a shared library rather than as a static library. This is
for the use case of creating shared modules to require at runtime in
Lua.
This makes the `ziglua` package available in your project. Access with `@import("ziglua")`.
128
128
129
-
There are currently two options that can be passed in the third argument to `ziglua.link()`:
129
+
There are currently three options that can be passed in the third argument to `ziglua.link()`:
130
130
131
131
*`.use_apicheck`: defaults to **false**. When **true** defines the macro `LUA_USE_APICHECK` in debug builds. See [The C API docs](https://www.lua.org/manual/5.4/manual.html#4) for more information on this macro.
132
132
133
133
*`.version`: Set the Lua version to build and embed. Defaults to `.lua_54`. Possible values are `.lua_51`, `.lua_52`, `.lua_53`, and `.lua_54`.
134
134
135
+
*`.shared`: Defaults to `false` for embedding in a Zig program. Set to `true` to dynamically link the Lua source code (useful for creating shared modules).
136
+
135
137
For example, here is a `ziglua.linkAndPackage()` call that enables api check and embeds Lua 5.2:
Copy file name to clipboardExpand all lines: readme.md
+15-11Lines changed: 15 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,32 +1,36 @@
1
-
# ziglua
1
+
# Ziglua
2
2
3
-
A Zig library that provides a lightweight wrapper around the [Lua C API](https://www.lua.org/manual/5.4/manual.html#4) to embed the Lua virtual machine into your Zig programs. Currently tracks the latest Lua version (5.4.4).
3
+
A Zig library that provides a complete yet lightweight wrapper around the [Lua C API](https://www.lua.org/manual/5.4/manual.html#4). Ziglua currently supports the latest releases of Lua 5.1, 5.2, 5.3, and 5.4.
4
4
5
-
Like the Lua C API, the ziglua API "emphasizes flexibility and simplicity... common tasks may involve several API calls. This may be boring, but it gives us full control over all the details" (_Programming In Lua 4th Edition_). However, ziglua takes advantage of Zig's features to make it easier and safer to interact with the Lua API.
5
+
Ziglua offers two approaches as a library:
6
+
***embedded**: used to embed the Lua VM in a Zig program
7
+
***module**: used to create shared Lua modules that can be loaded at runtime in other Lua-based software
8
+
9
+
Like the Lua C API, the Ziglua API "emphasizes flexibility and simplicity... common tasks may involve several API calls. This may be boring, but it gives us full control over all the details" (_Programming In Lua 4th Edition_). However, Ziglua takes advantage of Zig's features to make it easier and safer to interact with the Lua API.
In a nutshell, ziglua is a simple wrapper around the C API you would get by using Zig's `@cImport()`. ziglua aims to mirror the [Lua C API](https://www.lua.org/manual/5.4/manual.html#4) as closely as possible, while improving ergonomics using Zig's features. For example:
16
+
In a nutshell, Ziglua is a simple wrapper around the C API you would get by using Zig's `@cImport()`. Ziglua aims to mirror the [Lua C API](https://www.lua.org/manual/5.4/manual.html#4) as closely as possible, while improving ergonomics using Zig's features. For example:
13
17
14
18
* Zig error unions to require failure state handling
15
19
* Null-terminated slices instead of C strings
16
20
* Type-checked enums for parameters and return values
17
21
* Compiler-enforced checking of optional pointers
18
22
* More precise types (e.g. `bool` instead of `int`)
19
23
20
-
While there are some helper functions added to complement the C API, ziglua aims to remain low-level. This allows full access to the Lua API through a layer of Zig's improvements over C.
24
+
While there are some helper functions added to complement the C API, Ziglua aims to remain low-level. This allows full access to the Lua API through a layer of Zig's improvements over C.
21
25
22
26
If you want something higher-level (but doesn't expose the full API), perhaps try [zoltan](https://github.com/ranciere/zoltan).
23
27
24
28
## Getting Started
25
29
26
-
Adding ziglua to your project is easy. First add this repo as a git submodule, or copy the source into your repo. Then add the following to your `build.zig` file (assuming cloned/copied into a `lib/` subdirectory):
30
+
Adding Ziglua to your project is easy. First add this repo as a git submodule, or copy the source into your repo. Then add the following to your `build.zig` file (assuming cloned/copied into a `lib/` subdirectory):
27
31
28
32
```zig
29
-
// use the path to the ziglua build.zig file
33
+
// use the path to the Ziglua build.zig file
30
34
const ziglua = @import("lib/ziglua/build.zig");
31
35
32
36
pub fn build(b: *Builder) void {
@@ -56,13 +60,13 @@ pub fn main() anyerror!void {
56
60
}
57
61
```
58
62
59
-
See [docs.md](https://github.com/natecraddock/ziglua/blob/master/docs.md) for documentation and detailed [examples](https://github.com/natecraddock/ziglua/blob/master/docs.md#examples) of using ziglua.
63
+
See [docs.md](https://github.com/natecraddock/ziglua/blob/master/docs.md) for documentation and detailed [examples](https://github.com/natecraddock/ziglua/blob/master/docs.md#examples) of using Ziglua.
60
64
61
65
## Status
62
66
63
-
Nearly all functions, types, and constants in the C API have been wrapped in ziglua. Only a few exceptions have been made when the function doesn't make sense in Zig (like functions using `va_list`).
67
+
Nearly all functions, types, and constants in the C API have been wrapped in Ziglua. Only a few exceptions have been made when the function doesn't make sense in Zig (like functions using `va_list`).
64
68
65
-
All functions have been type checked, but only the standard C API has been tested fully. ziglua should be relatively stable and safe to use now, but is still new and changing frequently.
69
+
All functions have been type checked, but only the standard C API has been tested fully. Ziglua should be relatively stable and safe to use now, but is still new and changing frequently.
0 commit comments