Documentation
¶
Overview ¶
Package json is a simple JSON encoder/decoder for gopher-lua.
Documentation ¶
The following functions are exposed by the library:
decode(string): Decodes a JSON string. Returns nil and an error string if
the string could not be decoded.
encode(value): Encodes a value into a JSON string. Returns nil and an error
string if the value could not be encoded.
fromYAML(string): Decodes a YAML string. Returns nil and an error string if
the string could not be decoded.
toYAML(value): Encodes a value into a YAML string. Returns nil and an error
string if the value could not be encoded.
The following types are supported:
Lua | JSON/YAML
---------+----------
nil | null
number | number
string | string
table | object: when table is non-empty and has only string keys
| array: when table is empty, or has only sequential numeric keys
| starting from 1
Attempting to encode any other Lua type will result in an error.
Example ¶
Below is an example usage of the library:
import (
luajson "github.com/projectsveltos/lua-utils/glua-json"
)
L := lua.NewState()
luajson.Preload(L)
Index ¶
- func Decode(L *lua.LState, data []byte) (lua.LValue, error)
- func DecodeValue(L *lua.LState, value any) lua.LValue
- func Encode(value lua.LValue) ([]byte, error)
- func FromYAML(L *lua.LState, data []byte) (lua.LValue, error)
- func Loader(L *lua.LState) int
- func Preload(L *lua.LState)
- func ToYAML(value lua.LValue) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeValue ¶
DecodeValue converts the value to a Lua value.
This function only converts values that the encoding/json package decodes to. All other values will return lua.LNil.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.