Merge pull request #27 from tomaka/update-rustc

Update for rustc
This commit is contained in:
tomaka 2014-12-05 13:34:46 +01:00
commit 20a93287b6
7 changed files with 24 additions and 26 deletions

View File

@ -3,3 +3,4 @@
name = "rust-hl-lua" name = "rust-hl-lua"
version = "0.1.0" version = "0.1.0"
authors = [ "pierre.krieger1708@gmail.com" ] authors = [ "pierre.krieger1708@gmail.com" ]
license = "MIT"

View File

@ -1,7 +1,4 @@
#![crate_name = "rust-hl-lua"] #![crate_name = "rust-hl-lua"]
#![crate_type = "lib"]
#![comment = "Lua bindings for Rust"]
#![license = "MIT"]
#![feature(macro_rules)] #![feature(macro_rules)]
#![feature(unsafe_destructor)] #![feature(unsafe_destructor)]
@ -218,7 +215,7 @@ impl<'lua> Lua<'lua> {
/// Loads the value of a global variable. /// Loads the value of a global variable.
#[unstable] #[unstable]
pub fn load<'a, I: Str, V: ConsumeRead<'a, Lua<'lua>>>(&'a mut self, index: I) -> Option<V> { pub fn load<'a, I: Str, V: ConsumeRead<'a, Lua<'lua>>>(&'a mut self, index: I) -> Option<V> {
unsafe { ffi::lua_getglobal(self.lua, index.as_slice().to_c_str().unwrap()); } unsafe { ffi::lua_getglobal(self.lua, index.as_slice().to_c_str().into_inner()); }
ConsumeRead::read_from_variable(LoadedVariable { lua: self, size: 1 }).ok() ConsumeRead::read_from_variable(LoadedVariable { lua: self, size: 1 }).ok()
} }
@ -231,7 +228,7 @@ impl<'lua> Lua<'lua> {
/// Reads the value of a global variable by copying it. /// Reads the value of a global variable by copying it.
#[unstable] #[unstable]
pub fn get<I: Str, V: CopyRead<Lua<'lua>>>(&mut self, index: I) -> Option<V> { pub fn get<I: Str, V: CopyRead<Lua<'lua>>>(&mut self, index: I) -> Option<V> {
unsafe { ffi::lua_getglobal(self.lua, index.as_slice().to_c_str().unwrap()); } unsafe { ffi::lua_getglobal(self.lua, index.as_slice().to_c_str().into_inner()); }
CopyRead::read_from_lua(self, -1) CopyRead::read_from_lua(self, -1)
} }
@ -239,7 +236,7 @@ impl<'lua> Lua<'lua> {
#[unstable] #[unstable]
pub fn set<I: Str, V: Push<Lua<'lua>>>(&mut self, index: I, value: V) { pub fn set<I: Str, V: Push<Lua<'lua>>>(&mut self, index: I, value: V) {
value.push_to_lua(self); value.push_to_lua(self);
unsafe { ffi::lua_setglobal(self.lua, index.as_slice().to_c_str().unwrap()); } unsafe { ffi::lua_setglobal(self.lua, index.as_slice().to_c_str().into_inner()); }
} }
#[unstable] #[unstable]

View File

@ -3,7 +3,6 @@ use super::Push;
use HasLua; use HasLua;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::iter::Repeat;
use collections::hash::Hash; use collections::hash::Hash;
fn push_iter<L: HasLua, V: Push<L>, I: Iterator<V>>(lua: &mut L, iterator: I) -> uint { fn push_iter<L: HasLua, V: Push<L>, I: Iterator<V>>(lua: &mut L, iterator: I) -> uint {
@ -69,6 +68,7 @@ impl<L: HasLua, K: Push<L> + Eq + Hash, V: Push<L>> Push<L> for HashMap<K, V> {
impl<L: HasLua, K: Push<L> + Eq + Hash> Push<L> for HashSet<K> { impl<L: HasLua, K: Push<L> + Eq + Hash> Push<L> for HashSet<K> {
fn push_to_lua(self, lua: &mut L) -> uint { fn push_to_lua(self, lua: &mut L) -> uint {
push_rec_iter(lua, self.into_iter().zip(Repeat::new(true))) use std::iter;
push_rec_iter(lua, self.into_iter().zip(iter::repeat(true)))
} }
} }

View File

@ -116,7 +116,7 @@ numeric_impl!(f64)
impl<L: HasLua> Push<L> for String { impl<L: HasLua> Push<L> for String {
fn push_to_lua(self, lua: &mut L) -> uint { fn push_to_lua(self, lua: &mut L) -> uint {
unsafe { ffi::lua_pushstring(lua.use_lua(), self.to_c_str().unwrap()) }; unsafe { ffi::lua_pushstring(lua.use_lua(), self.to_c_str().into_inner()) };
1 1
} }
} }
@ -147,7 +147,7 @@ impl<L: HasLua> Index<L> for String {
impl<'str, L: HasLua> Push<L> for &'str str { impl<'str, L: HasLua> Push<L> for &'str str {
fn push_to_lua(self, lua: &mut L) -> uint { fn push_to_lua(self, lua: &mut L) -> uint {
unsafe { ffi::lua_pushstring(lua.use_lua(), self.to_c_str().unwrap()) } unsafe { ffi::lua_pushstring(lua.use_lua(), self.to_c_str().into_inner()) }
1 1
} }
} }

View File

@ -1,6 +1,6 @@
extern crate "rust-hl-lua" as lua; extern crate "rust-hl-lua" as lua;
use lua::Lua; use lua::Lua;
use lua::any::{AnyLuaValue,LuaNumber, LuaString, LuaBoolean}; use lua::any::AnyLuaValue;
#[test] #[test]
fn read_numbers() { fn read_numbers() {
@ -10,10 +10,10 @@ fn read_numbers() {
lua.set("b", 3.5f32); lua.set("b", 3.5f32);
let x: AnyLuaValue = lua.get("a").unwrap(); let x: AnyLuaValue = lua.get("a").unwrap();
assert_eq!(x, LuaNumber(-2.0)); assert_eq!(x, AnyLuaValue::LuaNumber(-2.0));
let y: AnyLuaValue = lua.get("b").unwrap(); let y: AnyLuaValue = lua.get("b").unwrap();
assert_eq!(y, LuaNumber(3.5)); assert_eq!(y, AnyLuaValue::LuaNumber(3.5));
} }
#[test] #[test]
@ -25,13 +25,13 @@ fn read_strings() {
lua.set("c", "false"); lua.set("c", "false");
let x: AnyLuaValue = lua.get("a").unwrap(); let x: AnyLuaValue = lua.get("a").unwrap();
assert_eq!(x, LuaString("hello".to_string())); assert_eq!(x, AnyLuaValue::LuaString("hello".to_string()));
let y: AnyLuaValue = lua.get("b").unwrap(); let y: AnyLuaValue = lua.get("b").unwrap();
assert_eq!(y, LuaString("3x".to_string())); assert_eq!(y, AnyLuaValue::LuaString("3x".to_string()));
let z: AnyLuaValue = lua.get("c").unwrap(); let z: AnyLuaValue = lua.get("c").unwrap();
assert_eq!(z, LuaString("false".to_string())); assert_eq!(z, AnyLuaValue::LuaString("false".to_string()));
} }
#[test] #[test]
@ -42,17 +42,17 @@ fn read_booleans() {
lua.set("b", false); lua.set("b", false);
let x: AnyLuaValue = lua.get("a").unwrap(); let x: AnyLuaValue = lua.get("a").unwrap();
assert_eq!(x, LuaBoolean(true)); assert_eq!(x, AnyLuaValue::LuaBoolean(true));
let y: AnyLuaValue = lua.get("b").unwrap(); let y: AnyLuaValue = lua.get("b").unwrap();
assert_eq!(y, LuaBoolean(false)); assert_eq!(y, AnyLuaValue::LuaBoolean(false));
} }
#[test] #[test]
fn push_numbers() { fn push_numbers() {
let mut lua = Lua::new(); let mut lua = Lua::new();
lua.set("a", LuaNumber(3.0)); lua.set("a", AnyLuaValue::LuaNumber(3.0));
let x: int = lua.get("a").unwrap(); let x: int = lua.get("a").unwrap();
assert_eq!(x, 3); assert_eq!(x, 3);
@ -62,7 +62,7 @@ fn push_numbers() {
fn push_strings() { fn push_strings() {
let mut lua = Lua::new(); let mut lua = Lua::new();
lua.set("a", LuaString("hello".to_string())); lua.set("a", AnyLuaValue::LuaString("hello".to_string()));
let x: String = lua.get("a").unwrap(); let x: String = lua.get("a").unwrap();
assert_eq!(x.as_slice(), "hello"); assert_eq!(x.as_slice(), "hello");
@ -72,7 +72,7 @@ fn push_strings() {
fn push_booleans() { fn push_booleans() {
let mut lua = Lua::new(); let mut lua = Lua::new();
lua.set("a", LuaBoolean(true)); lua.set("a", AnyLuaValue::LuaBoolean(true));
let x: bool = lua.get("a").unwrap(); let x: bool = lua.get("a").unwrap();
assert_eq!(x, true); assert_eq!(x, true);

View File

@ -41,7 +41,7 @@ fn wrong_arguments_types() {
lua.set("add", add); lua.set("add", add);
match lua.execute::<int>("return add(3, \"hello\")") { match lua.execute::<int>("return add(3, \"hello\")") {
Err(lua::ExecutionError(_)) => (), Err(lua::LuaError::ExecutionError(_)) => (),
_ => panic!() _ => panic!()
} }
} }
@ -54,7 +54,7 @@ fn return_result() {
lua.set("always_fails", always_fails); lua.set("always_fails", always_fails);
match lua.execute::<()>("always_fails()") { match lua.execute::<()>("always_fails()") {
Err(lua::ExecutionError(_)) => (), Err(lua::LuaError::ExecutionError(_)) => (),
_ => panic!() _ => panic!()
} }
} }

View File

@ -1,5 +1,5 @@
extern crate "rust-hl-lua" as lua; extern crate "rust-hl-lua" as lua;
use lua::{Lua, LuaTable}; use lua::Lua;
#[test] #[test]
fn iterable() { fn iterable() {
@ -29,8 +29,8 @@ fn iterable_multipletimes() {
let mut table = lua.load_table("a").unwrap(); let mut table = lua.load_table("a").unwrap();
for _ in range(0u, 10) { for _ in range(0u, 10) {
let tableContent: Vec<Option<(uint, uint)>> = table.iter().collect(); let table_content: Vec<Option<(uint, uint)>> = table.iter().collect();
assert_eq!(tableContent, vec!( Some((1,9)), Some((2,8)), Some((3,7)) )); assert_eq!(table_content, vec!( Some((1,9)), Some((2,8)), Some((3,7)) ));
} }
} }