

As an option we have GlobalPropertyJSON to pass data as JSON to/from JavaScript. You can use GlobalProperty(name) to get and set values in variables linked to the global namespace in JavaScript. If you need, you can call a function explicitly without evaluating using the CallFunction
Xojo msgbox code#
Params.Append 5 // one too much -> will be ignoredĭim r As Variant = j.CallFunction( "adder", params)Īs an advantage function we have functions to save the byte code for the JavaScript functions and restore it later with LoadFunction method. J.AddFunction "adder", "function (x,y) "ĭim r As Variant = j.CallFunction( "adder", 2, 3 ) J.RegisterFunction "MessageBox", AddressOf MessageBox, 1, Nil We can pass a fixed or variable number of parameters and a tag value: This uses a delegate pointing to a Xojo method in your class or module. With RegisterFunction you can add a custom function which calls back to a Xojo function. We compile the JavaScript and put it in the global name space.

We have a method AddFunction to add a custom function defined as JavaScript. Third function for yield is to give time to other Xojo threads if a you run JavaScript in a thread. The Input event works similar, but passes back the result from Xojo back to JavaScript and converts the types back. The print command will raise the Print event and allow you to implement a print command for JavaScript to write to a log window. If something goes wrong you may get a JavaScriptEngineExceptionMBS exception raised, so it may be good to wrap it in a try & catch block.įor your convenience we define a Print, Input and Yield function in JavaScript. Alternative you can use EvaluateToString which converts result to string. The variant will now contain the number 5. For your convenience we convert between JavaScript data types and Xojo's variant data type. Then you can evaluate some JavaScript code and get back a result. You can use JavaScriptEngineMBS class in next plugin version and instantiate a JavaScript environment. If you need, you can run JavaScript snippets at runtime to do calculations and even integrate your own functions to call back to Xojo. You can execute JavaScript similar to the XojoScript control and offer it to your users as a scripting language within your solution. For next MBS Xojo Plugins we add a JavaScript engine to be used within your Xojo application without a HTMLViewer control.
