views:

92

answers:

1

Does anyone know if it is possible to have a C++ class with overloaded operators such as +,-,* and declare it somehow (this is where the magic happens) to a QtScriptEngine such that js-expressions like "a+b" are evaluated as they would be on the C++ side?

A: 

It seems to be impossible. At least that is what I received as an answer in the #qt-labs IRC. However, I think I found a viable alternative: ChaiScript. It embeds itself wonderfully into C++, plays well with Qt and allows for the overloading of operators, and even better the direct use of any(?) C++ data type.

FFox
Do you still care about the original question? I could look into it when i have time and outline a solution if its possible.
Georg Fritzsche
Sure. I pretty sure I'm not the only one interested in this.
FFox
Regarding the "any" question, yes ChaiScript can accept any type passed to it, without any need to tell the engine explicitly about the type, unless you want to add constructors for it. That is, with the minor caveat that it is does not handle volatile.
lefticus
@lefticus I tried Chaiscript, and really liked it. It is very easy to use and integrate into the hosting application. However, I had to learn that the performance of Chaiscript (or maybe any interpreted language) was not sufficient for my purposes. After looking into llvm+clang (I hit a wall there due to the poor Windows support and the everchanging APIs), I am now settled with an embedded mono JIT.
FFox
We have not made a huge focus on performance with ChaiScript, the idea is that it's so easy to embed that any operation that has performance concerns can just be implemented in C++ and exposed. Not sure just how much performance you need, but the Lua JIT solution could have possibly worked for you too.
lefticus