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.

add math add text add time x = sqrt(100) write x \\ 10 write upper("vijay") \\ VIJAY time() \\ 11:48:48
💡 When a module loads successfully, Astra prints:
[ASTRA-INFO] :: Astra Power Check :: 'math.power' Linked Successfully

Available 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.

add math write sqrt(144) \\ 12 write pow(2, 10) \\ 1024 write rand(1, 100) \\ random number between 1 and 100 write prime(17) \\ 1 (is prime) write fib(10) \\ 55 write gcd(48, 18) \\ 6 write fact(6) \\ 720 write pi() \\ 3.14159... write sin(90) \\ 1 (degrees)
FunctionDescription
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)
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.

add text write upper("hello") \\ HELLO write lower("WORLD") \\ world write trim(" astra ") \\ astra write reverse("astra") \\ artsa write contains("hello", "ell") \\ TRUE write replace("a b c", " ", "-") \\ a-b-c write slen("astra") \\ 5 parts:n = split("a,b,c", ",") write parts1 \\ a write parts2 \\ b write parts3 \\ c
FunctionDescription
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.

add time time() \\ 11:48:32 date() \\ 28-06-2026 \\ Offset: 2 hours 30 minutes from now time("h:2,m:30") \\ 7 days from today date("d:7") \\ Sleep for 3 seconds sleep("s:3") \\ Stopwatch stopwatch("start") \\ ... some work ... stopwatch("stop") \\ 0.0031s \\ Unix timestamp ts = timestamp() write ts \\ Custom format format("%Y-%m-%d %H:%M")
FunctionDescription
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.

webpage.astra
add web set_filename("index.html") style("body { font-family: sans-serif; padding: 2rem; background: #f0f0f0; }") style(".card { background: white; padding: 1rem; border-radius: 8px; }") hover(".btn", "background: #333; color: white;") heading = h1("Welcome to Astra Web") text = para("Built entirely from Astra code.") button = btn("Click Me") card = div("card", heading + text + button) save(card)
FunctionDescription
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

hello.power.cpp
#include "astra_sdk.h" #ifdef _WIN32 #define ASTRA_EXPORT extern "C" __declspec(dllexport) #else #define ASTRA_EXPORT extern "C" #endif void my_greet(AstraVM* vm) { Value name = vm->pop(); Value result; result.type = VAL_STR; result.str = "Hello, " + name.str + "!"; result.isInitialized = true; vm->push(result); } ASTRA_EXPORT void astra_init(RegisterFunc reg) { reg("greet", my_greet); } ASTRA_EXPORT const char* astra_logic(const char* cmd, const char* args) { return "Hello_Module_Active"; }

Use it in Astra

add hello write greet("Vijay") \\ Hello, Vijay!
ℹ️ 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.