Open craig65535 opened 1 year ago
I should mention I'm using macOS (darwin/arm64).
That is correct. Variadic functions are not supported and there are currently no plans to add them.
Thanks for the response.
I think the documentation for RegisterFunc/RegisterLibFunc could be improved because that wasn't clear to me. But I'm not sure what to change it to, as there is probably some use for the current arrangement with []interface{}
that I'm not aware of.
The current implementation is used to implement the Send method in the objc package. This way the user of the method can call any objc method without having to create a func variable, link it to the C function and then call it.
How do I convert Go []string to C char **
Create a slice of byte. Convert each string to null terminated byte. Then pass the address of the slice to the function. So the signature would be &slice[0] and the type **byte
Please understand that I may be a little unclear in the description, for the case of a C function parameter char **, what type should be used in Go?
**byte like I said
I'm sorry that I can't solve this matter according to your suggestion C:
int test(char *path, char **result, int *len)
Go:
var test func(path string, result **byte, rlen *int) int32
...
purego.RegisterLibFunc(&test, lic, "test")
...
func Test(path string) {
var lenRes int
result := make([]*byte, 0)
_ = test(path, &result[0], &lenRes)
}
...
I'm not sure if that's what you said, but I still haven't gotten the correct data return, The correct result data should be a string, but I only got one byte, what should I do to get the returned string
You actually got all the code right so far. You just need to turn the *byte back into a string. There's no easy way to do this atm. There's discussion in https://github.com/ebitengine/purego/issues/121 about making it more accessible. You can also just copy the code that's inside purego/internal/strings. Ofc you'll have to do that for each pointer in the slice
EDIT: Oh it's a result no a parameter. So instead of using a slice just create a *byte and take the address of that.
I don't really want to busy up this issue more as your question doesn't relate to variadic functions. If you have more questions about this please ask on the discord.
@craig65535 @TotallyGamerJet My libffi wrapper supports variadic functions now. See ffi.PrepCifVar.
Unfortunately ffi doesn't support MacOS yet.
The source has a comment about a special case for variadic functions -
Does this mean they are not supported? I made my own library in C and am unable to find a way to get my function to see any of the variadic parameters.
Calling code:
This prints: