diff options
author | HampusM <hampus@hampusmat.com> | 2023-04-07 20:20:43 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-04-07 20:22:07 +0200 |
commit | 966ebb03abd8ae5ed4f47f4b53c00222269a56b4 (patch) | |
tree | 24e3325f1657bef89005583e9650b5c8e57459df /codegen/load_with.rs | |
parent | c7efbb55f075748d88e25735c6d7e85ba768fd15 (diff) |
refactor: replace usage of opengl-registry-macros
Diffstat (limited to 'codegen/load_with.rs')
-rw-r--r-- | codegen/load_with.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/codegen/load_with.rs b/codegen/load_with.rs new file mode 100644 index 0000000..0e8e672 --- /dev/null +++ b/codegen/load_with.rs @@ -0,0 +1,28 @@ +use opengl_registry::command::Command; +use proc_macro2::TokenStream; +use quote::{format_ident, quote}; + +pub fn create_load_with_function(commands: &[Command]) -> TokenStream +{ + let command_assignments = commands.iter().map(|command| { + let command_name = format_ident!("{}", command.prototype().name()); + + let command_name_str = command.prototype().name(); + + quote! { + functions::#command_name = get_proc_addr(#command_name_str); + } + }); + + quote! { + /// Loads OpenGL function pointers using the given function address retriever function. + pub fn load_with<GetProcAddrFn>(get_proc_addr: GetProcAddrFn) + where + GetProcAddrFn: Fn(&str) -> unsafe extern "C" fn(), + { + unsafe { + #(#command_assignments)* + } + } + } +} |