rust/hedgewars-engine/src/main.rs
author sheepluva
Tue, 22 Jun 2021 22:13:55 +0200
changeset 15824 d5c37e78ab83
parent 14187 7d3b94cdc3c4
child 15827 61da40b657fa
permissions -rw-r--r--
hedgewars-engine (rust): fix "protocol_version" -> "hedgewars_engine_protocol_version" That function/symbol was renamed in ef2fc0210362
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     1
extern crate libloading;
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     2
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     3
use libloading::{Library, Symbol};
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     4
use std::ops::Deref;
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     5
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     6
struct EngineInstance {}
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     7
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     8
struct Engine<'a> {
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
     9
    protocol_version: Symbol<'a, unsafe fn() -> u32>,
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    10
    start_engine: Symbol<'a, unsafe fn() -> *mut EngineInstance>,
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    11
    cleanup: Symbol<'a, unsafe fn(engine_state: *mut EngineInstance)>,
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    12
}
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    13
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    14
fn main() {
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    15
    let hwlib = Library::new("libhedgewars_engine.so").unwrap();
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    16
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    17
    unsafe {
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    18
        let engine = Engine {
15824
d5c37e78ab83 hedgewars-engine (rust): fix "protocol_version" -> "hedgewars_engine_protocol_version"
sheepluva
parents: 14187
diff changeset
    19
            protocol_version: hwlib.get(b"hedgewars_engine_protocol_version").unwrap(),
14187
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    20
            start_engine: hwlib.get(b"start_engine").unwrap(),
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    21
            cleanup: hwlib.get(b"cleanup").unwrap(),
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    22
        };
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    23
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    24
        println!("Hedgewars engine, protocol version {}", engine.protocol_version.deref()());
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    25
    }
7d3b94cdc3c4 - Move hedgewars-engine into lib-hedgewars-engine
unc0rr
parents:
diff changeset
    26
}