mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 16:48:30 +02:00
Add op_hello
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
console.log('---------------------------');
|
console.log('---------------------------');
|
||||||
console.log('- 👋 Hello from plugin.ts -');
|
console.log('- 👋 Hello from plugin.ts -');
|
||||||
console.log('---------------------------');
|
console.log('---------------------------');
|
||||||
|
|
||||||
|
Deno.core.ops.op_hello('World');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use deno_ast::{MediaType, ParseParams, SourceTextInfo};
|
use deno_ast::{MediaType, ParseParams, SourceTextInfo};
|
||||||
use deno_core::error::AnyError;
|
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 std::rc::Rc;
|
||||||
|
|
||||||
use deno_core::futures::FutureExt;
|
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> {
|
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
|
// Initialize a runtime instance
|
||||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||||
@@ -31,6 +33,13 @@ pub async fn run_plugin(file_path: &str) -> Result<(), AnyError> {
|
|||||||
result.await?
|
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;
|
struct TsModuleLoader;
|
||||||
|
|
||||||
impl deno_core::ModuleLoader for TsModuleLoader {
|
impl deno_core::ModuleLoader for TsModuleLoader {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
(function (globalThis) {
|
(function (globalThis) {
|
||||||
|
Deno.core.initializeAsyncOps();
|
||||||
|
|
||||||
function argsToMessage(...args) {
|
function argsToMessage(...args) {
|
||||||
return args.map((arg) => JSON.stringify(arg)).join(' ');
|
return args.map((arg) => JSON.stringify(arg)).join(' ');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user