cl: c.Func (llgo.funcAddr); demo: cppintf (how to use c++ interface)
This commit is contained in:
11
_demo/cppintf/foo/bar/bar.cpp
Normal file
11
_demo/cppintf/foo/bar/bar.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#define interface struct
|
||||
|
||||
interface ICallback {
|
||||
virtual int valA() = 0;
|
||||
virtual double valB() = 0;
|
||||
};
|
||||
|
||||
extern "C" void f(ICallback* cb) {
|
||||
printf("Hello %d, %lf!\n", cb->valA(), cb->valB());
|
||||
}
|
||||
22
_demo/cppintf/foo/foo.go
Normal file
22
_demo/cppintf/foo/foo.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
LLGoFiles = "bar/bar.cpp"
|
||||
LLGoPackage = "link"
|
||||
)
|
||||
|
||||
type Callback struct {
|
||||
Vptr *CallbackVtbl
|
||||
}
|
||||
|
||||
type CallbackVtbl struct {
|
||||
ValA unsafe.Pointer
|
||||
ValB unsafe.Pointer
|
||||
}
|
||||
|
||||
//go:linkname F C.f
|
||||
func F(cb *Callback)
|
||||
BIN
_demo/cppintf/foo/llgo_autogen.lla
Normal file
BIN
_demo/cppintf/foo/llgo_autogen.lla
Normal file
Binary file not shown.
Reference in New Issue
Block a user