is there a way to call Microscript function inside //javascript code?

anyone knows a solution?

In my opinion it is not possible! A function in MicroScript is really bytecode executed by JavaScript code (virtual processor). You would need to call this processor with parameters from javascript to jump to this function.

I've tried calling functions and objects.

I use microScript functions as a callback for the JS-library in my AnimeJS Library.

Here the helper function that Gilles created to be able to do so, might help you?

// javascript   

// global.jsfunc() allows to hand over ms functions
// as a callback reference to js 
// Example - 
// Javascript original:
// anime({
//   posx: function(){return anime.random(-50,50);},
//   loop: true
//   complete: animateBlocks       // ms function
// }) 
// microStudio verison:
// anime(object
//   posx     = jsfunc(function() anime.random(-50,50) end)
//   loop     = js.true
//   complete = jsfunc(animateBlocks)    // microStudio function !
// end)

global.jsfunc = function(ms_func) { return ms_func ; }

Well, I looked like a fool.

I thought that to do this you need to dig into the MicroScript structure, analyze the bytecode interpreter, parse the source code, etc...

I tried passing parameters through object "global" - it didn't work. Many javascript libraries need this communication and this prevented them from being used with MicroScript.

And here is one function - and it works.

Yeah, it is really useful when you don't want to write everything in JS.

I forgot, this belongs to the above:

// javascript 
// global.js returns 'strict' true/false values for
// js libraries that do not accept 0/1 instead
// usage:    loop = js.true

global.js = { "true": true , "false": false }; 

It allows to send 'true/false' statements to JS that it will accept (It doesn't like the ms 0/1)

Is it necessary to create an "object" structure with these posx, loop, complete fields?

I passed only the result of the jsfunc(funcName) function to the javascript code and it still works. So I'm wondering what the minimum code is to make it work correctly for all cases.

On the discord in the #babylon channel @Gilles went into a bit more detail about mS functions and how to hand them over to JS.

Post a reply



Validate your e-mail address to participate in the community