Platforms to show: All Mac Windows Linux Cross-Platform

/MacFrameworks/JavaScript/JavaScript


Required plugins for this example: MBS MacFrameworks Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacFrameworks/JavaScript/JavaScript

This example is the version from Tue, 30th Jan 2023.

Project "JavaScript.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control ListLog Inherits Listbox
ControlInstance ListLog Inherits Listbox
End Control
Control InputField Inherits TextArea
ControlInstance InputField Inherits TextArea
End Control
Control ExecuteButton Inherits PushButton
ControlInstance ExecuteButton Inherits PushButton
EventHandler Sub Action() dim s as string = InputField.Text log ">" + s dim e as JSValueMBS dim j as JSValueMBS = context.EvaluateScript(s, "", nil, 1, e) if e <> nil then log e.stringValue end if if j <> nil then log j.stringValue end if End EventHandler
End Control
Control PropertiesButton Inherits PushButton
ControlInstance PropertiesButton Inherits PushButton
EventHandler Sub Action() dim g as JSObjectMBS = context.globalObject dim names() as string = g.PropertyNames for each name as string in names dim e as JSValueMBS dim v as string dim j as JSValueMBS = g.GetProperty(name, e) if e <> nil then v = e.stringValue end if if j <> nil then if j.Type = j.kJSTypeObject then v = j.JSONString else v = j.StringValue end if end if log name+": "+v next End EventHandler
End Control
Control CheckButton Inherits PushButton
ControlInstance CheckButton Inherits PushButton
EventHandler Sub Action() dim s as string = InputField.Text log ">" + s dim e as JSValueMBS dim r as Boolean = context.CheckScriptSyntax(s, "", e) if e <> nil then log e.stringValue else log "Syntax Okay" end if End EventHandler
End Control
EventHandler Sub Open() #If TargetLinux Then // you may need to check what version you have If JSContextMBS.LoadLibraryPath("libjavascriptcoregtk-4.1.so") Then MessageBox "Okay" Else MessageBox "Failed to load: "+JSContextMBS.LibraryError End If #ElseIf TargetWindows // you may find somewhere a JavaScriptCore.dll for use here // we just load the DLLs from iTunes into our folder with exe file: // ASL.dll // CoreFoundation.dll // icudt62.dll // JavaScriptCore.dll // libdispatch.dll // libicuin.dll // libicuuc.dll // objc.dll // WTF.dll If JSContextMBS.LoadLibraryPath("JavaScriptCore.dll") Then MessageBox "Okay" Else MessageBox "Failed to load: "+JSContextMBS.LibraryError End If #endif context = New JSContextMBS End EventHandler
Sub log(s as string) ListLog.AddRow s ListLog.ScrollPosition = ListLog.ListIndex End Sub
Property context As JSContextMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project

See also:

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


The biggest plugin in space...