summaryrefslogtreecommitdiff
path: root/misc/swig/callback/run.go
blob: b3f13ad908bdaa294b9ade676807fcdbd0d44d41 (plain)
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
// Copyright 2011 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"swig/callback"
)

type GoCallback struct{}

func (p *GoCallback) Run() string {
	return "GoCallback.Run"
}

func main() {
	c := callback.NewCaller()
	cb := callback.NewCallback()

	c.SetCallback(cb)
	s := c.Call()
	fmt.Println(s)
	if s != "Callback::run" {
		panic(s)
	}
	c.DelCallback()

	cb = callback.NewDirectorCallback(&GoCallback{})
	c.SetCallback(cb)
	s = c.Call()
	fmt.Println(s)
	if s != "GoCallback.Run" {
		panic(s)
	}
	c.DelCallback()
	callback.DeleteDirectorCallback(cb)
}