Re:Purego – A library for calling C functions from Go withou...
by viraptor on Sunday February 12, 2023 @11:38AM
(#34764185)
The example seems straightforward: Include this package, and your usual os calls start going through their "fakecgo" path.
Re:Purego – A library for calling C functions from Go withou...
by totallygamerjet on Sunday February 12, 2023 @12:09PM
(#34764526)
It’s pretty simple to use if you are familiar with dlopen and friends.
Just call purego.Dlopen(“libname.so”, purego.RTLD_GLOBAL)
Take the returned library (make sure to check for errors with purego.Dlerror() first) and call purego.Dlsym(lib, “cfuncName”). If it exists than u can call it with either purego.SyscallN or purego.RegisterFunc
Re:Purego – A library for calling C functions from Go withou...
by mook on Monday February 13, 2023 @01:51AM
(#34770850)
It would be good to have more documentation on usage, though; things like how to deal with struct padding (or packed structs), common OS API types (presumably manual munging of UCS2/UTF16 is needed for Windows), etc; at least to mention that it's unchanged from …/x/sys?
It's easier with dlopen because it's still C and therefore you have the normal headers…
Re:Purego – A library for calling C functions from Go withou...
by mkm40 on Monday February 13, 2023 @02:10AM
(#34770945)
+1 for additional examples or documentation.
Particularly an example that takes a c struct pointer would be awesome.
What happens to const char* return values that are null ? I think it is empty string, but either test case or doc confirming it would be awesome
No documentation, and example has no content makes the learning curve a bit steep.
Does anyone have any pointers on how to use this?