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
70
71
72
73
74
75
76
77
78
79
80
81
|
package main
import (
"github.com/Shopify/go-lua"
"github.com/anon55555/mt"
"image/color"
)
func luaPushVec2(l *lua.State, val [2]float64) {
l.Global("vec2")
l.PushNumber(val[0])
l.PushNumber(val[1])
l.Call(2, 1)
}
func luaPushVec3(l *lua.State, val [3]float64) {
l.Global("vec3")
l.PushNumber(val[0])
l.PushNumber(val[1])
l.PushNumber(val[2])
l.Call(3, 1)
}
func luaPushBox1(l *lua.State, val [2]float64) {
l.Global("box")
l.PushNumber(val[0])
l.PushNumber(val[1])
l.Call(2, 1)
}
func luaPushBox2(l *lua.State, val [2][2]float64) {
l.Global("box")
luaPushVec2(l, val[0])
luaPushVec2(l, val[1])
l.Call(2, 1)
}
func luaPushBox3(l *lua.State, val [2][3]float64) {
l.Global("box")
luaPushVec3(l, val[0])
luaPushVec3(l, val[1])
l.Call(2, 1)
}
func luaPushColor(l *lua.State, val color.NRGBA) {
l.NewTable()
l.PushInteger(int(val.R))
l.SetField(-2, "r")
l.PushInteger(int(val.G))
l.SetField(-2, "g")
l.PushInteger(int(val.B))
l.SetField(-2, "b")
l.PushInteger(int(val.A))
l.SetField(-2, "a")
}
func luaPushStringSet(l *lua.State, val []string) {
l.NewTable()
for _, str := range val {
l.PushBoolean(true)
l.SetField(-2, str)
}
}
func luaPushStringList(l *lua.State, val []string) {
l.NewTable()
for i, str := range val {
l.PushString(str)
l.RawSetInt(-2, i+1)
}
}
// i hate go for making me do this instead of just using luaPushStringList
// but i dont want to make an unsafe cast either
func luaPushTextureList(l *lua.State, val []mt.Texture) {
l.NewTable()
for i, str := range val {
l.PushString(string(str))
l.RawSetInt(-2, i+1)
}
}
|