From 966ebb03abd8ae5ed4f47f4b53c00222269a56b4 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 7 Apr 2023 20:20:43 +0200 Subject: refactor: replace usage of opengl-registry-macros --- codegen/load_with.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 codegen/load_with.rs (limited to 'codegen/load_with.rs') 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(get_proc_addr: GetProcAddrFn) + where + GetProcAddrFn: Fn(&str) -> unsafe extern "C" fn(), + { + unsafe { + #(#command_assignments)* + } + } + } +} -- cgit v1.2.3-18-g5258