about summary refs log tree commit diff
path: root/pkg/lang/modules/natives/natives.go
blob: a1b09b647aba4fb247d62867bbc078517c142fb3 (plain)
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
package natives

import (
	"jinx/pkg/lang/modules/core"
	"jinx/pkg/lang/vm/executor"
)

var Natives = makeNatives(
	core.Natives,
)

func makeNatives(moduleNativesArrays ...[]any) []Native {
	natives := make([]Native, 0)

	for _, moduleNatives := range moduleNativesArrays {
		for _, moduleNativeI := range moduleNatives {
			moduleNative := moduleNativeI.(moduleNative)

			natives = append(natives, Native{
				Name:     moduleNative.Name(),
				ArgCount: moduleNative.ArgCount(),
				Fn:       moduleNative.Fn(),
			})
		}
	}
	return natives
}

type Native struct {
	Name     string
	ArgCount int
	Fn       executor.NativeFunc
}

type moduleNative interface {
	Name() string
	ArgCount() int
	Fn() executor.NativeFunc
}