Skip to content

Lua API

trustytrojan edited this page Aug 31, 2025 · 1 revision

This is the documentation of the globals provided to the Lua environment when you run the lua command in nds-shell.

Table libnds

A table containing libnds functions. For all functions listed below, refer to libnds documentation. They are direct bindings with no modification.

Functions

  • setBrightness(screen: number, level: number)
  • pmMainLoop(): boolean
  • threadYield()

Class CliPrompt

Asynchronous command-line interface prompt, taking input from the keypad (physical buttons) and libnds virtual keyboard. Provides:

  • a visible, movable cursor that can edit the line at any position
  • input line history with arrow-key & d-pad button navigation

Constructor new()

Returns

A new CliPrompt object with default prompt string (> ) and output stream (std::cout).

Constructor new(prompt)

Parameters

  • prompt: The string to print before processing keyboard input.

Returns

A new CliPrompt object with the provided prompt string and output stream set to the lua command's output stream (the console it was run on).

Property prompt

Write-only property. Sets the prompt string.

Property ostr

Write-only property. Sets the output stream. Must be an std::ostream.

Property input

Read-only property. Gets the current input string.

Method printFullPrompt(withInput)

Prints the prompt string, and optionally the current input.

Parameters

  • withInput: Boolean specifying whether the current input should be printed after the prompt string

Method prepareForNextLine()

Resets internal state necessary to start reading in characters for a "new line" of input. In particular, it clears the input string. You should call this when you want to reuse the prompt for multiple lines of input, after you are finished with what's currently in the input.

Method update()

Updates the prompt based on any detected user input (keyboard/keypad), and prints to the output stream reflecting the input buffer. You must call this (usually in a loop) to receive input and see it on the console.

Property enterPressed

Read-only property. Returns whether the Enter key was pressed on the last call to update().

Property foldPressed

Read-only property. Returns whether the "fold" key (the key in the Esc key's spot on the libnds default keyboard) was pressed on the last call to update().

Property lineHistory

Read-only property. Returns the current line history as an array of strings.

Method setLineHistoryFromFile(filename)

Replaces the line history with that from the file at filename.

Parameters

  • filename: Path to file to use as history file.

Method clearLineHistory()

Clears the line history.

Function fetch(url, opts, on_complete)

A fetch()-like API for asynchronous HTTP(S) requests.

Parameters

  • url: String containing endpoint URL
  • opts: Table of the form:
    {
        method = 'HTTP method string (optional)',
        body = 'HTTP request body (optional)',
        headers = { -- Optional table of headers
            ['Key'] = 'Value'
        },
    }
  • on_complete: Function taking the parameters (code, body, error), where code is the HTTP response code, body is the HTTP response body (may be empty), and error is a libcurl error string if an error occurred or nil if not.