Update for rust
This commit is contained in:
parent
c0a090d2cf
commit
3e643ffd2a
@ -2,7 +2,7 @@
|
|||||||
#![feature(phase)]
|
#![feature(phase)]
|
||||||
|
|
||||||
#[phase(plugin)]
|
#[phase(plugin)]
|
||||||
extern crate lua = "rust-hl-lua-modules";
|
extern crate "rust-hl-lua-modules" as lua;
|
||||||
|
|
||||||
#[export_lua_module]
|
#[export_lua_module]
|
||||||
pub mod mylib {
|
pub mod mylib {
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
extern crate rustc;
|
extern crate rustc;
|
||||||
extern crate syntax;
|
extern crate syntax;
|
||||||
|
|
||||||
use std::gc::{GC, Gc};
|
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
use syntax::ast::Item;
|
use syntax::ast::Item;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
@ -14,18 +13,19 @@ use syntax::ext::build::AstBuilder;
|
|||||||
use syntax::ext::base;
|
use syntax::ext::base;
|
||||||
use syntax::ext::quote::rt::ToSource;
|
use syntax::ext::quote::rt::ToSource;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
use syntax::ptr::P;
|
||||||
|
|
||||||
#[plugin_registrar]
|
#[plugin_registrar]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn plugin_registrar(reg: &mut ::rustc::plugin::Registry) {
|
pub fn plugin_registrar(reg: &mut ::rustc::plugin::Registry) {
|
||||||
reg.register_syntax_extension(token::intern("export_lua_module"),
|
reg.register_syntax_extension(token::intern("export_lua_module"),
|
||||||
base::ItemModifier(expand_lua_module));
|
base::ItemModifier(box expand_lua_module));
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler for export_lua_module
|
// handler for export_lua_module
|
||||||
pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
||||||
_: Gc<ast::MetaItem>, input_item: Gc<ast::Item>)
|
_: &ast::MetaItem, input_item: P<ast::Item>)
|
||||||
-> Gc<ast::Item>
|
-> P<ast::Item>
|
||||||
{
|
{
|
||||||
let ecx: &base::ExtCtxt = &*ecx;
|
let ecx: &base::ExtCtxt = &*ecx;
|
||||||
|
|
||||||
@ -38,7 +38,8 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
_ => {
|
_ => {
|
||||||
ecx.span_err(input_item.span,
|
ecx.span_err(input_item.span,
|
||||||
"`export_lua_module` extension is only allowed on modules");
|
"`export_lua_module` extension is only allowed on modules");
|
||||||
return input_item
|
return ecx.item_mod(span.clone(), span.clone(), ecx.ident_of("dummy"), vec![],
|
||||||
|
vec![], vec![]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
new_item.items.clear();
|
new_item.items.clear();
|
||||||
|
|
||||||
// creating an array of the statements to add to the main Lua entry point
|
// creating an array of the statements to add to the main Lua entry point
|
||||||
let module_handler_body: Vec<Gc<ast::Stmt>> = {
|
let module_handler_body: Vec<P<ast::Stmt>> = {
|
||||||
let mut module_handler_body = Vec::new();
|
let mut module_handler_body = Vec::new();
|
||||||
|
|
||||||
// iterating over elements inside the module
|
// iterating over elements inside the module
|
||||||
@ -64,11 +65,11 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
new_item.items.push(box (GC) Item {
|
new_item.items.push(ecx.item(
|
||||||
ident: moditem.ident.clone(),
|
span.clone(),
|
||||||
attrs: moditem.attrs.clone(),
|
moditem.ident.clone(),
|
||||||
id: moditem.id.clone(),
|
moditem.attrs.clone(),
|
||||||
node: ast::ItemFn(
|
ast::ItemFn(
|
||||||
decl.clone(),
|
decl.clone(),
|
||||||
style.clone(),
|
style.clone(),
|
||||||
abi.clone(),
|
abi.clone(),
|
||||||
@ -86,10 +87,8 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
vis: moditem.vis.clone(),
|
));
|
||||||
span: moditem.span.clone(),
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ast::ItemStatic(..) => {
|
ast::ItemStatic(..) => {
|
||||||
@ -132,7 +131,7 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
let view_items = quote_item!(ecx,
|
let view_items = quote_item!(ecx,
|
||||||
mod x {
|
mod x {
|
||||||
extern crate core;
|
extern crate core;
|
||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate native;
|
extern crate native;
|
||||||
}
|
}
|
||||||
@ -143,14 +142,19 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
None => {
|
None => {
|
||||||
ecx.span_err(input_item.span,
|
ecx.span_err(input_item.span,
|
||||||
"internal error in the library (could not parse view items)");
|
"internal error in the library (could not parse view items)");
|
||||||
return input_item;
|
return ecx.item_mod(span.clone(), span.clone(), ecx.ident_of("dummy"), vec![],
|
||||||
|
vec![], vec![]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// getting all the items
|
// getting all the items
|
||||||
let view_items = match view_items.node {
|
let view_items = match view_items.node {
|
||||||
ast::ItemMod(ref m) => m,
|
ast::ItemMod(ref m) => m,
|
||||||
_ => { ecx.span_err(span, "internal error in the library"); return input_item; }
|
_ => {
|
||||||
|
ecx.span_err(span, "internal error in the library");
|
||||||
|
return ecx.item_mod(span.clone(), span.clone(), ecx.ident_of("dummy"), vec![],
|
||||||
|
vec![], vec![]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for i in view_items.view_items.iter() {
|
for i in view_items.view_items.iter() {
|
||||||
@ -202,7 +206,8 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
None => {
|
None => {
|
||||||
ecx.span_err(input_item.span,
|
ecx.span_err(input_item.span,
|
||||||
"internal error in the library (could not parse function body)");
|
"internal error in the library (could not parse function body)");
|
||||||
return input_item;
|
return ecx.item_mod(span.clone(), span.clone(), ecx.ident_of("dummy"), vec![],
|
||||||
|
vec![], vec![]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -211,18 +216,19 @@ pub fn expand_lua_module(ecx: &mut base::ExtCtxt, span: codemap::Span,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// returning
|
// returning
|
||||||
box(GC) Item {
|
ecx.item(
|
||||||
ident: input_item.ident.clone(),
|
span.clone(),
|
||||||
attrs: input_item.attrs.clone(),
|
input_item.ident.clone(),
|
||||||
id: input_item.id.clone(),
|
input_item.attrs.clone(),
|
||||||
node: ast::ItemMod(new_item),
|
ast::ItemMod(new_item)
|
||||||
vis: {
|
).map(|mut item| {
|
||||||
|
item.vis = {
|
||||||
if input_item.vis != ast::Public {
|
if input_item.vis != ast::Public {
|
||||||
ecx.span_warn(input_item.span,
|
ecx.span_warn(input_item.span,
|
||||||
"`export_lua_module` will turn the module into a public module");
|
"`export_lua_module` will turn the module into a public module");
|
||||||
}
|
}
|
||||||
ast::Public
|
ast::Public
|
||||||
},
|
};
|
||||||
span: input_item.span.clone(),
|
item
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
use lua::Lua;
|
use lua::Lua;
|
||||||
use lua::any::{AnyLuaValue, Number, String, Boolean};
|
use lua::any::{AnyLuaValue, Number, String, Boolean};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
use lua::Lua;
|
use lua::Lua;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_function() {
|
fn simple_function() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
use lua::{Lua, LuaTable};
|
use lua::{Lua, LuaTable};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
use lua::{Lua, LuaTable};
|
use lua::{Lua, LuaTable};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
extern crate lua = "rust-hl-lua";
|
extern crate "rust-hl-lua" as lua;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn readwrite() {
|
fn readwrite() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user