The ucode language

ucode is a small scripting language for Linux systems. It features an ECMAScript-like syntax, native JSON datatypes, a built-in template engine and an embeddable C core, and it ships preinstalled on OpenWrt, where it powers the nftables firewall and the LuCI web interface.

For a comprehensive treatment of the language, the standard library and the C embedding API, see the ucode manual.

Tutorials

  • Usage — the ucode command line options and how scripts receive arguments and data.
  • Arrays — recipes for set operations, chunking, flattening and deep copying, and a common pitfall when mapping builtins.
  • Objects — recipes for merging, filtering and comparing objects, and using them as caches and lookup tables.
  • Metamethods — patterns for making values callable, synthesizing properties and routing writes to backing stores.

Module reference

  • core — the builtin functions available to every script.
  • debug — breakpoints, backtraces, memory dumps and the line-based debug protocol.
  • digest — MD2/4/5, SHA1/256/384/512 and FNV-1a digests.
  • ffi — foreign function interface to C libraries.
  • fs — file and directory operations, popen() and friends.
  • io — POSIX file descriptor I/O.
  • log — syslog and OpenWrt ulog output.
  • math — mathematical functions and pseudo-random numbers.
  • netaddr — IPv4, IPv6 and MAC address validation and range operations.
  • nl80211 — wireless extension over the nl80211 netlink interface.
  • resolv — DNS name resolution.
  • rtnl — interfaces, addresses and routes over rtnetlink.
  • serial — serial port attributes and I/O.
  • socket — BSD sockets.
  • struct — packing and unpacking binary data.
  • ubus — ubus IPC: object calls, events and subscriptions.
  • uci — OpenWrt configuration (UCI) access.
  • uloop — the event loop: timers, signals, processes and tasks.
  • zlib — gzip and deflate compression and decompression.