ReadNotIndex() (type)

Data type handler for the bang-prefixed index, ![, builtin

Description

This is a function you would write when programming a Murex data-type.

It’s called by the index, ![, builtin.

The purpose of this function is to allow builtins to support sequential reads (where possible) and also create a standard interface for ![ (index), thus allowing it to be data-type agnostic.

Usage

Registering your ReadNotIndex()

// To avoid data races, this should only happen inside func init()
lang.ReadNotIndexes[ /* your type name */ ] = /* your readIndex func */

Examples

Example ReadIndex() function (the code structure is the same for ReadIndex and ReadNotIndex):

package json

import (
    "github.com/lmorg/murex/lang"
    "github.com/lmorg/murex/utils/json"
)

func index(p *lang.Process, params []string) error {
    var jInterface interface{}

    b, err := p.Stdin.ReadAll()
    if err != nil {
        return err
    }

    err = json.Unmarshal(b, &jInterface)
    if err != nil {
        return err
    }

    marshaller := func(iface interface{}) ([]byte, error) {
        return json.Marshal(iface, p.Stdout.IsTTY())
    }

    return lang.IndexTemplateObject(p, params, &jInterface, marshaller)
}

Detail

While there is support for a dedicated ReadNotIndex() for instances of ![, the template APIs lang.IndexTemplateObject and lang.IndexTemplateTable are both agnostic to the bang prefix.

Parameters

  1. *lang.Process: Process’s runtime state. Typically expressed as the variable p
  2. []string: slice of parameters used in ![

See Also


This document was generated from lang/stdio/interface_doc.yaml.

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Tue Dec 10 22:56:57 UTC 2024 against commit 60f05a260f05a227caf73dd5b3478e3cb3f4bb24e46745b.

Current version is 6.4.1005 (develop) which has been verified against tests cases.