PIE has two kinds of modules: standard library modules (bundled with the compiler) and user modules (any .pie file you write).
Import with the import keyword at the top of the file:
import sqlite;
import json;
import http;
import date;
Multiple imports are allowed — one per line:
import sqlite;
import json;
After importing, call functions with the module name as a prefix:
import date;
int now = date.now();
string formatted = date.format_iso(now);
output(formatted, string);
| Module | Purpose | Doc |
|---|---|---|
sqlite |
SQLite database CRUD and transactions | sqlite.md |
json |
Parse and build JSON | json.md |
http |
HTTP client (GET/POST) and HTTP server | http.md |
date |
Timestamps, formatting, parsing, arithmetic | date.md |
Any .pie file can be imported as a module. Mark the functions you want to expose with the export keyword.
mathutils.pie:
export int square(int n) {
return n * n;
}
export float hypotenuse(float a, float b) {
return sqrt(a * a + b * b);
}
int private_helper(int x) {
return x + 1;
}
- Functions marked
exportare visible to importers. - Functions without
exportare private to the module file.
import mathutils;
void main() {
int sq = mathutils.square(5);
output(sq, int);
float h = mathutils.hypotenuse(3.0, 4.0);
output(h, float, 2);
}
The compiler looks for modulename.pie relative to the source file being compiled, then in the standard library paths. To import a module in a subdirectory:
import utils/helpers;
This resolves to utils/helpers.pie relative to the source file.
- Module names must be valid identifiers (
[a-zA-Z_][a-zA-Z0-9_]*). - Standard library module names are lowercase (
sqlite,json,http,date). - User module names should match their filename (without
.pie). - Call exported functions as
modulename.functionname(args).
- HTTP Module — HTTP client and server
- JSON Module — JSON parse/build
- SQLite Module — Database access
- Date Module — Time and date utilities
- Language Reference — Core language