-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlua-basics.go
More file actions
79 lines (60 loc) · 1.34 KB
/
lua-basics.go
File metadata and controls
79 lines (60 loc) · 1.34 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
78
79
package luajit
import (
"unsafe"
)
/*
#include <stdlib.h>
#include <lua.h>
*/
import "C"
type Index C.int
type UpvalueIndex C.int
type Integer C.int
type Number C.double
const (
RegistryIndex = Index(C.LUA_REGISTRYINDEX)
GlobalsIndex = Index(C.LUA_GLOBALSINDEX)
)
func (L *State) GetTop() Index {
return L.Y_lua_gettop()
}
func (L *State) SetTop(index Index) {
L.Y_lua_settop(index)
}
func (L *State) Pop(n int) {
L.Y_lua_pop(n)
}
func (L *State) pushvalue(index Index) {
L.Y_lua_pushvalue(index)
}
func (L *State) pushlightuserdata(ptr unsafe.Pointer) {
L.Y_lua_pushlightuserdata(ptr)
}
func (L *State) newuserdata(size int) (ptr unsafe.Pointer) {
return L.Y_lua_newuserdata(size)
}
func (L *State) newuserdata_Type(uType any) (ptr unsafe.Pointer) {
return L.Y_lua_newuserdata(int(unsafe.Sizeof(uType)))
}
func (L *State) pushcclosure(fn LuaCFunction, nUpvalues int) {
L.Y_lua_pushcclosure(fn, nUpvalues)
}
func (L *State) remove(index Index) {
L.Y_lua_remove(index)
}
func (L *State) insert(index Index) {
L.Y_lua_insert(index)
}
// convert from relative to absolute
func (L *State) abs_index(index Index) Index {
if index > 0 || index <= RegistryIndex {
return index
}
return Index(L.GetTop()) + index + 1
}
func upvalueindex(i UpvalueIndex) Index {
return y_lua_upvalueindex(i)
}
func (L *State) NewTable() {
L.Y_lua_newtable()
}