Documentation
¶
Index ¶
- Constants
- func FromGo(v interface{}) object.Object
- func MustParseJSON(jsonStr string) object.Object
- func ParseJSON(jsonStr string) (object.Object, error)
- func ToBytes(obj object.Object) ([]byte, object.Object)
- func ToGo(obj object.Object) interface{}
- func ToGoChecked(obj object.Object) (interface{}, *object.Error)
- func ToGoError(obj object.Object) error
- func ToGoLimited(obj object.Object) (interface{}, *object.Error)
- func ToGoWithError(obj object.Object) (interface{}, *object.Error)
Constants ¶
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 ¶
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 ¶
MustParseJSON parses a JSON string and returns a Scriptling object, returning an Error object if parsing fails.
func ParseJSON ¶
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. Only whitespace may follow the value: "2 notes" is an error ("extra data", as in Python), not the number 2.
func ToBytes ¶ added in v0.19.0
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 ¶
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
ToGoChecked is ToGoLimited for serializers: a value nested more than 10000 levels is a RecursionError rather than a MemoryError.
func ToGoError ¶
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
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 as it goes, the values and the bytes of the strings and bytes values among them, and stops with a MemoryError as soon as that passes the value limit or the memory left, so the work done is bounded too. Use it for script data handed to libraries (templates, encoders, request bodies). With no limits set it converts as ToGo does.
The limits are those of the interpreter bound to the calling goroutine: a host converting a result after the call has returned binds it first with object.BindGuard(p.ResourceGuard()).
Types ¶
This section is empty.