gluajson

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: 0BSD Imports: 3 Imported by: 2

README

JSON library for gopher-lua in PeerDB

Unfortunately existing JSON libraries for gopher-lua suffer from the existing issue of how to encode an empty table, while this library offers a mechanism to specify how a particular table should be encoded if empty

These libraries also fail to integrate with UserData, which PeerDB scripting relies on heavily


gluajson exports encode & decode

To guide encode, there are 3 wrapper functions: array, object, raw

array / table can be used to direct whether an empty table should be encoded as an array or a table

json.raw(string) will interpolate string without encoding, this can be useful if you want to wrap an already encoded json string into another json object

Passing true as the 2nd parameter to decode will decode json using markers, arrays will be marked as array, objects marked as object, numbers marked as raw strings of their digits to preserve precision, & nulls marked as raw("null")

To handle marked objects, there is a function unmark which for marked objects returns inner, wrapper, while for unmarked objects the original parameter is returned

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loader

func Loader(ls *lua.LState) int

func LuaJsonDecode

func LuaJsonDecode(ls *lua.LState) int

func LuaJsonEncode

func LuaJsonEncode(ls *lua.LState) int

Types

type Array

type Array *lua.LTable

type DecodeTarget

type DecodeTarget struct {
	// contains filtered or unexported fields
}

func (*DecodeTarget) Ingest

func (dt *DecodeTarget) Ingest(value lua.LValue)

type Object

type Object *lua.LTable

type Raw

type Raw lua.LString

Jump to

Keyboard shortcuts

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