1
1
Fork 0
mirror of https://github.com/boxgaming/qbjs.git synced 2024-05-12 08:00:12 +00:00
4 Adding Support for a New Keyword
boxgaming edited this page 2022-09-17 11:37:59 -05:00

Prerequisites

These steps assume that:

  1. You have cloned the QBJS github project and have a local working copy
  2. You have the QB64 (2.0.2) compiler installed

Step 1 - Register the new Keyword in the QB2JS Converter

  1. Open the tools/qb2js.bas file for edit
  2. Find the InitQBMethods function
  3. 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
  4. Save and compile the qb2js.bas
  5. 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 version

name
This is the name of the function in Upper Camel Case

synchronousFlag
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

Step 2 - Implement the function

  1. Open the qb.js file for edit
  2. Find the appropriate section for the keyword
    This file is also organized into the following three sections: QB64, QB45 and QBJS-only
  3. 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);
}

Step 3 - Register the keyword with the IDE

  • Open the codemirror/qb-lang.js file for edit
  • Add the keyword name (in all lowercase) to the builtinFuncsWord list

Step 4: Test

  • Launch the index.html and test the new method