1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
//! Macros utilizing the [OpenGL API and Extension Registry].
//!
//! [OpenGL API and Extension Registry]: https://github.com/KhronosGroup/OpenGL-Registry
#![cfg_attr(test, feature(test))]
#![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 iter;
mod repeat;
mod str;
mod token_stream;
const OPENGL_CMD_NAME_REPLACE: &str = "gl_command_name";
const OPENGL_CMD_NAME_NOPREFIX_REPLACE: &str = "gl_command_name_noprefix";
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 **prefixed with a hashtag**.
///
/// ### The following identifiers will be replaced
///
/// **`gl_command_name`**<br>
/// Will be replaced by the full command name. For example, `glViewport`.
///
/// **`gl_command_name_noprefix`**<br>
/// Will be replaced by the command name without the "gl" prefix. For example,
/// `Viewport`.
///
/// **`gl_command_ret_type`**<br>
/// Will be replaced by the command return type. For example, `GLuint`.
///
/// **`gl_command_args`**<br>
/// Will be replaced by the command arguments formatted as `name: type`, seperated by
/// comma.
///
/// **`gl_command_arg_names`**<br>
/// Will be replaced by the command argument names, seperated by comma.
///
/// **`gl_command_arg_types`**<br>
/// Will be replaced by the command argument types, seperated by comma.
///
/// # Examples
/// ```
/// # use opengl_registry_macros::for_each_opengl_command;
/// for_each_opengl_command! {
/// fn #gl_command_name()
/// {
/// println!("Hello from {}", stringify!(#gl_command_name));
/// }
/// }
/// ```
///
/// 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()
}
|