Crystal C bindings: return type char*
I have a function with this signature: const char* get_version(); My declaration is: fun get_version(): LibC::Char* And to use it: version = MyLib.get_version() puts version # how to convert to String? How can I manage the return string? Do I have to import also strlen to measure the length of the C string and covert it to Crystal string manually?
You wrap the Char* pointer with String.new(MyLib.version). If you know the string length, you may call String.new(ptr, size) too. Note that this will copy the data from the pointer, so the C binding may release its pointer without affecting the Crystal String.
JSON.mapping if “root” attribute has inherit keys
Crystal C bindings: using fopen
Define Class object validations
Set attribute of type “Class” to define it as Int32, String, Float64
Set both default attribute and type of attribute
How can I test private methods?
Write binary data to stdout in Crystal
Unable to compile after upgrade from crystal 0.19.4 to 0.20
Application server for Crystal web app / Kemal
Crystal Fiber error - “Unhandled exception in spawn: SSL_shutdown: Operation now in progress (Errno)”
Convert hex string to int in Crystal
Crystal convert string to hash from response.body
Crystal no overload matches 'Array(Type)#' with type (Int32 | Nil)
Crystal method return multiple values
Reopening class or struct inside macro
define method with UInt8 variable