assistance-engine/docs/developer.avapframework.com/chapter9_6.md

25 lines
1.1 KiB
Markdown

## 5. The Import System in AVAP
AVAP code in one file gains access to code in another file through the import process. The `import` statement is the only way to invoke the import machinery in AVAP.
The `include` statement inserts the contents of the specified file at the exact point where the import statement appears in the original file. There are no other ways to invoke the import system in AVAP.
When an `include` statement is executed, the contents of the imported file are processed as if they were part of the original file, ensuring that all functions and variables from the imported file are available in the context of the original file. If the specified file is not found, a `FileNotFoundError` is raised.
Example of using the `include` statement in AVAP:
```javascript
Content of file main.avap
addVar(x,10)
include functions.avap
myFunction(x)
Content of file functions.avap
function myFunction(y){
addVar(result, y + 5)
addResult(result)
}
```
In this example, the content of `functions.avap` is inserted into `main.avap` at the point of the import statement, ensuring that `myFunction` is defined before being called.