Skip to content

Instantly share code, notes, and snippets.

View bstrie's full-sized avatar

bstrie bstrie

View GitHub Profile
struct Struct_lua_Debug {
event: c_int,
name: *c_schar,
namewhat: *c_schar,
what: *c_schar,
source: *c_schar,
currentline: c_int,
linedefined: c_int,
lastlinedefined: c_int,
nups: c_uchar,
/* automatically generated by rust-bindgen */
use libc::*;
type Struct_lua_State = c_void;
type lua_State = Struct_lua_State;
type lua_CFunction = *u8;
type lua_Reader = *u8;
type lua_Writer = *u8;
type lua_Alloc = *u8;
type lua_Number = c_double;
fn with<T, U, V>(foo: fn() -> U, bar: fn(U) -> V) {
bar(foo());
}
fn open() -> int {
return 1;
}
fn main() {
do with(open) |f| {
fn mk_appender(suffix: ~str) -> fn@(~str) -> ~str {
return fn@(s: ~str) -> ~str { s + suffix };
}
fn main() {
let shout = mk_appender(~"!");
io::println(shout(~"hey ho, let's go"));
}
@bstrie
bstrie / bad
Created October 12, 2012 23:49
fn mk_appender(suffix: ~str) -> @fn(~str) -> ~str {
return @fn(s: ~str) -> ~str { s + suffix }; // error: mismatched types: expected `fn@(~str) -> ~str` but found `@fn&(~str) -> ~str` (expected fn but found @-ptr)
}
fn main() {
let shout = mk_appender(~"!");
io::println(shout(~"hey ho, let's go"));
}
const bar: int = 1,
foo: int = 4;
fn main() {
let baz: int = 0,
qux: int = 1;
}
fn main() {
let x = 1;
let f = fn@() -> int {
return x+20;
};
let mut x = move x;
io::println(f().to_str());
x += 1;
io::println(f().to_str());
}
struct Vec2 {
x: f32,
y: f32,
}
#[inline(always)]
fn lerp(a: f32, b: f32, v: f32) -> f32 {
a * (1f32 - v) + b * v
}
match x {
x < 0 => -1,
x > 0 => 1,
0
}
@bstrie
bstrie / gist:3975337
Created October 29, 2012 18:07
Rust stdin example
use io::ReaderUtil;
fn main () {
let stdin = io::stdin();
let raw_input = stdin.read_line();
io::println(raw_input);
}