Skip to content

Commit

Permalink
Merge pull request PistonDevelopers#294 from bjz/rustup
Browse files Browse the repository at this point in the history
Update to latest rustc
  • Loading branch information
kvark committed Feb 21, 2015
2 parents b76c7d5 + 72f2cf3 commit addd417
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "glfw"
version = "0.0.3"
version = "0.0.4"
authors = ["The glfw-rs developers."]
description = "GLFW3 bindings and idiomatic wrapper for Rust."
keywords = ["windowing", "opengl"]
Expand Down
8 changes: 4 additions & 4 deletions examples/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ fn main() {

fn handle_window_event(window: &mut glfw::Window, (time, event): (f64, glfw::WindowEvent)) {
match event {
glfw::WindowEvent::Pos(x, y) => window.set_title(format!("Time: {:?}, Window pos: ({:?}, {:?})", time, x, y).as_slice()),
glfw::WindowEvent::Size(w, h) => window.set_title(format!("Time: {:?}, Window size: ({:?}, {:?})", time, w, h).as_slice()),
glfw::WindowEvent::Pos(x, y) => window.set_title(&format!("Time: {:?}, Window pos: ({:?}, {:?})", time, x, y)),
glfw::WindowEvent::Size(w, h) => window.set_title(&format!("Time: {:?}, Window size: ({:?}, {:?})", time, w, h)),
glfw::WindowEvent::Close => println!("Time: {:?}, Window close requested.", time),
glfw::WindowEvent::Refresh => println!("Time: {:?}, Window refresh callback triggered.", time),
glfw::WindowEvent::Focus(true) => println!("Time: {:?}, Window focus gained.", time),
Expand All @@ -71,10 +71,10 @@ fn handle_window_event(window: &mut glfw::Window, (time, event): (f64, glfw::Win
glfw::WindowEvent::FramebufferSize(w, h) => println!("Time: {:?}, Framebuffer size: ({:?}, {:?})", time, w, h),
glfw::WindowEvent::Char(character) => println!("Time: {:?}, Character: {:?}", time, character),
glfw::WindowEvent::MouseButton(btn, action, mods) => println!("Time: {:?}, Button: {:?}, Action: {:?}, Modifiers: [{:?}]", time, glfw::DebugAliases(btn), action, mods),
glfw::WindowEvent::CursorPos(xpos, ypos) => window.set_title(format!("Time: {:?}, Cursor position: ({:?}, {:?})", time, xpos, ypos).as_slice()),
glfw::WindowEvent::CursorPos(xpos, ypos) => window.set_title(&format!("Time: {:?}, Cursor position: ({:?}, {:?})", time, xpos, ypos)),
glfw::WindowEvent::CursorEnter(true) => println!("Time: {:?}, Cursor entered window.", time),
glfw::WindowEvent::CursorEnter(false) => println!("Time: {:?}, Cursor left window.", time),
glfw::WindowEvent::Scroll(x, y) => window.set_title(format!("Time: {:?}, Scroll offset: ({:?}, {:?})", time, x, y).as_slice()),
glfw::WindowEvent::Scroll(x, y) => window.set_title(&format!("Time: {:?}, Scroll offset: ({:?}, {:?})", time, x, y)),
glfw::WindowEvent::Key(key, scancode, action, mods) => {
println!("Time: {:?}, Key: {:?}, ScanCode: {:?}, Action: {:?}, Modifiers: [{:?}]", time, key, scancode, action, mods);
match (key, action) {
Expand Down
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#![crate_type = "dylib"]
#![crate_name = "glfw"]

#![feature(core)]
#![feature(std_misc)]
#![feature(unsafe_destructor)]

#![allow(non_upper_case_globals)]
Expand Down Expand Up @@ -72,7 +74,7 @@ extern crate bitflags;

use libc::{c_char, c_double, c_float, c_int};
use libc::{c_ushort, c_void};
use std::ffi::CString;
use std::ffi::{CStr, CString};
use std::mem;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::fmt;
Expand Down Expand Up @@ -505,7 +507,7 @@ impl Glfw {
let mut count = 0;
let ptr = ffi::glfwGetMonitors(&mut count);
f(self,
slice::from_raw_buf(&(ptr as *const _), count as usize).iter().map(|&ptr| {
slice::from_raw_parts(ptr as *const _, count as usize).iter().map(|&ptr| {
Monitor {
ptr: ptr
}
Expand Down Expand Up @@ -732,14 +734,13 @@ pub fn get_version() -> Version {

/// Replacement for `String::from_raw_buf`
pub unsafe fn string_from_c_str(c_str: *const c_char) -> String {
use std::ffi::c_str_to_bytes;
String::from_utf8_lossy(c_str_to_bytes(&c_str)).into_owned()
String::from_utf8_lossy(CStr::from_ptr(c_str).to_bytes()).into_owned()
}

/// Replacement for `ToCStr::with_c_str`
pub fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const c_char) -> T {
let c_str = CString::from_slice(s.as_bytes());
f(c_str.as_slice_with_nul().as_ptr())
let c_str = CString::new(s.as_bytes());
f(c_str.unwrap().as_bytes_with_nul().as_ptr() as *const _)
}

/// Wrapper for `glfwGetVersionString`.
Expand Down Expand Up @@ -794,7 +795,7 @@ impl Monitor {
unsafe {
let mut count = 0;
let ptr = ffi::glfwGetVideoModes(self.ptr, &mut count);
slice::from_raw_buf(&ptr, count as usize).iter().map(VidMode::from_glfw_vid_mode).collect()
slice::from_raw_parts(ptr, count as usize).iter().map(VidMode::from_glfw_vid_mode).collect()
}
}

Expand All @@ -815,11 +816,11 @@ impl Monitor {
unsafe {
let llramp = *ffi::glfwGetGammaRamp(self.ptr);
GammaRamp {
red: slice::from_raw_buf(&(llramp.red as *const c_ushort), llramp.size as usize)
red: slice::from_raw_parts(llramp.red as *const c_ushort, llramp.size as usize)
.iter().map(|&x| x).collect(),
green: slice::from_raw_buf(&(llramp.green as *const c_ushort), llramp.size as usize)
green: slice::from_raw_parts(llramp.green as *const c_ushort, llramp.size as usize)
.iter().map(|&x| x).collect(),
blue: slice::from_raw_buf(&(llramp.blue as *const c_ushort), llramp.size as usize)
blue: slice::from_raw_parts(llramp.blue as *const c_ushort, llramp.size as usize)
.iter().map(|&x| x).collect(),
}
}
Expand Down Expand Up @@ -1099,7 +1100,7 @@ pub fn flush_messages<'a, Message: Send>(receiver: &'a Receiver<Message>) -> Flu
/// `Receiver`'s queue.
pub struct FlushedMessages<'a, Message: 'a>(&'a Receiver<Message>);

impl<'a, Message: Send> Iterator for FlushedMessages<'a, Message> {
impl<'a, Message: 'static + Send> Iterator for FlushedMessages<'a, Message> {
type Item = Message;

fn next(&mut self) -> Option<Message> {
Expand Down Expand Up @@ -1649,7 +1650,7 @@ impl Joystick {
unsafe {
let mut count = 0;
let ptr = ffi::glfwGetJoystickAxes(self.id as c_int, &mut count);
slice::from_raw_buf(&ptr, count as usize).iter().map(|&a| a as f32).collect()
slice::from_raw_parts(ptr, count as usize).iter().map(|&a| a as f32).collect()
}
}

Expand All @@ -1658,7 +1659,7 @@ impl Joystick {
unsafe {
let mut count = 0;
let ptr = ffi::glfwGetJoystickButtons(self.id as c_int, &mut count);
slice::from_raw_buf(&ptr, count as usize).iter().map(|&b| b as c_int).collect()
slice::from_raw_parts(ptr, count as usize).iter().map(|&b| b as c_int).collect()
}
}

Expand Down

0 comments on commit addd417

Please sign in to comment.