Documentation
¶
Overview ¶
Package native lets Go code define Kukel modules: functions, constants and native classes, whose objects carry a Go value and whose member functions are written in Go. A program uses one with "use name;", like a module written in Kukel, and reaches its names as name::x.
A module registers itself (Register, usually from an init function); the loader, the compiler and the VM look modules up by name. Native classes have no data members: everything goes through member functions. A Kukel class can derive from a native class that has a constructor; its objects then hold the Go value too, once the derived constructor has called the native one.
Index ¶
- func Global(qualified string) (value.Value, bool)
- func Names() []string
- func Omit(name, why string)
- func Omitted(name string) (string, bool)
- func Prepare(m *Module)
- func Register(m *Module)
- type Args
- func (a Args) Errorf(kind string, format string, args ...any) error
- func (a Args) Has(i int) bool
- func (a Args) Int(i int) (int64, error)
- func (a Args) Number(i int) (float64, error)
- func (a Args) Object(i int, c *Class) (any, error)
- func (a Args) String(i int) (string, error)
- func (a Args) TypeError(i int, want string) error
- type Class
- type Config
- type Func
- type Module
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Global ¶
Global returns what a qualified name of a registered module stands for at run time: a function ("json::encode"), a static member function ("time::Time::parse") or a class ("time::Time"). The VM links the global slots of a program with it.
func Omit ¶ added in v0.12.0
func Omit(name, why string)
Omit records that module name is not in this kukel, and why: "it was built with the build tag nozmq", "it was built without the build tag tk".
func Omitted ¶ added in v0.12.0
Omitted gives why module name is not in this kukel, if a build tag left it out.
Types ¶
type Args ¶
type Args struct {
Name string // as in messages: "json::encode", "time::Time::format"
V []value.Value
}
Args are the arguments of a call of a native function, for checking them with messages like those of the built-ins.
func (Args) Errorf ¶
Errorf returns a Kukel exception of the given kind (value.ValueError, value.TypeError, ...), prefixed with the function's name.
func (Args) Object ¶
Object returns the Go value of argument i, which must be an object of class c or of a class derived from it.
type Class ¶
type Class struct {
Name string
New value.NativeMethod
Methods map[string]value.NativeMethod
Statics map[string]Func
Show func(o *value.ObjectObj) string
// contains filtered or unexported fields
}
Class is a native class. Methods and Statics are its instance and static member functions. New is its constructor (for "new name::C(...)"): it sets this.State; without one, objects only come from the module's functions (Class.Object). Show formats an object for str() and println; without it an object shows as "name::C{}".
func (*Class) Is ¶ added in v0.9.0
Is reports whether v is an object of class c, or of a class derived from it, with its Go value set up.
func (*Class) QualifiedName ¶
QualifiedName is "module::Class".
type Config ¶
type Config struct {
Modules []*Module // this program's own modules (prepared), found before the registered ones
AllowedModules map[string]bool // registered modules the program may use; nil: all
DeniedBuiltins map[string]bool // built-ins the program may not use
Path []string // directories where "use" looks for name.kkl after the using file's directory
NoFileModules bool // "use" never reads .kkl files (modules written in Go only)
}
Config is what one program may use beyond its own code: modules written for it (by a Go program that embeds Kukel), which of the registered modules and built-ins are allowed, and where "use" finds modules written in Kukel. The compiler, the loader and the VM (also of the program's workers) follow it. A nil *Config allows everything and finds Kukel modules only next to the files that use them.
func (*Config) BuiltinDenied ¶
BuiltinDenied reports whether the program may not use built-in name.
func (*Config) Disallowed ¶
Disallowed reports whether name is a registered module the program may not use (for a clearer message than "not found").