feat: add some shit
This commit is contained in:
parent
738bc1cf7a
commit
b54370bec0
@ -1,9 +1,20 @@
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn execute(a: u32, b: u32) -> u32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
const DEFINITION: &str = include_str!("./node.json");
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn get_definition() -> String {
|
||||
include_str!("./node.json").to_string()
|
||||
pub fn get_definition() -> *mut c_char {
|
||||
let s = CString::new(DEFINITION).unwrap();
|
||||
s.into_raw()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn get_definition_len() -> usize {
|
||||
DEFINITION.len()
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
use std::fs;
|
||||
use std::{
|
||||
ffi::{c_char, CStr},
|
||||
fs,
|
||||
};
|
||||
use wasmtime::*;
|
||||
|
||||
pub struct NodeRegistryCore {
|
||||
@ -17,10 +20,41 @@ impl NodeRegistryCore {
|
||||
_author: &str,
|
||||
_namespace: &str,
|
||||
node_id: &str,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let bytes = self.get_node(_author, _namespace, node_id);
|
||||
) -> Result<String, String> {
|
||||
let bytes = self.get_node(_author, _namespace, node_id)?;
|
||||
|
||||
let engine = Engine::default();
|
||||
let mut store = Store::new(&engine, ());
|
||||
let module = Module::new(&engine, bytes).map_err(|err| {
|
||||
println!("{}", err);
|
||||
err.to_string()
|
||||
})?;
|
||||
let instance = Instance::new(&mut store, &module, &[]).map_err(|_| "asd".to_string())?;
|
||||
|
||||
let get_definition_len = instance
|
||||
.get_func(&mut store, "get_definition_len")
|
||||
.ok_or("Failed to find 'get_definition_len' function export")?;
|
||||
let get_definition_len_func = get_definition_len
|
||||
.typed::<(), i32>(&store)
|
||||
.map_err(|err| err.to_string())?;
|
||||
let len = get_definition_len_func
|
||||
.call(&mut store, ())
|
||||
.map_err(|err| err.to_string())?;
|
||||
|
||||
// Access the exports
|
||||
let get_definition_ptr = instance
|
||||
.get_func(&mut store, "get_definition")
|
||||
.ok_or("Failed to find 'get_definition' function export")?;
|
||||
let get_definition_func = get_definition_ptr
|
||||
.typed::<(), i32>(&store)
|
||||
.map_err(|err| err.to_string())?;
|
||||
let ptr = get_definition_func
|
||||
.call(&mut store, ())
|
||||
.map_err(|err| err.to_string())?;
|
||||
|
||||
println!("{} {}", ptr, len);
|
||||
|
||||
Ok("Dude".to_string())
|
||||
}
|
||||
|
||||
// Function that takes a string and returns bytes
|
||||
|
@ -17,7 +17,13 @@ async fn get_node(req: Request<()>) -> tide::Result {
|
||||
let node_registry = NodeRegistryCore::new("../../target/wasm32-unknown-unknown/release");
|
||||
|
||||
if node_id.ends_with(".json") {
|
||||
Ok("asd".into())
|
||||
let res =
|
||||
node_registry.get_node_definition(author, namespace, &node_id.replace(".json", ""));
|
||||
|
||||
match res {
|
||||
Ok(res) => Ok(format!("Hello {}", res).into()),
|
||||
Err(er) => Ok(format!("Err: {}", er).into()),
|
||||
}
|
||||
} else {
|
||||
let res = node_registry.get_node(author, namespace, node_id);
|
||||
|
||||
|
@ -69,6 +69,9 @@ importers:
|
||||
vite:
|
||||
specifier: ^5.0.0
|
||||
version: 5.1.4
|
||||
vite-plugin-glsl:
|
||||
specifier: ^1.2.1
|
||||
version: 1.2.1(vite@5.1.4)
|
||||
|
||||
packages/types: {}
|
||||
|
||||
@ -652,7 +655,6 @@ packages:
|
||||
estree-walker: 2.0.2
|
||||
picomatch: 2.3.1
|
||||
rollup: 4.12.0
|
||||
dev: false
|
||||
|
||||
/@rollup/rollup-android-arm-eabi@4.12.0:
|
||||
resolution: {integrity: sha512-+ac02NL/2TCKRrJu2wffk1kZ+RyqxVUlbjSagNgPm94frxtr+XDL12E5Ll1enWskLrtrZ2r8L3wED1orIibV/w==}
|
||||
@ -1554,7 +1556,6 @@ packages:
|
||||
|
||||
/estree-walker@2.0.2:
|
||||
resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}
|
||||
dev: false
|
||||
|
||||
/estree-walker@3.0.3:
|
||||
resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==}
|
||||
@ -3440,6 +3441,18 @@ packages:
|
||||
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
|
||||
dev: false
|
||||
|
||||
/vite-plugin-glsl@1.2.1(vite@5.1.4):
|
||||
resolution: {integrity: sha512-yBpBHWfdiRVMxN3yIKx4qmwuqMwoMAnEMipVI0NbdIieyRFO8hpW8VTFHYi3W75h7CkvsotteP9C4pln51OE0A==}
|
||||
engines: {node: '>= 16.15.1', npm: '>= 8.11.0'}
|
||||
peerDependencies:
|
||||
vite: ^3.0.0 || ^4.0.0 || ^5.0.0
|
||||
dependencies:
|
||||
'@rollup/pluginutils': 5.1.0(rollup@4.12.0)
|
||||
vite: 5.1.4
|
||||
transitivePeerDependencies:
|
||||
- rollup
|
||||
dev: true
|
||||
|
||||
/vite@5.1.4:
|
||||
resolution: {integrity: sha512-n+MPqzq+d9nMVTKyewqw6kSt+R3CkvF9QAKY8obiQn8g1fwTscKxyfaYnC632HtBXAQGc1Yjomphwn1dtwGAHg==}
|
||||
engines: {node: ^18.0.0 || >=20.0.0}
|
||||
|
Loading…
Reference in New Issue
Block a user