Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I try to call a javascript function from rust. It does not work #869

Closed
kiyingitimo opened this issue Dec 25, 2024 · 3 comments
Closed

Comments

@kiyingitimo
Copy link

This is my js code

import { createApp } from 'vue'
import App from './App.vue'

function on_init() {
    console.log("Ready")
}


register_plugin = function (importObject) {
    importObject.env.perform_demo = function () {
        console.log("Called from rust")
    };
}

miniquad_add_plugin({ register_plugin, on_init });

createApp(App).mount('#app')

It's supposed to register a function to be called by Rust later on in this code

extern "C" {
    fn perform_demo();
}

#[macroquad::main("Coder")]
async fn main() {
    unsafe {
        perform_demo();
    }

It continues to give this in the console
image

@InnocentusLime
Copy link
Contributor

Hello! How and where do you launch your macroquad application?

You must make sure load() is called after all miniquad_add_plugin calls. Otherwise your function will not be imported.

@kiyingitimo
Copy link
Author

Thank you. That does the trick

@InnocentusLime
Copy link
Contributor

Thank you. That does the trick

Nice! If the issue is resolved, I suggest closing it :)

@not-fl3 not-fl3 closed this as completed Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants