Work on macro binding generation, some cleanup needed, rename runner to plugin
This commit is contained in:
parent
dda6dcb3b8
commit
f6a9558c5c
22 changed files with 330 additions and 59 deletions
7
crates/plugin_runtime/plugin/cargo_test/Cargo.lock
generated
Normal file
7
crates/plugin_runtime/plugin/cargo_test/Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cargo_test"
|
||||
version = "0.1.0"
|
9
crates/plugin_runtime/plugin/cargo_test/Cargo.toml
Normal file
9
crates/plugin_runtime/plugin/cargo_test/Cargo.toml
Normal file
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "cargo_test"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = "1.0"
|
||||
bincode = "1.3"
|
||||
plugin = { path = "../../../plugin" }
|
34
crates/plugin_runtime/plugin/cargo_test/src/main.rs
Normal file
34
crates/plugin_runtime/plugin/cargo_test/src/main.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use core::slice;
|
||||
use plugin::prelude::*;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn banana(ptr: *const u8, len: usize) -> *const Buffer {
|
||||
// setup
|
||||
let buffer = Buffer { ptr, len };
|
||||
let data = unsafe { buffer.to_vec() };
|
||||
// operation
|
||||
// let reversed: Vec<u8> = data.into_iter().rev().collect();
|
||||
let number: f64 = bincode::deserialize(&data).unwrap();
|
||||
let new_number = number * 2.0;
|
||||
let new_data = bincode::serialize(&new_number).unwrap();
|
||||
// teardown
|
||||
let new_buffer = unsafe { Buffer::from_vec(new_data) };
|
||||
return new_buffer.leak_to_heap();
|
||||
}
|
||||
|
||||
pub fn banana2(number: f64) -> f64 {
|
||||
number * 2.0
|
||||
}
|
||||
|
||||
#[bind]
|
||||
pub fn sum_lengths(strings: Vec<String>) -> usize {
|
||||
let mut total = 0;
|
||||
for string in strings {
|
||||
total += string.len();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
pub fn main() -> () {
|
||||
()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue