diff options
author | HampusM <hampus@hampusmat.com> | 2023-02-19 17:16:54 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-02-19 18:24:57 +0100 |
commit | 6b6f25357e25a07d234ae683c1b58b1929b8483e (patch) | |
tree | 5ff873b64aa21c0961d32c6aee056aca32481e20 /src/lib.rs | |
parent | b3fc15dc216794419c7d97d9f4d7f596c26e9182 (diff) |
feat: add project & for_each_opengl_command macro
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..35d975f --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,76 @@ +//! Macros utilizing the [OpenGL API and Extension Registry]. +//! +//! [OpenGL API and Extension Registry]: https://github.com/KhronosGroup/OpenGL-Registry +#![deny(clippy::all, clippy::pedantic, missing_docs)] +use once_cell::sync::Lazy; +use opengl_registry::Registry; +use proc_macro::TokenStream; + +use crate::repeat::for_each_opengl_command_impl; + +mod repeat; +mod str; +mod token_stream; + +const OPENGL_CMD_IDENT_REPLACE: &str = "_gl_command_"; +const OPENGL_CMD_RET_TYPE_REPLACE: &str = "_gl_command_ret_type_"; +const OPENGL_CMD_ARGS_REPLACE: &str = "_gl_command_args_"; +const OPENGL_CMD_ARG_NAMES_REPLACE: &str = "_gl_command_arg_names_"; +const OPENGL_CMD_ARG_TYPES_REPLACE: &str = "_gl_command_arg_types_"; + +static OPENGL_REGISTRY: Lazy<Registry> = Lazy::new(|| Registry::retrieve().unwrap()); + +/// Repeats the input for each command in the [OpenGL API and Extension Registry]. +/// +/// # Replacements +/// This macro will replace some specific identifiers. These identifiers are to be put +/// between underscores. +/// +/// ### The following identifiers will be replaced +/// +/// **`gl_command`**<br> +/// Will be replaced by the command name. +/// +/// **`gl_command_ret_type`**<br> +/// Will be replaced by the command return type. +/// +/// **`gl_command_args`**<br> +/// Will be replaced by the command arguments formatted as `name: type`. +/// +/// **`gl_command_arg_names`**<br> +/// Will be replaced by the command argument names. +/// +/// **`gl_command_arg_types`**<br> +/// Will be replaced by the command argument types. +/// +/// # Examples +/// ``` +/// # use opengl_registry_macros::for_each_opengl_command; +/// for_each_opengl_command! { +/// fn _gl_command_() +/// { +/// println!("Hello from {}", stringify!(_gl_command_)); +/// } +/// } +/// ``` +/// +/// Would expand to the following if the only OpenGL commands were `glCreateShader` and +/// `glBindBuffer`. +/// +/// ``` +/// fn glCreateShader() +/// { +/// println!("Hello from {}", stringify!(glCreateShader)); +/// } +/// fn glBindBuffer() +/// { +/// println!("Hello from {}", stringify!(glBindBuffer)); +/// } +/// ``` +/// +/// [OpenGL API and Extension Registry]: https://github.com/KhronosGroup/OpenGL-Registry +#[proc_macro] +pub fn for_each_opengl_command(input_stream: TokenStream) -> TokenStream +{ + for_each_opengl_command_impl(&input_stream.into(), &OPENGL_REGISTRY).into() +} |