-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclass.go
More file actions
69 lines (53 loc) · 1.6 KB
/
class.go
File metadata and controls
69 lines (53 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2023, Peter Ohler, All rights reserved.
package slip
import (
"strings"
)
// Class represents all class types.
type Class interface {
Object
// Name of the class.
Name() string
// Package the class is defined in.
Pkg() *Package
// Documentation of the class.
Documentation() string
// SetDocumentation of the class.
SetDocumentation(doc string)
// Describe the class in detail.
Describe(b []byte, indent, right int, ansi bool) []byte
// MakeInstance creates a new instance but does not call the :init method.
MakeInstance() Instance
// Inherits returns true if this Class inherits from a specified Class.
Inherits(c Class) bool
// InheritsList returns a list of all inherited classes.
InheritsList() []Class
// LoadForm should return a list that can be evaluated to create the class
// or nil if the class is a built in class. As an example, a flavor would
// be created by a defflavor expression.
LoadForm() Object
// Metaclass returns the name of the class's meta class which can be
// built-in-class, standard-class, flavor, or condition-class.
Metaclass() Symbol
// VarNames for DefMethod, requiredVars and defaultVars combined.
VarNames() []string
}
// Find finds the named class.
func FindClass(name string) (c Class) {
pkg := CurrentPackage
if index := strings.IndexByte(name, ':'); 0 < index {
if pkg = FindPackage(name[:index]); pkg == nil {
return nil
}
name = name[index+1:]
}
return pkg.FindClass(name)
}
// RegisterClass a class.
func RegisterClass(name string, c Class) {
p := c.Pkg()
if p == nil {
p = CurrentPackage
}
p.RegisterClass(name, c)
}