Skip to content

Instantly share code, notes, and snippets.

View bvssvni's full-sized avatar

Sven Nilsen bvssvni

View GitHub Profile
mkdir -p lib
rustc --out-dir=lib --link-args="-lglfw3 -lrt -lXrandr -lXi -lGL -lm -ldl -lXrender -ldrm -lXdamage -lX11-xcb -lxcb-glx -lXxf86vm -lXfixes -lXext -lX11 -lpthread -lxcb -lXau -lXdmcp " -O src/lib/lib.rs
error: linking with `cc` failed: exit code: 1
note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'lib/libglfw-rs-c68009f4-0.1.so' 'lib/glfw-rs.o' 'lib/glfw-rs.metadata.o' '-Wl,--as-needed' '-Wl,-O1' '-L/home/sven/Desktop/opensource/glfw-rs/.rust' '-L/home/sven/Desktop/opensource/glfw-rs' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lstd-966edb7e-0.10-pre' '-ldl' '-lm' '-lpthread' '-shared' '-lmorestack' '-Wl,-rpath,$ORIGIN/../../../../../../usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lglfw3' '-lrt' '-lXrandr' '-lXi' '-lGL' '-lm' '-ldl' '-lXrender' '-ldrm' '-lXdamage' '-lX11-xcb' '-lxcb-glx' '-lXxf86vm' '-lXfixes' '-lXext' '-lX11' '-lpthread' '-lxcb' '-lXau' '-lXdmcp'
note: /
struct Test<T> {
a: T
}
pub fn test_int<'a>(a: &'a int) -> Test<&'a int> {
Test { a: a }
}
fn main() {
let a = 42;
glfw::set_error_callback(~ErrorContext);
glfw::start(proc() {
let monitor = glfw::Monitor::get_primary().unwrap();
let window_mode = glfw::FullScreen(monitor);
let (w, h) = (1024, 768); // monitor.get_physical_size();
let window = glfw::Window::create(w as u32, h as u32, "Hello this is window", window_mode)
.expect("Failed to create GLFW window.");
window.set_key_polling(true);
pub struct A {
a: int
}
pub struct B {
b: int
}
pub trait GetValue {
fn get_value(&self) -> int;
pub struct Test<'a> {
function: 'a ||
}
fn main() {
let sayhello = || println!("Hello!");
let test = Test { function: sayhello };
(test.function)();
}
pub struct Test<'a> {
function: 'a ||
}
fn main() {
// x outlives 'test.function' because of lifetime constraint.
let x = 42;
let sayhello = || println!("{}", x);
let test = Test { function: sayhello };
pub struct Test<'a> {
function: 'a ||
}
fn main() {
let mut parent = Test { function: || () };
{
let x = 42;
let sayhello = || println!("{}", x);
@bvssvni
bvssvni / gist:9304940
Last active August 29, 2015 13:56
A simple stack based evaluator
//! A simple stack based evaluator.
//! You can modify this code to create your own domain specific language.
//!
//! Terminology:
//! - A 'stack' here is represented as a vector.
//! - The 'top' of the stack means the end of the vector.
//!
//! In this example we will create a language that evaluates:
//!
//! Point3D
fn main() {
let a: *int = &182323;
let b: *int = &102932;
let c = a as uint - b as uint;
// Prints '16'.
println!("{}", c);
}
@bvssvni
bvssvni / gist:9327294
Last active August 29, 2015 13:56
Emulating dynamic types: How to implement Any for owned Trait pointers
//!
//! >rustc --version
//! rustc 0.10-pre (ee8f45e 2014-02-18 13:41:49 -0800)
//!
//! In this example we will implement Any for a trait pointer.
//! This is useful when we want to design an Entity/Component system
//! that is extensible beyond the library.
//!
//! As example we have two objects 'Player' and 'Enemy'.
//! Both implement the trait 'Entity' which is used 90% of the time.