Documentation
¶
Overview ¶
Package cpp allows methods on C++ objects to be called directly from the Go runtime without requiring cgo compilation.
For more information on how to use this library, see the project README: https://github.com/lsegal/cppgo/blob/master/README.md
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertRef ¶
ConvertRef converts a C++ object ref into a wrapper obj that can call methods on the reference object. The obj interface type should be a struct containing function pointers matching the interface of the C++ class. For example, given the following class:
class Math { public: int multiply(int value, int times); }
You might create a struct type Math as follows:
type Math struct { Multiply func(value, times int) int }
You would then call ConvertRef with a pointer to this structure.
Example ¶
package main import ( "fmt" cpp "github.com/lsegal/cppgo" "github.com/lsegal/cppgo/dl" ) var get_object *dl.Func type lib struct { GetInt func() int `call:"cdecl"` GetBool func(b bool) bool `call:"this"` FlipBool func(b *bool) GetString func() string GetSelf func() *lib TestValues func(string, int, uintptr) bool Add func(n, m int) int `call:"std"` } func objref() uintptr { o, _ := get_object.Call() return o } func main() { /* // with Go type `lib`: type lib struct { GetString func() string } // and C++ class Library: class Library { public: const char *get_string(); } */ var l lib err := cpp.ConvertRef(objref(), &l) if err != nil { return } fmt.Println(l.GetString()) }
Output: hello world
Types ¶
This section is empty.
Directories
¶
Path | Synopsis |
---|---|
Package asmcall implements low-level ABI method calls for various C calling conventions without using cgo.
|
Package asmcall implements low-level ABI method calls for various C calling conventions without using cgo. |
cdecl
Package cdecl implements method call ABI for the POSIX C/C++ calling convention.
|
Package cdecl implements method call ABI for the POSIX C/C++ calling convention. |
stdcall
Package stdcall implements method call ABI for the __stdcall calling convention.
|
Package stdcall implements method call ABI for the __stdcall calling convention. |
thiscall
Package thiscall implements method call ABI for the __thiscall calling convention.
|
Package thiscall implements method call ABI for the __thiscall calling convention. |
Package dl implements support for loading dynamic libraries at runtime without cgo.
|
Package dl implements support for loading dynamic libraries at runtime without cgo. |
internal
|
|
Click to show internal directories.
Click to hide internal directories.