Beispiel #1
0
func (self *RefLua) init(state State, lobject int) {
	self.VM = state.VM
	C.lua_pushvalue(state.L, C.int(lobject))
	refvalue := C.luaL_ref(state.L, C.LUA_REGISTRYINDEX)
	self.Ref = int(refvalue)
	runtime.SetFinalizer(self, func(r *RefLua) {
		r.Release()
	})
}
Beispiel #2
0
func (sinfo *structInfo) makeFieldsIndexCache(vm *VM) {
	L := vm.globalL
	sinfo.cache = make(map[*C.char]*structField, len(sinfo.fields))
	sinfo.lref = make(map[string]int, len(sinfo.fields))
	for key, field := range sinfo.fields {
		pushStringToLua(L, key)
		pstr := C.lua_tolstring(L, -1, nil)
		sinfo.cache[pstr] = field
		sinfo.lref[key] = int(C.luaL_ref(L, C.LUA_REGISTRYINDEX))
	}
}
Beispiel #3
0
// luaL_ref
func (L *State) Ref(t int) int {
	return int(C.luaL_ref(L.s, C.int(t)))
}