diff options
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)* + } + } + } +} |