-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
38 lines (28 loc) · 1.02 KB
/
util.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
33
34
35
36
37
38
package gobindlua
import (
"fmt"
lua "github.com/yuin/gopher-lua"
)
func FuncResCastError(L *lua.LState, res int, exp string, got any) {
L.RaiseError("function result number %d expects %s, received %T", res, reduceUserData(exp), reduceUserData(got))
}
func TableElemCastError(L *lua.LState, level int, exp string, got any) {
L.RaiseError("inner table assignment, level %d, expects %s, received %T", level, reduceUserData(exp), reduceUserData(got))
}
func CastArgError(L *lua.LState, arg int, exp string, got any) {
L.ArgError(arg, fmt.Sprintf("expected %s, received %T", reduceUserData(exp), reduceUserData(got)))
}
func badArrayOrTableCast(exp, got any, level int) error {
exp = reduceUserData(exp)
got = reduceUserData(got)
if level == 0 {
return fmt.Errorf("expected %T, received %T", exp, got)
}
return fmt.Errorf("inner table assignment (level %d) expected %T, received %T", level+1, exp, got)
}
func reduceUserData(d any) any {
if ud, ok := d.(*lua.LUserData); ud != nil && ok {
return ud.Value
}
return d
}