luadata

package module
v0.1.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 6 Imported by: 0

README

luadata (Go)

Go wrapper for luadata — parse Lua data files (such as World of Warcraft SavedVariables) and convert to JSON. Uses the Rust core library via a C shared library loaded at runtime.

Install

go get github.com/mmobeus/luadata/go

Usage

import luadata "github.com/mmobeus/luadata/go"

// From a string
reader, err := luadata.TextToJSON("input", luaString)

// From a file
reader, err := luadata.FileToJSON("config.lua")

// From bytes
reader, err := luadata.ToJSON(luaBytes)

// From an io.Reader
reader, err := luadata.ReaderToJSON("input", r)

// With options
reader, err := luadata.TextToJSON("input", luaString,
    luadata.WithArrayMode("sparse", 10),
    luadata.WithEmptyTableMode("array"),
    luadata.WithStringTransform(1024, "truncate"),
)

All functions return an io.Reader containing JSON.

Options

All functions accept functional options:

  • WithSchema(schemaJSON) — provide a JSON Schema string to guide type decisions, overriding heuristics
  • WithUnknownFieldMode(mode) — how to handle fields not in the schema (ignore, include, fail)
  • WithStringTransform(maxLen, mode, [replacement]) — limit string length during parsing (truncate, empty, redact, replace)
  • WithArrayMode(mode, [maxGap]) — control how integer-keyed Lua tables map to JSON arrays (sparse, index-only, none)
  • WithEmptyTableMode(mode) — choose how empty Lua tables render in JSON (null, omit, array, object)

See the full options documentation for details and examples.

Documentation

Overview

Package luadata converts Lua data files to JSON using a Rust shared library via purego.

This package provides a pure-Go interface (no CGO required) by loading a platform-specific Rust shared library at runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileToJSON

func FileToJSON(filePath string, opts ...Option) (io.Reader, error)

FileToJSON parses a Lua data file and returns JSON as an io.Reader.

func ReaderToJSON

func ReaderToJSON(name string, r io.Reader, opts ...Option) (io.Reader, error)

ReaderToJSON parses Lua data from an io.Reader and returns JSON as an io.Reader.

func TextToJSON

func TextToJSON(name, text string, opts ...Option) (io.Reader, error)

TextToJSON parses a Lua data string and returns the JSON as an io.Reader.

func ToJSON

func ToJSON(lua []byte, opts ...Option) (io.Reader, error)

ToJSON parses Lua data bytes and returns the JSON as an io.Reader.

Types

type Option

type Option func(*optionsConfig)

Option configures conversion behavior.

func WithArrayMode

func WithArrayMode(mode string, maxGap ...int) Option

WithArrayMode sets the array detection mode for JSON output. Valid values: "none", "index-only", "sparse" (default). For sparse mode, use WithArrayMaxGap to set the gap threshold.

func WithEmptyTableMode

func WithEmptyTableMode(mode string) Option

WithEmptyTableMode sets how empty Lua tables ({}) are rendered in JSON output. Valid values: "null" (default), "omit", "array", "object".

func WithSchema added in v0.1.15

func WithSchema(schemaJSON string) Option

WithSchema sets a JSON Schema to guide parsing. The schema is a standard JSON Schema string (subset: type, properties, items, format).

func WithStringTransform

func WithStringTransform(maxLen int, mode string, replacement ...string) Option

WithStringTransform configures how long strings are handled. Strings exceeding maxLen are transformed according to mode. Valid modes: "truncate" (default), "empty", "redact", "replace". For "replace" mode, pass the replacement string.

func WithUnknownFieldMode added in v0.1.15

func WithUnknownFieldMode(mode string) Option

WithUnknownFieldMode sets how fields not in the schema are handled. Valid values: "ignore" (default), "include", "fail".

Directories

Path Synopsis
internal
ffi
Package ffi provides the low-level bridge to the Rust shared library via purego.
Package ffi provides the low-level bridge to the Rust shared library via purego.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL