rust/hedgewars-engine/src/main.rs
author Wuzzy <Wuzzy2@mail.ru>
Sat, 02 Nov 2019 13:01:28 +0100
changeset 15506 5a30396f8fb2
parent 14171 7d3b94cdc3c4
permissions -rw-r--r--
ClimbHome: Change misleading Seed assignment to nil value This was "Seed = ClimbHome", but ClimbHome was a nil value. This code still worked as the engine interpreted the nil value as empty string. But it can be very misleading. This changeset makes the Seed assignment more explicit by assigning the empty string directly. The compability has been tested.

extern crate libloading;

use libloading::{Library, Symbol};
use std::ops::Deref;

struct EngineInstance {}

struct Engine<'a> {
    protocol_version: Symbol<'a, unsafe fn() -> u32>,
    start_engine: Symbol<'a, unsafe fn() -> *mut EngineInstance>,
    cleanup: Symbol<'a, unsafe fn(engine_state: *mut EngineInstance)>,
}

fn main() {
    let hwlib = Library::new("libhedgewars_engine.so").unwrap();

    unsafe {
        let engine = Engine {
            protocol_version: hwlib.get(b"protocol_version").unwrap(),
            start_engine: hwlib.get(b"start_engine").unwrap(),
            cleanup: hwlib.get(b"cleanup").unwrap(),
        };

        println!("Hedgewars engine, protocol version {}", engine.protocol_version.deref()());
    }
}