mirror of
https://github.com/icewind1991/ivory.git
synced 2026-06-03 18:54:07 +02:00
Implemented to build empty php extension in Rust
This commit is contained in:
parent
12ca6545e8
commit
b1a4a5fb8d
8 changed files with 204 additions and 0 deletions
53
examples/helloworld/src/lib.rs
Normal file
53
examples/helloworld/src/lib.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#![allow(unused_variables)]
|
||||
#![feature(link_args)]
|
||||
|
||||
extern crate libc;
|
||||
extern crate php;
|
||||
|
||||
use libc::*;
|
||||
use php::*;
|
||||
use php::info::*;
|
||||
|
||||
#[link_args = "-Wl,-undefined,dynamic_lookup"]
|
||||
extern {
|
||||
|
||||
}
|
||||
|
||||
macro_rules! c_str {
|
||||
($s:expr) => { {
|
||||
concat!($s, "\0").as_ptr() as *const c_char
|
||||
} }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn php_module_startup(type_: c_int, module_number: c_int) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn php_module_shutdown(type_: c_int, module_number: c_int) -> c_int {
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn php_module_info() {
|
||||
print_table_start();
|
||||
unsafe {
|
||||
php_info_print_table_row(2, c_str!("A demo PHP extension written in Rust"), c_str!("enabled"));
|
||||
}
|
||||
print_table_end();
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn get_module() -> *mut zend::Module {
|
||||
|
||||
let mut entry = Box::new(zend::Module::new(
|
||||
c_str!("demo"),
|
||||
c_str!("0.1.0-dev"),
|
||||
));
|
||||
|
||||
entry.set_info_func(php_module_info);
|
||||
|
||||
Box::into_raw(entry)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue