require Function
Syntax
Arguments
- moduleNameCharacter
The name of the Xbasic module to load.
- searchPathCharacter
A path (i.e. directory) that contains the Xbasic module. The search path is only required if the Xbasic module is stored in a location other than the application webroot or a directory named "Xbasic_modules" located in the webroot.
Returns
- loadedModulePointer
A pointer object that represents the imported Xbasic module. Functions exported from the Xbasic module using the exports keyword are called as methods of the pointer.
Description
Used in a web application to load an Xbasic Module so that functions defined in the module can be called. You can pass in an optional searchPath. By default, the searchPath includes [webroot]\Xbasic_modules
Discussion
The require() function loads the specified Xbasic module into a locally defined Xbasic pointer. Methods exported from the Xbasic module are called as methods of the pointer object. For example, suppose you have an Xbasic module called "HelloWorld" defined as follows:
function printHelloMessage as c (name as c) printHelloMessage = "Hello " + name + "!" end function exports.sayHello=printHelloMessage
The HelloWorld Xbasic module exports the function, printHelloMessage as sayHello. The Xbasic module would be imported as follows:
dim xbm as p xbm = require("HelloWorld")
The exported function sayHello can be called as a method of the pointer that the Xbasic module was loaded into:
? xbm.sayHello("Sam") = Hello Sam!
See Also