Help us shape the future of Go! Take the 2026 Go Developer Survey

extending

command
v0.27.3 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 7 Imported by: 0

README

Scriptling Extension Examples

This directory contains a comprehensive example of how to extend Scriptling with custom functions and libraries written in Go.

main.go

A complete example demonstrating:

  • Custom Functions: Registering individual functions with RegisterFunc()
  • Custom Libraries: Creating and registering libraries with RegisterLibrary()
  • Argument Handling: Accepting and validating function arguments
  • Return Values: Returning different types of results
  • Type Casting: Converting between Scriptling object types (Integer, Float, String, List, Dict)
  • Arrays: Processing Scriptling lists/arrays
  • Maps: Working with Scriptling dictionaries/maps
Features Demonstrated
  1. Simple Function: greet(name) - Takes a string, returns a greeting
  2. Array Processing: process_numbers(numbers) - Takes an array of numbers, returns processed strings
  3. Library Functions:
    • mathutils.power(base, exp) - Calculates power with type casting
    • mathutils.sum_array(numbers) - Sums all numbers in an array
    • mathutils.get_map_value(map, key) - Retrieves values from dictionaries
    • mathutils.create_person(name, age) - Creates and returns a person dictionary
Running the Example
cd examples/extending
go run .

This will execute a comprehensive Scriptling script that demonstrates all the extension features.

Key Concepts

Function Signature

All Scriptling functions must follow this signature:

func(ctx context.Context, kwargs object.Kwargs, args ...object.Object) object.Object
Type System

Scriptling objects include:

  • *object.String - String values
  • *object.Integer - Integer values
  • *object.Float - Float values
  • *object.Boolean - Boolean values
  • *object.List - Lists/arrays
  • *object.Dict - Dictionaries
Error Handling

Return error messages as strings:

return object.NewString("Error: invalid argument")
Registration
  • Functions: p.RegisterFunc(name, function)
  • Libraries: p.RegisterLibrary(library) (name is extracted from library)

Advanced Topics

For more advanced examples including:

  • Output capture for logging
  • State management in libraries
  • Database integration
  • HTTP clients
  • Testing custom extensions

See the Go Integration documentation at scriptling.dev.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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