phper_macros/lib.rs
1// Copyright (c) 2022 PHPER Framework Team
2// PHPER is licensed under Mulan PSL v2.
3// You can use this software according to the terms and conditions of the Mulan
4// PSL v2. You may obtain a copy of Mulan PSL v2 at:
5// http://license.coscl.org.cn/MulanPSL2
6// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
7// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
8// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
9// See the Mulan PSL v2 for more details.
10
11#![warn(rust_2018_idioms, missing_docs)]
12#![warn(clippy::dbg_macro, clippy::print_stdout)]
13#![doc = include_str!("../README.md")]
14
15// TODO Write a bridge macro for easy usage about register functions and
16// classes, like `cxx`.
17
18mod alloc;
19mod derives;
20mod globals;
21mod inner;
22mod log;
23mod utils;
24
25use proc_macro::TokenStream;
26
27/// C style string end with '\0'.
28///
29/// # Examples
30///
31/// ```no_test
32/// use std::ffi::CStr;
33///
34/// assert_eq!(c_str!("foo"), unsafe {
35/// CStr::from_ptr("foo\0".as_ptr().cast())
36/// });
37/// ```
38#[proc_macro]
39pub fn c_str(input: TokenStream) -> TokenStream {
40 utils::c_str(input)
41}
42
43/// C style string end with '\0'.
44///
45/// # Examples
46///
47/// ```no_test
48/// assert_eq!(c_str_ptr!("foo"), "foo\0".as_ptr().cast());
49/// ```
50#[proc_macro]
51pub fn c_str_ptr(input: TokenStream) -> TokenStream {
52 utils::c_str_ptr(input)
53}
54
55/// PHP module entry, wrap the `phper::modules::Module` write operation.
56///
57/// # Examples
58///
59/// ```no_test
60/// use phper::{php_get_module, modules::Module};
61///
62/// #[php_get_module]
63/// pub fn get_module() -> Module {
64/// let mut module = Module::new(
65/// env!("CARGO_CRATE_NAME"),
66/// env!("CARGO_PKG_VERSION"),
67/// env!("CARGO_PKG_AUTHORS"),
68/// );
69///
70/// // ...
71///
72/// module
73/// }
74/// ```
75#[proc_macro_attribute]
76pub fn php_get_module(attr: TokenStream, input: TokenStream) -> TokenStream {
77 inner::php_get_module(attr, input)
78}