yaml

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

yaml GoDoc

Usage

decode
local yaml = require("yaml")
local inspect = require("inspect")

-- yaml.decode()
local text = [[
a:
  b: 1
]]
local result, err = yaml.decode(text)
if err then error(err) end
print(inspect(result, {newline="", indent=""}))
-- Output:
-- {a = {b = 1}}
encode
    local yaml = require("yaml")
    local encoded, err = yaml.encode({a = {b = 1}})
    if err then error(err) end
    print(encoded)
	-- Output:
	-- a:
	--   b: 1
	--

Documentation

Overview

Package yaml implements yaml decode functionality for lua.

Example

yaml.decode(string)

state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
    local yaml = require("yaml")
    local inspect = require("inspect")
    local text = [[
a:
  b: 1
    ]]
    local result, err = yaml.decode(text)
    if err then error(err) end
    print(inspect(result, {newline="", indent=""}))
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

{a = {b = 1}}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(L *lua.LState) int

Decode lua yaml.decode(string) returns (table, error)

func Encode

func Encode(L *lua.LState) int

Encode lua yaml.encode(any) returns (string, error)

Example
state := lua.NewState()
Preload(state)
inspect.Preload(state)
source := `
    local yaml = require("yaml")
    local encoded, err = yaml.encode({a = {b = 1}})
    if err then error(err) end
    print(encoded)
`
if err := state.DoString(source); err != nil {
	log.Fatal(err.Error())
}
Output:

a:
  b: 1

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds yaml to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local yaml = require("yaml")

Types

This section is empty.

Jump to

Keyboard shortcuts

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