TezzNative v1.1.0 is hardening toward production. View roadmap

Examples

Small programs that show the stable path.

Search examples by feature and copy the snippets directly into a `.tn` file.

Hello world

Hello world
import "std"

fn main() -> int:
  say "hello from TezzNative"
  ret 0

CLI-style flags

CLI-style flags
fn flag_enabled(arg:str, name:str) -> int:
  if strcmp(arg, name) == 0:
    ret 1
  ret 0

fn main() -> int:
  if flag_enabled("--verbose", "--verbose") != 0:
    say "verbose mode"
  ret 0

File IO

File IO
import "io"

fn main() -> int:
  path:str = "out.txt"
  data:str = "saved"
  f:*File = io.open_w(path)
  if f == 0:
    ret 1
  p:*char
  unsafe:
    p = data as *char
  io.file_write(f, p, len(data))
  io.file_close(f)
  ret 0

HTTP parse

HTTP parse
import "net"

fn main() -> int:
  resp:str = "HTTP/1.1 200 OK\nContent-Length: 2\n\nok"
  if net.http_status_code(resp) != 200:
    ret 1
  ret 0

C extern

C extern
@abi("c")
extern fn puts(s:str) -> int

fn main() -> int:
  puts("hello from C ABI")
  ret 0