Re: [go-nuts] ask for you help about cgo and interface

2019-12-04 Thread Ian Lance Taylor
On Wed, Dec 4, 2019 at 5:21 PM FAN DEAR  wrote:
>
> First of all, thank you very much for your reply.
> Actually, what I want to do is to use golang to complete the TCP 
> communication SDK.
> When C++ calls golang to send a message,
> I need to tell the C++ message sending status at the appropriate time, such 
> as sending failed, sending successfully, and the reply received.
> Here are some code snippets:

When calling between C++ and Go, you need to call functions by name.
You can't use an interface.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWkSmxGRHrhp-m9F1%3DuZ00z8DbHDHNz%3DkPgjzrGY2ERPA%40mail.gmail.com.


Re: [go-nuts] ask for you help about cgo and interface

2019-12-04 Thread FAN DEAR
First of all, thank you very much for your reply.
Actually, what I want to do is to use golang to complete the TCP 
communication SDK. 
When C++ calls golang to send a message, 
I need to tell the C++ message sending status at the appropriate time, such 
as sending failed, sending successfully, and the reply received.
Here are some code snippets:


package test3

import "C"

func main() {

}

//export IRequestListener

type IRequestListener interface {

  OnSendSuccess()

  OnSendFailure(err error)

  OnResponse(msg string)

}


//export GetCard

func GetCard(uid string, listener IRequestListener) {

  disposeRequest(&request{

  message: uid,

  }, func(req *request) {

  listener.OnSendSuccess()

  }, func(req *request, err error) {

  listener.OnSendFailure(err)

  }, func(resp *response) {

  listener.OnResponse(resp.string())

  })

}

Can you give me a sample code? thank you very much!


在 2019年12月3日星期二 UTC+8下午11:28:47,Ian Lance Taylor写道:
>
> On Tue, Dec 3, 2019 at 12:29 AM FAN DEAR > 
> wrote: 
> > 
> > typedef struct { void *t; void *v; } GoInterface; 
> > 
> > 
> > What is *t and *v? 
>
> See https://research.swtch.com/interfaces. 
>
> Ian 
>
>
> > 在 2019年12月3日星期二 UTC+8上午2:41:36,Ian Lance Taylor写道: 
> >> 
> >> On Mon, Dec 2, 2019 at 9:57 AM FAN DEAR  wrote: 
> >> > 
> >> > 
> >> > How to use add2 function, i am very troubled. 
> >> 
> >> On this mailing list please post code as ordinary text, or as a link 
> >> to the Go playground.  Don't post colorized images with a black 
> >> background.  Thanks. 
> >> 
> >> You can't declare a Go interface type in C.  C doesn't have interface 
> >> types.  The only way to use an exported Go function that takes an 
> >> argument of interface type is for a Go function to call a C function 
> >> with an interface value and for that C function to then call a Go 
> >> function. 
> >> 
> >> What are you really trying to do? 
> >> 
> >> Ian 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "golang-nuts" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to golan...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/10a1fea2-fe29-45c3-8261-f92b5baae3df%40googlegroups.com.
>  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/db6734f7-aecf-47e0-8e1d-4e0227d7b74b%40googlegroups.com.


Re: [go-nuts] ask for you help about cgo and interface

2019-12-03 Thread Ian Lance Taylor
On Tue, Dec 3, 2019 at 12:29 AM FAN DEAR  wrote:
>
> typedef struct { void *t; void *v; } GoInterface;
>
>
> What is *t and *v?

See https://research.swtch.com/interfaces.

Ian


> 在 2019年12月3日星期二 UTC+8上午2:41:36,Ian Lance Taylor写道:
>>
>> On Mon, Dec 2, 2019 at 9:57 AM FAN DEAR  wrote:
>> >
>> >
>> > How to use add2 function, i am very troubled.
>>
>> On this mailing list please post code as ordinary text, or as a link
>> to the Go playground.  Don't post colorized images with a black
>> background.  Thanks.
>>
>> You can't declare a Go interface type in C.  C doesn't have interface
>> types.  The only way to use an exported Go function that takes an
>> argument of interface type is for a Go function to call a C function
>> with an interface value and for that C function to then call a Go
>> function.
>>
>> What are you really trying to do?
>>
>> Ian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/10a1fea2-fe29-45c3-8261-f92b5baae3df%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWKCaTM-pw%2B3zZvF6ij8bmbhYE-Tj4mENOZ4BEg6u_erw%40mail.gmail.com.


Re: [go-nuts] ask for you help about cgo and interface

2019-12-03 Thread FAN DEAR


typedef struct { void *t; void *v; } GoInterface;

What is *t and *v?

在 2019年12月3日星期二 UTC+8上午2:41:36,Ian Lance Taylor写道:
>
> On Mon, Dec 2, 2019 at 9:57 AM FAN DEAR > 
> wrote: 
> > 
> > 
> > How to use add2 function, i am very troubled. 
>
> On this mailing list please post code as ordinary text, or as a link 
> to the Go playground.  Don't post colorized images with a black 
> background.  Thanks. 
>
> You can't declare a Go interface type in C.  C doesn't have interface 
> types.  The only way to use an exported Go function that takes an 
> argument of interface type is for a Go function to call a C function 
> with an interface value and for that C function to then call a Go 
> function. 
>
> What are you really trying to do? 
>
> Ian 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/10a1fea2-fe29-45c3-8261-f92b5baae3df%40googlegroups.com.


Re: [go-nuts] ask for you help about cgo and interface

2019-12-02 Thread Ian Lance Taylor
On Mon, Dec 2, 2019 at 9:57 AM FAN DEAR  wrote:
>
>
> How to use add2 function, i am very troubled.

On this mailing list please post code as ordinary text, or as a link
to the Go playground.  Don't post colorized images with a black
background.  Thanks.

You can't declare a Go interface type in C.  C doesn't have interface
types.  The only way to use an exported Go function that takes an
argument of interface type is for a Go function to call a C function
with an interface value and for that C function to then call a Go
function.

What are you really trying to do?

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcX_1m6Y7cOH%2Bm_ehtLg9AaL-jibEuWq_jdmZF_OvmuPSQ%40mail.gmail.com.