Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sylvrs/ext-php-zig
A Zig library to enable the writing of PHP extensions in Zig.
https://github.com/sylvrs/ext-php-zig
Last synced: 2 months ago
JSON representation
A Zig library to enable the writing of PHP extensions in Zig.
- Host: GitHub
- URL: https://github.com/sylvrs/ext-php-zig
- Owner: sylvrs
- Created: 2023-08-03T04:44:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-16T02:41:44.000Z (7 months ago)
- Last Synced: 2024-10-10T23:26:20.748Z (3 months ago)
- Language: Zig
- Homepage:
- Size: 47.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ext-php-zig
A Zig library to enable the writing of PHP extensions in Zig.
## DISCLAIMER!
This library is extremely early in development and as such, isn't feature complete nor ready for production use. Use at your own risk.## Usage
A basic module can be created by creating a Zig file with the following contents:
```zig
const php = @import("php");
const std = @import("std");var test_module = php.Module.init(.{
.name = "test_ext",
.version = "0.0.2",
.allocator = std.heap.page_allocator,
});// The library will automatically search for these three functions:
// - displayInfo - This is the function called when phpinfo() or php -i is called
// - handleStartup - This is the function called when the module is loaded
// - handleShutdown - This is the function called when the module is unloaded
pub fn displayInfo(_: *const php.ZendModuleEntry) void {
php.printInfoStart();
php.printInfoHeaderMap(.{
.@"test extension support" = "enabled",
});
php.printInfoEnd();
}pub fn handleStartup(version: usize, module_number: usize) !void {
// do something on startup
}pub fn handleShutdown(version: usize, module_number: usize) !void {
// make sure our allocated memory is freed
test_module.deinit();
}pub fn extHello(name: []const u8) void {
std.debug.print("Hello, {s}!\n", .{name});
}pub fn extFibonacci(n: i64) i64 {
if (n <= 1) {
return n;
}
return extFibonacci(n - 1) + extFibonacci(n - 2);
}pub fn
// This is the most important function when creating a module as this is what PHP will look for when loading the module
export fn get_module() *php.ZendModuleEntry {
test_module.addFunction("ext_hello", extHello, &.{});
test_module.addFunction("ext_fibonacci", extFibonacci, &.{});
return test_module.create(@This());
}
```