// Variables and functions
a = 20
b: string = "Hello!" // Type is optional
const c = 42;
myarray = [1, 2, 3]
mydict = {"x": 1, "y": 2}
myset = {true, "apple", 1.5}
mybool = false
nullable?: int = null
// Descriptive keywords like 'function' are available via `verbose=true` option in project's compiler settings.
// Default is 'fn'
public function main(args: string[], num) {
print("Hello, ${args[0]}!")
result = add(10, 5)
print("Sum: ${result}")
}
private fn add(a, b) -> int {
return a + b
}
public fn subtract(a, b) -> int => a - b
// Imports from Neoluma modules
#import "fs"
#import "random" as rnd
num = rnd.random(1, 100);
print(num);
a = input("Say something: ")
with open("log.txt", write) as file {
file.write(a);
}
// Unsafe memory access
// Example 1: Raw memory usage
#import "memory"
ptr = memory.allocate(4 * size(int))
*ptr = 123
print(*ptr)
memory.free(ptr)
// Example 2: Using foreign libraries
#import "cpp:SDL3" as SDL // Language packs feature!
#unsafe
// NOT A REAL EXAMPLE! Look up SDL3 documentation https://wiki.libsdl.org/SDL3/FrontPage
// to write it correctly.
fn main() {
// Initialize SDL
if (SDL.init(SDL.INIT_VIDEO) != 0) {
print("SDL failed to initialize: ${SDL.GetError()}")
return;
}
// Create a window
window = SDL.createWindow(
"Hello Neoluma + SDL3",
SDL.WINDOWPOS_CENTERED,
SDL.WINDOWPOS_CENTERED,
800,
600,
SDL.WINDOW_SHOWN
)
if (window == null) {
print("Failed to create window: ${SDL.GetError()}")
SDL.quit()
return;
}
// Main loop
running = true
event = SDL.Event()
while (running) {
while (SDL.PollEvent(&event) != 0) {
if (event.type == SDL.QUIT) {
running = false
}
}
// Set draw color and clear
SDL.SetRenderDrawColor(window, 50, 75, 100, 255)
SDL.RenderClear(window)
// Render stuff here...
SDL.RenderPresent(window)
}
// Cleanup
SDL.DestroyWindow(window)
SDL.quit()
}