lua_macro_impl/
lib.rs

1#![feature(proc_macro_span)]
2#![feature(proc_macro_hygiene)]
3
4extern crate proc_macro;
5use proc_macro::TokenStream;
6
7#[macro_use]
8extern crate quote;
9
10#[proc_macro]
11pub fn lua(input: TokenStream) -> TokenStream {
12    let mut tokens = input.into_iter();
13    let mut span = tokens.next().unwrap().span();
14
15    while let Some(tk) = tokens.next() {
16        span = span.join(tk.span()).unwrap();
17    }
18
19    let src = span.source_text().unwrap();
20
21    quote!( lua_macro::run_lua::<()>(#src); ).into()
22}
23
24#[proc_macro]
25pub fn lua_eval(input: TokenStream) -> TokenStream {
26    let mut tokens = input.into_iter();
27    let mut span = tokens.next().unwrap().span();
28
29    while let Some(tk) = tokens.next() {
30        span = span.join(tk.span()).unwrap();
31    }
32
33    let src = span.source_text().unwrap();
34
35    quote!( lua_macro::run_lua::<_>(#src) ).into()
36}