Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename Web Object with web_interop macro #750

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/gosub_webinterop/src/impl_interop_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::{format_ident, quote};

use crate::types::Field;

pub fn impl_interop_struct(name: Ident, fields: &[Field]) -> TokenStream {
pub fn impl_interop_struct(name: Ident, fields: &[Field], js_name: TokenStream) -> TokenStream {
let marker_struct = format_ident!("{}JSMethodsMarker", name);
let marker_trait = format_ident!("{}JSMethods", name);

Expand All @@ -12,7 +12,7 @@ pub fn impl_interop_struct(name: Ident, fields: &[Field]) -> TokenStream {
quote! {
impl JSInterop for #name {
fn implement<RT: JSRuntime>(s: Rc<RefCell<Self>>, mut ctx: RT::Context) -> Result<()> {
let mut obj = ctx.new_global_object(stringify!(#name))?;
let mut obj = ctx.new_global_object(stringify!(#js_name))?;

#getters_setters

Expand Down
27 changes: 19 additions & 8 deletions crates/gosub_webinterop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ use proc_macro::TokenStream;
use std::collections::HashMap;
use std::sync::RwLock;

use lazy_static::lazy_static;
use proc_macro2::{Ident, TokenTree};
use quote::ToTokens;
use syn::spanned::Spanned;
use syn::{FnArg, ItemImpl, ItemStruct};

use crate::function::Function;
use crate::impl_function::impl_js_functions;
use crate::impl_interop_struct::impl_interop_struct;
use crate::property::{FieldProperty, FunctionProperty};
use crate::types::{Arg, ArgVariant, Field, GenericsMatcher, ReturnType, SelfType};
use crate::utils::crate_name;
use lazy_static::lazy_static;
use proc_macro2::{Ident, TokenTree};
use quote::ToTokens;
use syn::punctuated::Punctuated;
use syn::spanned::Spanned;
use syn::{parse_macro_input, FnArg, ItemImpl, ItemStruct, MetaNameValue, Token};

mod function;
mod impl_function;
Expand All @@ -29,7 +29,7 @@ lazy_static! {
}

#[proc_macro_attribute]
pub fn web_interop(_: TokenStream, item: TokenStream) -> TokenStream {
pub fn web_interop(args: TokenStream, item: TokenStream) -> TokenStream {
let mut fields: Vec<Field> = Vec::new();

let mut input: ItemStruct = syn::parse_macro_input!(item);
Expand All @@ -47,7 +47,18 @@ pub fn web_interop(_: TokenStream, item: TokenStream) -> TokenStream {
}
}

let extend = impl_interop_struct(input.ident.clone(), &fields);
let items: Punctuated<MetaNameValue, Token![,]> =
parse_macro_input!(args with Punctuated::<MetaNameValue, Token![,]>::parse_terminated);

let mut js_name = input.ident.to_token_stream();

for item in items {
if item.path.is_ident("js_name") {
js_name = item.value.to_token_stream();
}
}

let extend = impl_interop_struct(input.ident.clone(), &fields, js_name);

let name = input.ident.clone().into_token_stream().to_string();
STATE.write().unwrap().insert((crate_name(), name), 0);
Expand Down
1 change: 0 additions & 1 deletion examples/vello-renderer/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::window::Window;
use crate::WinitEventLoopHandle;
use anyhow::anyhow;
use gosub_instance::{DebugEvent, InstanceMessage};
use gosub_interface::chrome::ChromeHandle;
use gosub_interface::config::{HasRenderBackend, ModuleConfiguration};
use gosub_interface::instance::{Handles, InstanceId};
use gosub_interface::render_backend::{NodeDesc, RenderBackend, SizeU32};
Expand Down
Loading