conversion

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MaxFromGoDepth = 10000

MaxFromGoDepth caps how many containers deep a Go value may be converted. Conversion recurses in Go, and a stack overflow is a fatal error that ends the whole process, so past this depth FromGo returns a RecursionError instead. It matches the nesting depth the data decoders accept.

Variables

This section is empty.

Functions

func FromGo

func FromGo(v interface{}) object.Object

FromGo converts a Go interface{} value to a scriptling Object. It handles primitive types (nil, bool, int, float, string), nested structures (maps, slices), and falls back to JSON marshaling for unknown types. A value nested more than MaxFromGoDepth containers deep converts to a RecursionError.

func MustParseJSON

func MustParseJSON(jsonStr string) object.Object

MustParseJSON parses a JSON string and returns a Scriptling object, returning an Error object if parsing fails.

func ParseJSON

func ParseJSON(jsonStr string) (object.Object, error)

ParseJSON parses a JSON string and returns a Scriptling object. It uses UseNumber() to preserve large integers, and builds dicts in the document's key order (as Python's json.loads does) rather than through a Go map, whose iteration order is random.

func ToBytes added in v0.19.0

func ToBytes(obj object.Object) ([]byte, object.Object)

ToBytes accepts a Bytes or String input and returns the raw byte slice. Used by libraries that historically took strings but now also accept Bytes (file I/O, HTTP bodies, socket send, etc.). Returns a Scriptling *Error object for any other type so callers can return it directly.

Bytes are returned as-is (no copy — treat the result as read-only). Strings are UTF-8 encoded into a fresh byte slice.

func ToGo

func ToGo(obj object.Object) interface{}

ToGo converts a scriptling Object to a Go interface{}. It returns the underlying Go value for the object type.

func ToGoChecked added in v0.33.0

func ToGoChecked(obj object.Object) (interface{}, *object.Error)

ToGoChecked is ToGo for serializers: a value nested more than 10000 levels is a RecursionError rather than silently truncated to a placeholder. It applies no other limit.

func ToGoError

func ToGoError(obj object.Object) error

ToGoError converts a scriptling Object to a Go error. If the object is an Error type, it returns a Go error with the error message. Otherwise, it returns nil.

func ToGoLimited added in v0.31.0

func ToGoLimited(obj object.Object) (interface{}, *object.Error)

ToGoLimited is ToGo held to the limits of the interpreter on the calling goroutine. A value shared by several containers converts once per reference, so a small script value can expand into a huge Go value; the conversion counts what it builds and stops with a MemoryError once that passes the value limit or the memory left. Use it for script data handed to libraries (templates, encoders, request bodies).

func ToGoWithError

func ToGoWithError(obj object.Object) (interface{}, *object.Error)

ToGoWithError converts a Scriptling object to a Go value, returning error for complex types

Types

This section is empty.

Jump to

Keyboard shortcuts

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