Skip to content

Can the modules exported by module_init be used directly by qjs? #462

@Lorangeve

Description

@Lorangeve

Can the modules exported by module_init be used directly by qjs?

#[rquickjs::module]
pub mod native_module {

    #[rquickjs::function]
    pub fn fib(n: i32) -> i32 {
        if n <= 0 {
            return 0;
        } else if n == 1 {
            return 1;
        } else {
            return fib(n - 1) + fib(n - 2);
        }
    }
}

test_fib.js:

import * as os from "qjs:os";

const isWin = os.platform === 'win32';
const { fib } = await import(`./fib.${isWin ? 'dll' : 'so'}`);

console.log("Hello World");
console.log("fib(10)=", fib(10));

run it:

qjs test_fib.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:questionUnclear usage of the library

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions