1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use libc::*;
use std::mem;
use std::ptr;
use std::process;
use std::thread::spawn;
use ffi::*;
static mut global_main_func: Option<extern "Rust" fn()> = None;
pub fn run(main_func: extern "Rust" fn()) -> !
{
unsafe
{
global_main_func = Some(main_func);
let ret = al_run_main(0, ptr::null(), mem::transmute(allegro_main));
process::exit(ret)
}
}
extern "C"
fn allegro_main(_: isize, _: *const *const u8) -> c_int
{
unsafe
{
let ok = spawn(move ||
{
(global_main_func.unwrap())();
}).join().is_ok();
al_uninstall_system();
if ok
{
0
}
else
{
1
}
}
}