Documentation ¶
Overview ¶
Package json implements json decode/encode functionality for lua. original code: https://github.com/layeh/gopher-json
Index ¶
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=""})) ` if err := state.DoString(source); err != nil { log.Fatal(err.Error()) }
Output: '{"a":{"b":1}}'
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.