Add a shared string that can be used in properties

This commit is contained in:
Olivier Goffart 2020-05-18 16:00:50 +02:00
parent e6be2c91b8
commit 25bf149e13
14 changed files with 208 additions and 52 deletions

View file

@ -6,6 +6,7 @@ pub mod re_exports {
pub use corelib::abi::datastructures::{Component, ComponentTO, ComponentVTable, ItemTreeNode};
pub use corelib::abi::primitives::{Image, ImageVTable, Rectangle, RectangleVTable};
pub use corelib::ComponentVTable_static;
pub use corelib::SharedString;
pub use gl::sixtyfps_runtime_run_component_with_gl_renderer;
pub use once_cell::sync::Lazy;
pub use vtable::{self, *};

View file

@ -10,6 +10,5 @@ path = "lib.rs"
[dependencies]
quote = "1.0"
proc-macro2 = "1.0"
sixtyfps_compiler = { path = "../../../sixtyfps_compiler", features = ["proc_macro_span"] }

View file

@ -1,7 +1,6 @@
extern crate proc_macro;
use object_tree::Expression;
use proc_macro::TokenStream;
use proc_macro2::{Literal, TokenTree};
use quote::quote;
use sixtyfps_compiler::*;
@ -126,9 +125,7 @@ pub fn sixtyfps(stream: TokenStream) -> TokenStream {
// That's an error
Expression::Identifier(_) => quote!(),
Expression::StringLiteral(s) => {
let c_str: std::ffi::CString = std::ffi::CString::new(s.as_bytes()).unwrap();
let tok = TokenTree::Literal(Literal::byte_string(c_str.as_bytes_with_nul()));
quote!(#tok as *const u8).into()
quote!(sixtyfps::re_exports::SharedString::from(#s))
}
Expression::NumberLiteral(n) => quote!(#n),
};