func TestCallbackWithNoInputParameters(t *testing.T) {
	// Test that NewCallback and NewCallbackCDecl can accept functions without
	// input parameters, see issue 9871.
	cb := func() uintptr { return 0 }
	_ = syscall.NewCallback(cb)
	_ = syscall.NewCallbackCDecl(cb)
}
예제 #2
0
파일: stream.go 프로젝트: tyochiai/nyagos
func (L Lua) pushStream(fd ansicfile.FilePtr, closer func(Lua) int) *stream_t {
	var userdata *stream_t
	userdata = (*stream_t)(L.NewUserData(unsafe.Sizeof(*userdata)))
	userdata.FilePtr = fd
	userdata.Closer = syscall.NewCallbackCDecl(closer)
	L.GetField(LUA_REGISTRYINDEX, LUA_FILEHANDLE) // metatable
	L.SetMetaTable(-2)
	return userdata
}
예제 #3
0
func (test *cbTest) run(t *testing.T, dllpath string) {
	dll := syscall.MustLoadDLL(dllpath)
	defer dll.Release()
	cb := cbFuncs[test.n]
	stdcall := syscall.NewCallback(cb)
	f := cbDLLFunc(test.n)
	test.runOne(t, dll, f.stdcallName(), stdcall)
	cdecl := syscall.NewCallbackCDecl(cb)
	test.runOne(t, dll, f.cdeclName(), cdecl)
}
예제 #4
0
파일: lua.go 프로젝트: tyochiai/nyagos
func (this Lua) Dump() []byte {
	buffer := make([]byte, 0, 1024)

	rc, _, _ := lua_dump.Call(
		this.State(),
		syscall.NewCallbackCDecl(callback_writer),
		uintptr(unsafe.Pointer(&buffer)))
	if rc == 0 {
		return buffer
	} else {
		return nil
	}
}
예제 #5
0
파일: loadfile.go 프로젝트: tyochiai/nyagos
func (L Lua) LoadFile(path string, mode string) (int, error) {
	fd, err := os.OpenFile(path, os.O_RDONLY, 0666)
	if err != nil {
		return 0, err
	}
	defer fd.Close()

	path_ptr, path_err := syscall.BytePtrFromString(path)
	if path_err != nil {
		return 0, err
	}
	mode_ptr, mode_err := syscall.BytePtrFromString(mode)
	if mode_err != nil {
		return 0, err
	}
	callback := syscall.NewCallbackCDecl(callback_reader)
	load_buffer_mutex.Lock()
	defer load_buffer_mutex.Unlock()
	rc, _, _ := lua_load.Call(
		L.State(),
		callback,
		uintptr(unsafe.Pointer(fd)),
		uintptr(unsafe.Pointer(path_ptr)),
		uintptr(unsafe.Pointer(mode_ptr)))

	if rc == LUA_OK {
		return 0, nil
	} else if rc == LUA_ERRSYNTAX {
		return LUA_ERRSYNTAX, errors.New("lua_load: LUA_ERRSYNTAX")
	} else if rc == LUA_ERRMEM {
		return LUA_ERRMEM, errors.New("lua_load: LUA_ERRMEM")
	} else if rc == LUA_ERRGCMM {
		return LUA_ERRGCMM, errors.New("lua_load: LUA_ERRGCMM")
	} else {
		return int(rc), fmt.Errorf("lua_load: returns %d", rc)
	}
}
예제 #6
0
파일: push.go 프로젝트: kissthink/nyagos
func (this Lua) PushGoFunction(fn func(Lua) int) {
	lua_pushcclosure.Call(uintptr(this), syscall.NewCallbackCDecl(fn), 0)
}
예제 #7
0
func nativeLoop() {
	_nativeLoop.Call(
		syscall.NewCallbackCDecl(systray_ready),
		syscall.NewCallbackCDecl(systray_menu_item_selected))
}
예제 #8
0
파일: push.go 프로젝트: tyochiai/nyagos
func (this Lua) PushGoClosure(fn func(Lua) int, n uintptr) {
	lua_pushcclosure.Call(this.State(), syscall.NewCallbackCDecl(fn), n)
}