Are there any C bindings/libs for Apache Cassandra? Or, alternatively, is there a way to use the C++ binding/library "libcql" with C, and if so, how?
Pure C and cassandra dont mix well because there isn't much support for C in the Thrift protocol. I dont know of any binary C APIs either.
There is a 'proof-of-concept' C API but the author highlights that this shouldn't be used in production. This SO question has another C++ library mentioned, but it looks like there isn't much support for C.
Related
I have a C NIF in my Erlang project that has limitations, due to libraries that it relies on (unstable libraries, or libraries that I need that don't exist). I think that I can do what I want to do, in Go. Can Erlang interface to Go like this?
Summarizing the above comments into an answer:
There is no such thing as a simple Go NIF
The standard Erlang approach to needing to make foreign calls of moderate weight is to write a port driver. There's an example of calling Go from Erlang in this answer.
A more heavyweight solution is to implement the distribution interface and make a whole foreign node. There's some code to do this that might be interesting.
If you really wanted to make a Go NIF, you'd want to write a C interface to Go, then call that C interface as your NIF.
Hello Stackoverflowians -
I'm working with an embedded system that's written in C that communicates over a cell modem to a server written in Ruby on Rails. There message format is fairly simplistic and uses several constants to define messages types.
Right now, the ruby side of things takes the C include file, and scans for the constant definitions, and imports those via const_set.
Is there a better way to keep the ruby side sync'ed up with the C side of this project?
Thanks,
-- Mike
Since you're comfortable with C, my suggestion would be to create a Ruby extension in C that uses the header from the C application to expose the constants. That way you're not stuck to declaring the constants in a specific way or custom parsing routines.
See guides.rubygems.org for a concise introduction to the topic.
I was reading on terralang site about terra language as
"a new low-level system programming language that is designed to
interoperate seamlessly with the Lua programming language..."
Zach DeVito (the main author) write about the use of terra :
A scripting-language with high-performance extensions.....
An embedded JIT-compiler for building languages.....
A stand-alone low-level language....
But (may be my fault) I don't understand if terra is:
a luaJit competitor
a better system to interface with c library
something better than luaJit using llvm
Can someone help me to better understand what is going on terralang project ?
Thanks
But (may be my fault) I don't understand if terra is:
a luaJit competitor
It is not. It is built on top of LuaJIT and LLVM. LuaJIT is written by Mike Pall and LLVM is written by Apple and the community. It can do two things.
1) It adds extra language syntax (dubbed Terra) to your Lua code. In this way, you can mix Lua code with hard core low level code with great ease.
2) It allows you to generate fast code at runtime. Great if you want to create new languages, compilers or generate fast machine code without all the work normally associated with this.
a better system to interface with c library
Yes and No. If all you want to do is call existing C or other native libraries from Lua, I recommend using LuaJIT as is. Mike Pall has done a fantastic job at this and a lot of the C integration magic comes from LuaJITs FFI. But if you need to create new "C like" code mixed together with your Lua program, Terra is nice. You have a dynamic language / status language hybrid.
something better than luaJit using llvm
No, Lua code is still evaluated using LuaJIT and Terra code uses LLVM.
Summary
Terra is fantastic, I can really recommend it.
I want to write an OCaml library which will be used by other programing languages like C or even python.
I not sure it's even feasible, and i guess i need to drop some type safety and add runtime checks to the interface for dynamically typed language.
Is it doable ? Is there tools to achieve this goal to auto-generate bindings ? I think stuffs like Corba do not fit well with ocaml ABI, but I may be wrong.
EDIT : by dropping the runtime requirement and using only languages having a llvm frontend, I could use llvm as a common ABI I guess, but it seems tricky.
OCaml has a FFI to interact with C code. The code for the binding has to be written in C, not in OCaml (which has no direct representation of C values, while C has representations of OCaml values). My advice would be:
On the C side, decide what would be the best interface to export that C programmers would like (or Python programmers writing Python bindings starting from your C interface)
Define a "low-level layer" on the OCaml side that gets your OCaml value as close as possible from the C representation
Write some C wrappers to convert from this low-level OCaml representation to your optimal C representation
The reason for step (2) is to have the step (3) as small as possible. Manipulating OCaml values from the C side is a bit painful, in particular you risk getting the interaction with the Garbage Collector wrong, which means segfaults -- plus you don't get any type safety. So the less work you have to do on the C side, the better.
There are some projects to do some of the wrapping work for you. CamlIDL for example, and I think Swig has some support for OCaml. I have never used those, though, so I can't comment.
If you know to which high-level language you wish to convert your interface to, there may be specialized bridge that don't need a C step. For example there are libraries to interact directly with Python representations (search for Pycaml, not sure how battle-tested their are) or with the Java runtime (the OCamlJava project). A C interface is still a safe bet that will allow other people to create bridges to their own languages.
It is feasible, but you need to understand involved topics, like how the GC works.
Have a look at this: http://caml.inria.fr/pub/docs/manual-ocaml-4.00/manual033.html#toc148
You need to be careful about types in the stub code, but otherwise you can keep type safety.
I've written a Haskell library I would like to include in an iPhone app. It makes heavy use of Haskell's functional abilities, currying, etc. and rewriting in Objective-C would be tough.
Is it possible to automatically translate Haskell to C? or dig out an intermediate C representation from one of the compilers?
Apple's developer agreement forbids statically linking one of the lightweight Haskell interpreters, not that I'm keen on that solution.
I haven't used it but there is
http://projects.haskell.org/ghc-iphone/
http://repetae.net/computer/jhc/ compiles to fairly standard C. It might be possible to use it.
Have a look at the ghc-ios project:
http://www.reddit.com/r/haskell/comments/1lboh4/announcing_ghc_ios/