Documentation ¶
Overview ¶
Package json implements json decode/encode functionality for lua. original code: https://github.com/layeh/gopher-json
Index ¶
- func CheckJSONDecoder(L *lua.LState, n int) *json.Decoder
- func CheckJSONEncoder(L *lua.LState, n int) *json.Encoder
- func Decode(L *lua.LState) int
- func Encode(L *lua.LState) int
- func LVJSONDecoder(L *lua.LState, decoder *json.Decoder) lua.LValue
- func LVJSONEncoder(L *lua.LState, encoder *json.Encoder) lua.LValue
- func Loader(L *lua.LState) int
- func Preload(L *lua.LState)
- func ValueDecode(L *lua.LState, data []byte) (lua.LValue, error)
- func ValueEncode(value lua.LValue) ([]byte, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode lua json.decode(string) returns (table, err)
Example ¶
json.decode(string)
state := lua.NewState() Preload(state) inspect.Preload(state) source := ` local json = require("json") local inspect = require("inspect") local jsonString = [[{"a":{"b":1}}]] local result, err = json.decode(jsonString) 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}}
func Encode ¶
Encode lua json.encode(obj) returns (string, err)
Example ¶
json.encode(obj)
state := lua.NewState() Preload(state) inspect.Preload(state) source := ` local json = require("json") local inspect = require("inspect") local table = {a={b=1}} local result, err = json.encode(table) if err then error(err) end print(inspect(result, {newline="", indent=""})) print(inspect( json.encode( {} ) )) ` if err := state.DoString(source); err != nil { log.Fatal(err.Error()) }
Output: '{"a":{"b":1}}' "[]"
func LVJSONDecoder ¶ added in v0.1.6
func LVJSONEncoder ¶ added in v0.1.6
func Preload ¶
Preload adds json to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:
local json = require("json")
func ValueDecode ¶
ValueDecode converts the JSON encoded data to Lua values.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.