Power Modules
Power Modules are C++ plugins that extend Astra with new built-in functions. Drop a .power file next to your program, load it with add, and call its functions like native Astra built-ins — no imports, no wrappers.
💡 When a module loads successfully, Astra prints:
[ASTRA-INFO] :: Astra Power Check :: 'math.power' Linked SuccessfullyAvailable Modules
🔢
math.power
Mathematical functions — sqrt, trig, primes, random, and more
📝
text.power
String operations — upper, split, replace, substr, and more
⏱️
time.power
Date and time — current time, date math, sleep, stopwatch
🌐
web.power
HTML generation — build and save web pages from Astra
🔢 math.power
Mathematical functions — trigonometry, rounding, primes, random numbers, and more.
| Function | Description |
|---|---|
| sqrt(x) | Square root |
| abs(x) | Absolute value |
| pow(x, y) | x to the power y |
| mod(x, y) | Floating-point remainder |
| floor(x) | Round down to integer |
| ceil(x) | Round up to integer |
| round(x) | Round to nearest integer |
| log(x) | Base-10 logarithm |
| ln(x) | Natural logarithm |
| exp(x) | eˣ |
| cbrt(x) | Cube root |
| sin(x) | Sine (degrees) |
| cos(x) | Cosine (degrees) |
| tan(x) | Tangent (degrees) |
| hypot(x, y) | Hypotenuse √(x²+y²) |
| max(x, y) | Larger of two values |
| min(x, y) | Smaller of two values |
| rand(a, b) | Random integer between a and b |
| pi() | Returns π (3.14159…) |
| e() | Returns e (2.71828…) |
| fact(n) | Factorial of n |
| prime(n) | 1 if prime, 0 if not |
| gcd(a, b) | Greatest common divisor |
| fib(n) | nth Fibonacci number |
📝 text.power
String manipulation — case conversion, searching, splitting, and transformation.
| Function | Description |
|---|---|
| upper(s) | Convert to UPPERCASE |
| lower(s) | Convert to lowercase |
| trim(s) | Remove leading/trailing spaces |
| slen(s) | Length of string |
| replace(s, pat, rep) | Replace all occurrences of pat with rep |
| reverse(s) | Reverse the string |
| contains(s, pat) | TRUE if s contains pat |
| startswith(s, pat) | TRUE if s starts with pat |
| endswith(s, pat) | TRUE if s ends with pat |
| tonum(s) | Convert string to number |
| tostr(x) | Convert number to string |
| substr(s, start, len) | Extract substring |
| indexof(s, pat) | Index of first match (-1 if not found) |
| strrepeat(s, n) | Repeat string n times |
| split(s, delim) | Split string into a chain |
| chars(s) | Split string into individual characters |
⏱️ time.power
Current time, date arithmetic, sleep, stopwatch, and timestamp utilities.
| Function | Description |
|---|---|
| time() | Print current time (HH:MM:SS) |
| time("h:2,m:30") | Print time offset by 2h 30m |
| date() | Print current date (DD-MM-YYYY) |
| date("d:7") | Print date 7 days from now |
| date("m:1") | Print date 1 month from now |
| sleep("s:3") | Pause program for 3 seconds |
| timestamp() | Return current Unix timestamp |
| stopwatch("start") | Start a stopwatch |
| stopwatch("stop") | Stop and print elapsed time |
| format("%Y-%m-%d %H:%M") | Print date/time in custom format |
| addtime(ts, "h:1") | Add 1 hour to a timestamp |
🌐 web.power
Generate and save HTML pages directly from Astra — no external tools needed.
| Function | Description |
|---|---|
| set_filename("page.html") | Set output HTML file name |
| style("body { margin:0 }") | Add CSS to the page |
| hover("selector", "color:red") | Add hover style |
| h1("Hello") | Create an <h1> element |
| para("text") | Create a <p> element |
| btn("Click me") | Create a <button> element |
| img("alt", "src.png") | Create an <img> element |
| input("text", "placeholder") | Create an <input> element |
| div("class", content) | Wrap content in a <div> |
| js("alert(1)") | Add JavaScript to the page |
| save(html) | Write final HTML to file |
⚠️
save(html) must be called last — it writes the final file and resets the internal CSS/JS state.Custom Modules
You can write your own .power file in C++ using the Astra SDK. Every module exports two functions: astra_init to register functions, and astra_logic as an optional command handler.
Minimal example
Use it in Astra
ℹ️ Compile your
.cpp file as a shared library (.dll on Windows, .so on Linux) and rename it to yourname.power. Place it in the same directory as your .astra file.