-
Notifications
You must be signed in to change notification settings - Fork 4
/
library.go
32 lines (26 loc) · 1.24 KB
/
library.go
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
package library
import (
"ghostlang.org/x/ghost/library/functions"
"ghostlang.org/x/ghost/library/modules"
"ghostlang.org/x/ghost/object"
)
var Functions = map[string]*object.LibraryFunction{}
var Modules = map[string]*object.LibraryModule{}
func init() {
RegisterModule("console", modules.ConsoleMethods, modules.ConsoleProperties)
RegisterModule("ghost", modules.GhostMethods, modules.GhostProperties)
RegisterModule("http", modules.HttpMethods, modules.HttpProperties)
RegisterModule("io", modules.IoMethods, modules.IoProperties)
RegisterModule("math", modules.MathMethods, modules.MathProperties)
RegisterModule("os", modules.OsMethods, modules.OsProperties)
RegisterModule("random", modules.RandomMethods, modules.RandomProperties)
RegisterModule("time", modules.TimeMethods, modules.TimeProperties)
RegisterFunction("print", functions.Print)
RegisterFunction("type", functions.Type)
}
func RegisterFunction(name string, function object.GoFunction) {
Functions[name] = &object.LibraryFunction{Name: name, Function: function}
}
func RegisterModule(name string, methods map[string]*object.LibraryFunction, properties map[string]*object.LibraryProperty) {
Modules[name] = &object.LibraryModule{Name: name, Methods: methods, Properties: properties}
}