Platforms to show: All Mac Windows Linux Cross-Platform
JavaScriptEngineMBS class
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
class | JavaScript | MBS Tools Plugin | 20.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
We use DukTape, an embeddable Javascript engine, with a focus on portability and compact footprint.
https://duktape.org
Your own JavaScript engine is useful for:
- Running some snippet of JavaScript code without HTMLViewer.
- Using various JavaScript libraries
- Providing a scripting language to your own application.
- An lightweight alternative to XojoScript.
- Working with JSON data
- Enjoy using regular expressions, unicode text functions, number parsing and formatting with no platform dependencies
MBS Plugin added Input(), Yield() and Print() functions for your convenience.
Yield will pass CPU control to other threads, so background tasks continue to run.
MBS Plugin can convert JavaScript values to variant.
Boolean -> Boolean
Number -> Double
String -> String
Buffer -> MemoryBlock
Pointer -> Ptr
Array -> Variant array
Object -> JSON string
null -> nil
We convert variant to JavaScript:
nil -> null
Int32, Int64, Single, Double, Currency -> Number
Boolean -> Boolean
String, Text, Date -> String
Ptr -> Pointer
all other -> undefined
This class is like XojoScript, but using JavaScript as language.
Warning: error handling is broken in version 21.1 of the MBS Plugin. Please update to 22.2 for a fix.
- 2 events
- 7 properties
- property Handle as Integer
- property MemoryBlocks as Dictionary
- property ObjectCount as Integer
- property StringCount as Integer
- property GlobalMemoryBlock(PropertyName as String) as MemoryBlock
- property GlobalProperty(PropertyName as String) as Variant
- property GlobalPropertyJSON(PropertyName as String) as String
- 16 methods
- method AddFunction(Name as String, JavaScript as String, FileName as String = "")
- method CallFunction(Name as String, ParamArray Params as Variant) as Variant
- method CallFunction(Name as String, Params() as Variant) as Variant
- method CallFunctionMT(Name as String, ParamArray Params as Variant) as Variant
- method CallFunctionMT(Name as String, Params() as Variant) as Variant
- method DateComponentsToTime(date as JavaScriptDateComponentsMBS) as Double
- method Destructor
- method Evaluate(JavaScript as String) as Variant
- method EvaluateMT(JavaScript as String) as Variant
- method EvaluateToString(JavaScript as String) as String
- method InitModules
- method LoadFunction(Name as String, Data as Memoryblock) as Boolean
- method Now as Double
- method RegisterFunction(Name as String, theDelegate as JavaScriptEngineDelegateMBS, ArgCount as Integer = -1, tag as Variant = nil)
- method SaveFunction(Name as String) as MemoryBlock
- method TimeToDateComponents(time as Double) as JavaScriptDateComponentsMBS
- delegate JavaScriptEngineDelegateMBS(Name as String, Params() as Variant, tag as Variant) as Variant
This class has no sub classes.
Some examples using this class:
- /Tools/JavaScript/JavaScript AES/JavaScript AES
- /Tools/JavaScript/JavaScript Engine
- /Tools/JavaScript/JavaScript Pixel Editing
- /Tools/JavaScript/LibPhoneNumber/JavaScript LibPhoneNumber
Blog Entries
- MBS Xojo Plugin, June 2021 News
- News from the MBS Xojo Plugins Version 20.1
- MonkeyBread Software Releases the MBS Xojo Plugins in version 20.1
- Multithreaded JavaScript usage
- Our JavaScript engine, a game changer
- Tips for our JavaScript functions
- Comparing JavaScriptEngineMBS to XojoScript
- New in the MBS Xojo Plugins 20.0
- MonkeyBread Software Releases the MBS Xojo Plugins in version 20.0
- Our JavaScript engine for Xojo
Xojo Developer Magazine
- 19.5, pages 92 to 93: JavaScript in Xojo, Running JavaScript in your Xojo apps by Stefanie Juchmes
- 19.4, page 9: News
- 18.3, page 47: Happy Birthday MonkeyBread Software, What is new in the MBS Xojo Plugins by Stefanie Juchmes
- 18.3, page 10: News
Videos
Release notes
- Version 24.0
- Improved JavaScriptEngineMBS class to handle arrays of Int32, Int64, Double, Single, Boolean, Color, String and Currency for conversion from Variant to JavaScript.
- Version 22.2
- Updated DukTape library for JavaScriptEngineMBS class to version 2.7.
- Version 21.2
- Added InitModules method for JavaScriptEngineMBS class.
- Fixed error handling in JavaScriptEngineMBS class, broken in v21.1.
- Version 21.1
- Updated DukTape library for JavaScriptEngineMBS class to version 2.6.
- Version 20.5
- Added code to detect if variant is unsigned, so we can handle UInt32/UInt64 correctly in BigNumberMBS, JavaScriptEngineMBS, SQLPreparedStatementMBS and SQLCommandMBS, SQLValueMBS, and JSONMBS classes and in CFDictionaryMBS/NSDictionary conversion.
- Version 20.2
- Fixed RegisterFunction in JavaScriptEngineMBS class for non MT usage.
- Version 20.1
- Added DateComponentsToTime, TimeToDateComponents and Now methods to JavaScriptEngineMBS class.
- Added EvaluateMT and CallFunctionMT methods to JavaScriptEngineMBS class.
- Added GlobalMemoryBlock property and MemoryBlocks dictionary to JavaScriptEngineMBS class.
- Added ObjectCount and StringCount properties to JavaScriptEngineMBS class.
- Improved JavaScriptEngineMBS to accept Memoryblocks passed as buffers to JavaScript. JavaScript code can work on memoryblock and later you pass it back to Xojo.
- Version 20.0
- Added JavaScriptEngineMBS class with DukTape JavaScript engine.
The items on this page are in the following plugins: MBS Tools Plugin.
JavaScriptEngineExceptionMBS - JavaShortArrayMBS