Skip to content

dart:ffi how to describe in dart GoString and GoSlice structures generated by go #37509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Jul 12, 2019 · 6 comments
Closed
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi

Comments

@ghost
Copy link

ghost commented Jul 12, 2019

Here (gist) dart and go code with generated header file.
i tried with Utf8 class from sqlite example, it's seems work.
calling add 1, 2: 3
calling cosine 2pi: 1.0
callin log��U��o��U�����U@�o��UP�o��U��o��UP�o��Uf��o��U��o��U��o��U��o��U��o��U��o��U�o��U�o��U �o��U0�o��U@�o��UP�o��U�o��Up�o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U�o��U�o��U �o��U0�o��U@�o��UP�o��U�o��Up�o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U�o��U�o��U �o��U0�o��U@�o��UP�o��U�o��Up�o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U�o��U�o��U �o��U0�o��U@�o��UP�o��U`�o��Up�o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U��o��U
1

@ghost ghost changed the title dart:ffi how to describe in dart GoString and GoSlice generated by go dart:ffi how to describe in dart GoString and GoSlice structures generated by go Jul 12, 2019
@vsmenon vsmenon added library-ffi area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Jul 12, 2019
@sjindel-google
Copy link
Contributor

Here's a working Gist which uses your "Log" function:

https://gist.github.com/sjindel-google/b88c964eb260e09280e588c41c6af3e5

Note that because GoString is represented as a struct in C, you have to pass it to the Go function by pointer (*string in Go) because we don't supporting passing structs directly to native functions.

@sjindel-google
Copy link
Contributor

/cc @mraleph @dcharkes

@crossle
Copy link

crossle commented Jan 10, 2020

@sjindel-google how to return a GoString when dart call golang return string, like go code

func hello() (string, error) {
   return "", nil
}

@dcharkes
Copy link
Contributor

We need support for passing structs by values in the calling convention for that. See #36730.

@sjindel-google
Copy link
Contributor

In the meantime you can use a string* in Go (GoString* in C).

@crossle
Copy link

crossle commented Jan 10, 2020

Thanks @dcharkes @sjindel-google, hope support soon.
How about the return multiple values like go return error and another value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-ffi
Projects
None yet
Development

No branches or pull requests

4 participants