Skip to content

Instantly share code, notes, and snippets.

View luqmana's full-sized avatar

Luqman Aden luqmana

View GitHub Profile
> % rustc hello.rs --target=psp -lpspdebug -lpspdisplay -lpspge -lm -lc -lpspuser -lgcc
> % psp-fixup-imports hello && psp-prxgen hello hello.prx

Or what the hell do #![no_start], #![no_main], #[lang = "start"], #[start], and #[main] do?

Crate Attributes:

#![no_start]

Disable automatically linking in the native crate and thus the default start lang item.

Which means you'll probably need one of: #![no_main], #![lang = “start”] or #[start] instead

@luqmana
luqmana / gist:2d688d81fed84caba0a6
Created May 2, 2014 05:16
Ident Server in Rust

Simple Ident Server in Rust

This is a quick example of a simple TCP server written (mostly) in Rust which implements RFC 1413. It has a bit of networking, regex, and FFI.

All code examples have been written against a recent build from git: rustc 0.11-pre (9f484e6 2014-04-30 15:46:47 -0700)

To start off, how about we flesh out the general structure a little:

@luqmana
luqmana / rotl.rs
Last active December 27, 2015 21:09
#![feature(asm, macro_rules)]
use std::mem;
fn rotl(val: u64, shift: u8) -> u64 {
let sz = mem::size_of_val(&val);
(val << shift) | (val >> (sz * 8 - shift as uint))
}
@luqmana
luqmana / build
Last active December 24, 2015 05:09
-> % rustc foo.rs --lib -Z extra-debug-info
-> % ls
foo.c foo.rs libfoo-102129e09d96658-0.0.so
-> % gcc foo.c -g -L. -lfoo-102129e09d96658-0.0 -o foo
-> % LD_LIBRARY_PATH=. ./foo
[1] 30770 segmentation fault LD_LIBRARY_PATH=. ./foo
@luqmana
luqmana / foo.c
Created September 19, 2013 18:58
extern int foobar __attribute__((weak));
int main(int argc, char *argv[]) {
return foobar;
}
#[simd]
struct F(f32, f32);
static A: F = F(2.0, 3.5);
fn main() {
}
@luqmana
luqmana / rj.rs
Last active December 21, 2015 06:28
extern mod sdl;
use std::libc::{c_int, c_void};
use std::rt::comm;
use std::rt::io::extensions::*;
use std::rt::io::io_error;
use std::rt::io::net::ip::{IpAddr, Ipv4Addr, Port, SocketAddr};
use std::rt::io::net::tcp::TcpStream;
use std::task;
use std::vec;
~"register_foreign_item_fn(abis=\"C\", path=[cmath, c_float_utils, ceil], foreign_item.id=153330)"
~"trans_native_call(callee_ty=extern \"C\" unsafe fn(f32) -> f32, llfn=*fn(Float) -> Float, llretptr=*Float)"
~"argument 0, llarg_rust=Float, rust_indirect=false, arg_ty=Float"
~"llarg_rust=*Float (after indirection)"
~"llarg_rust=*Float (after casting)"
~"argument 0, llarg_foreign=Float"
~"llretptr=*Float"
~"llforeign_retval=Float"
~"llrust_ret_ty=Float"
~"llforeign_ret_ty=Float"