-
Notifications
You must be signed in to change notification settings - Fork 10
Adding Support for a New Keyword
These steps assume that:
- You have cloned the QBJS github project and have a local working copy
- You have the QB64 (2.0.2) compiler installed
- Open the tools/qb2js.bas file for edit
- Find the InitQBMethods function
- Add a new call to the AddQBMethod** for the new keyword
Keywords are organized alphabetically in the following three sections: QB64, QB45 and QBJS-only - Save and compile the qb2js.bas
- Convert qb2js to javascript by running the following command from the tools directory:
qb2js qb2js.bas > ../qb2js.js
**The syntax for this method is as follows:
AddQBMethod type, name, synchronousFlag
type
Must be either "FUNCTION" or "SUB"
If there is both a Sub and Function version of the method then two calls should be made to AddQBMethod, one for each versionname
This is the name of the function in Upper Camel CasesynchronousFlag
Indicates whether this method should be called synchronously.
In most cases this should be set to false unless within the implementing javascript function the await keyword is used to wait for the response of an asynchronous function call.For example, if we were adding support for the "Cos" keyword this call would be the following:
AddQBMethod "FUNCTION", "Cos", False
- Open the qb.js file for edit
- Find the appropriate section for the keyword
This file is also organized into the following three sections: QB64, QB45 and QBJS-only - Add a new function with the following format: typePrefix__functionName
The typePrefix will be either "sub" or "func"
For example, if we were implementing the "Cos" method, the function would be defined as:
this.func_Cos = function(value) {
return Math.cos(value);
}
- Open the codemirror/qb-lang.js file for edit
- Add the keyword name (in all lowercase) to the builtinFuncsWord list
- Launch the index.html and test the new method