Interacting with 123basic JS code - metzzo/123-basic GitHub Wiki
This article aims to explain how to call 123basic functions from JS and call JS functions from 123basic.
123basic -> JS
Given the scenario you want to call some super fancy JS function that does not exist in 123basic. To achieve this 123basic has introduced so called NATIVE FUNCTION
s. These simply tell the compiler that some function exists, but the compiler does modify them in any way or implement it.
REQUIRE "mySuperAwesomeFunction.js" // include some fancy js file
NATIVE FUNCTION mySuperAwesomeFunction: hello$, mello%
mySuperAwesomeFunction("Hello", 102)
The generated 123basic code will call mySuperAwesomeFunction().
JS -> 123basic
Call some 123basic functions from JS? Simply use the EXPORT
keyword, which exposes 123basic functions to use for JS. Normally 123basic changes function names, to prevent name collisions. Which means, if you use EXPORT, make sure you have no naming collisions (for example: exporting a FUNCTION named with
is valid in 123basic but invalid in JavaScript)
FUNCTION mySuperAwesomeFunction:
STDOUT "super aweomse"
ENDFUNCTION
EXPORT mySuperAwesomeFunction // can now be used in JS with mySuperAwesomeFunction()
Datatypes
Arrays
123basic does not use the JS arrays directly, it uses a wrapper class named OTTArray which provides the functionality that 123basic needs. TODO
Types
TODO