mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 07:24:07 +01:00
Add op_hello
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use deno_ast::{MediaType, ParseParams, SourceTextInfo};
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::{Extension, JsRuntime, ModuleSource, ModuleType, RuntimeOptions};
|
||||
use deno_core::{op, Extension, JsRuntime, ModuleSource, ModuleType, RuntimeOptions};
|
||||
use std::rc::Rc;
|
||||
|
||||
use deno_core::futures::FutureExt;
|
||||
@@ -11,7 +11,9 @@ pub fn run_plugin_sync(file_path: &str) -> Result<(), AnyError> {
|
||||
}
|
||||
|
||||
pub async fn run_plugin(file_path: &str) -> Result<(), AnyError> {
|
||||
let extension = Extension::builder("pluginjs").ops(vec![]).build();
|
||||
let extension = Extension::builder("runtime")
|
||||
.ops(vec![op_hello::decl()])
|
||||
.build();
|
||||
|
||||
// Initialize a runtime instance
|
||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||
@@ -31,6 +33,13 @@ pub async fn run_plugin(file_path: &str) -> Result<(), AnyError> {
|
||||
result.await?
|
||||
}
|
||||
|
||||
#[op]
|
||||
async fn op_hello(name: String) -> Result<String, AnyError> {
|
||||
let contents = format!("Hello {} from Rust!", name);
|
||||
println!("{}", contents);
|
||||
Ok(contents)
|
||||
}
|
||||
|
||||
struct TsModuleLoader;
|
||||
|
||||
impl deno_core::ModuleLoader for TsModuleLoader {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
(function (globalThis) {
|
||||
Deno.core.initializeAsyncOps();
|
||||
|
||||
function argsToMessage(...args) {
|
||||
return args.map((arg) => JSON.stringify(arg)).join(' ');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user