Platforms to show: All Mac Windows Linux Cross-Platform

JavaScriptEngineMBS class

Type Topic Plugin Version macOS Windows Linux Console & Web iOS
class JavaScript MBS Tools Plugin 20.0 Yes Yes Yes Yes No
Function: The class for our embedded JavaScript engine.
Notes:
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.

Feedback, Comments & Corrections

  • 2 events
    • event Input(values() as Variant) as Variant
    • event Print(values() as Variant)
  • 3 properties
  • 9 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 Destructor
    • method Evaluate(JavaScript as String) as Variant
    • method EvaluateToString(JavaScript as String) as String
    • method LoadFunction(Name as String, Data as Memoryblock) as Boolean
    • method RegisterFunction(Name as String, theDelegate as JavaScriptEngineDelegateMBS, ArgCount as Integer = -1, tag as Variant = nil)
    • method SaveFunction(Name as String) as MemoryBlock
  • delegate JavaScriptEngineDelegateMBS(Name as String, Params() as Variant, tag as Variant) as Variant

This class has no sub classes.

Some examples which use this class:

Blog Entries


The items on this page are in the following plugins: MBS Tools Plugin.


JavaScriptEngineExceptionMBS   -   JavaShortArrayMBS

The biggest plugin in space...




Links
MBS Xojo PDF Plugins