Skip to content

[specification] Dynamic Linking to Rust Functions #100

@mrodz

Description

@mrodz

MScript

call_rust_function: fn(a: int, b: int) -> int = symbol "add_ints" : "path/to/my_lib.dll"

assert call_rust_function(5, 10) == 15

Rust

use bytecode::BytecodePrimitive;
use bytecode::{int, raise_error};
use bytecode::FFIReturnValue;

#[no_mangle]
pub fn adder(args: &[BytecodePrimitive]) -> FFIReturnValue {
    let (Some(BytecodePrimitive::Int(x)), Some(BytecodePrimitive::Int(y))) = (args.get(0), args.get(1)) else {
        raise_error!("cannot add two non-ints!")
    };

    let result = x + y;

    println!("hello from rust!!! the answer is {result}");

    FFIReturnValue::Value(int!(result))
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bytecodeIssues related to bytecodecompilerIssues related to compilation & parsingenhancementNew feature or requesthigh priorityThis issue is required for the next release

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions