Code Monkey home page Code Monkey logo

sharedlib's Introduction

sharedlib Travis CI Appveyor CI

A cross-platform shared library loader.

(crates.io) (docs)

Based on libloading by Simonas Kazlauskas.

sharedlib is a crate for loading shared libraries at runtime. This is a useful primitive for implementing other things like plugins. The advantage of this crate over other shared library crates is that it provides both lifetime-bound and ref-counted libraries, and it allows both functions and data to be loaded.

Quickstart

To load a library you can use any of the Lib, LibTracked, or LibUnsafe structs. Each of these structs provides different guarantees. For more information about the guarantees they provide see the choosing your guarantees section in the docs. We use Lib for the examples below:

Calling a function in another library

unsafe {
    let path_to_lib = "examplelib.dll";
    let lib = try!(Lib::new(path_to_lib));
    let hello_world_symbol: Func<extern "C" fn()> = try!(lib.find_func("hello_world"));
    let hello_world = hello_world_symbol.get();
    hello_world();
}

Accessing data in another library

unsafe {
    let path_to_lib = "examplelib.dll";
    let lib = try!(Lib::new(path_to_lib));
    let my_usize_symbol: Data<usize> = try!(lib.find_data("my_usize"));
    let my_usize = my_usize_symbol.get();
    assert_eq!(*my_usize, 0);
}

Additional information

Plenty of additional information can be found in the docs.

sharedlib's People

Contributors

tyleo avatar nagisa avatar lilianmoraru avatar adamcrume avatar skade avatar mbrubeck avatar ktff avatar llogiq avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.