-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlua-type.go
More file actions
77 lines (67 loc) · 1.54 KB
/
lua-type.go
File metadata and controls
77 lines (67 loc) · 1.54 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
70
71
72
73
74
75
76
77
package luajit
import (
"log"
)
/*
#include <stdlib.h>
#include <lua.h>
*/
import "C"
type LuaType int
const (
LUA_TNONE LuaType = C.LUA_TNONE
LUA_TNIL LuaType = C.LUA_TNIL
LUA_TBOOLEAN LuaType = C.LUA_TBOOLEAN
LUA_TLIGHTUSERDATA LuaType = C.LUA_TLIGHTUSERDATA
LUA_TNUMBER LuaType = C.LUA_TNUMBER
LUA_TSTRING LuaType = C.LUA_TSTRING
LUA_TTABLE LuaType = C.LUA_TTABLE
LUA_TFUNCTION LuaType = C.LUA_TFUNCTION
LUA_TUSERDATA LuaType = C.LUA_TUSERDATA
LUA_TTHREAD LuaType = C.LUA_TTHREAD
LUA_TCDATA LuaType = 10
)
func (typ LuaType) String() string {
switch typ {
case LUA_TNONE:
return "none"
case LUA_TNIL:
return "nil"
case LUA_TNUMBER:
return "number"
case LUA_TBOOLEAN:
return "boolean"
case LUA_TSTRING:
return "string"
case LUA_TTABLE:
return "table"
case LUA_TFUNCTION:
return "function"
case LUA_TUSERDATA:
return "userdata"
case LUA_TTHREAD:
return "thread"
case LUA_TLIGHTUSERDATA:
return "lightuserdata"
case LUA_TCDATA:
return "cdata"
default:
log.Fatalf("luajit.(LuaType).String() error : unhandled LuaType %d", typ)
}
return "?"
}
func (L *State) Type(index Index) LuaType {
return L.Y_lua_type(index)
}
func (L *State) TypeName(index Index) string {
return L.Type(index).String()
}
func (L *State) IsType(index Index, typ LuaType) bool {
return L.Type(index) == typ
}
func (L *State) IsNil(index Index) bool {
return L.IsType(index, LUA_TNIL)
}
func (L *State) IsTable(index Index) bool {
return L.IsType(index, LUA_TTABLE)
}