-
Notifications
You must be signed in to change notification settings - Fork 1
JavaScript Interop
Some effort was made in the last few builds to establish methods to call out to the underlying JavaScript platform.
When you create the Sallied-Forth interpreter, you can now pass in a JavaScript Object as a reference for the interpreter to access.
var interpreter = new salliedForth.Interpreter( window );As in this example, it could be your Browser window object, but equally, it could be the document object or any other arbitrary JS object.
All the js words can handle native JavaScript data structures.*
By default the valueStore is now the same object as passed in the Interpreter upon instantiation. So @ and ! can be used to access properties, but we provide 2 convenience methods js@ and js!.
js@ temp ( gets the value from the JS property 'temp' and pushes it on the stack )
99 js! temp ( pops the value '99' off the stack and sets the value of 'temp' in the JavaScript context. )hello ( calls the 'hello' function with no parameters )
[ 12 help ] js setWarning ( calls setWarning with 12, "help" as parameters )
[] js- setWarning ( calls getWarning with no parameters and pushes the returned value on the stack )The js* words pops the parameters array off the stack and then uses the next word as the function name, calling it with the elements of the array as individual parameters. [] is a word which simply pushes an empty JS array on the stack.