ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility and modern design in mind. It is an ECMAScript-inspired, embedded functional-like language.
ChaiScript is licensed under the BSD license.
ChaiScript is the first and only scripting language designed from the ground up with C++ compatibility and modern design in mind. It is an ECMAScript-inspired, embedded functional-like language.
ChaiScript is licensed under the BSD license.
Due to an increased release schedule, and the nature of ChaiScript being a header-only library, binary releases will be made less often. Previous releases can be found on github.
Version: 4.2.0 Released: 12/1/2012
(Requires Boost)
Source (tar.bz2)
Source (zip)
Version: 5.2.0 Released: 12/1/2012
(Requires C++11 Compiler)
Source (tar.bz2)
Source (zip)
This is a rather crude test and they do not claim to be an absolute measure of performance. If you are somebody give an example - I tried to do more tests.
In turn, I would say that is a really nice Chaisript syntax, and it is easy to register functions and classes (although in python and lua it done about as well), but the question of productivity is still open.
So everyone else knows, I did add a handful of new functions for inserting into maps. Please see https://github.com/ChaiScript/ChaiScript/blob/master/unittests/map.chai for examples. It's also important to remember that map is a direct mapping of std::map.
I'll get a search function added as soon as I can.
-Jason
Object lifetime works like it does in C++:
ChaiScript has never been intended for doing calculations with fast performance. If you truly need to sum 10,000 digits, make a C++ function that does it and export the function to ChaiScript. There is ChaiScript's main advantage: you can expose a C++ to ChaiScript with a simple 1 line of code, far less work than any other scripting language available.
Do you have a more real world example of the code that is slowing you down / making it so you cannot use ChaiScript in your project? Please share and I will work out optimizing for such cases.
Thanks,
Jason
Are you initializing the ChaiScript engine with each frame? That will definitely slow you down. If you are doing a few simple calculations and simply setting some variables, that does surprise me.
Also, have you compared release vs debug builds? ChaiScript performance is heavily influenced by compiler optimization settings.
Can you paste what your per-frame code is like and I can run some tests to see if I can optimize it further.
Thanks,
Jason
var obj := Object() // alloc 200 Mb memory
var obj2 := obj.work() // alloc 100 Mb memory
var obj = 0 // free 200 Mb memory
I also care about this issue, and therefore I decided to do a little test. I compared the python and chaisript:
python:
chaiscript:
the result:
Python time: ~10ms
Chaiscript time: ~1600ms
!!!!!!
But, this is not the best example. Let me know if you want more tests.
But as long as the ChaiScript seems not so fast. Especially given the fact that Python is quite slow embedded language and I find it very frustrating. =(
UPD:
python:
chaiscript:
result:
Python time: 2ms
Chaiscript time: 45ms
UPD2:
python:
chaiscript:
lua:
a = 0 b = 0 c = 0 for i=0,10000 do a = 999 b = 1 c = a + b endresult:
Python time: 4ms
Chaiscript time: 244ms !!!
Lua time: 4ms
I am trying to create a map of references.
(These are references to C++ objects, which were created in the C++ and then passed into ChaiScript. I do NOT want to copy the objects themselves into the map, but just store a map of references.)
When I do this: sub_map = [strSellStatus: offerData]
I get this error: ---------------
OTScriptChai::ExecuteScript:
Caught chaiscript::exception::eval_error:
Can not find appropriate copy constructor or 'clone' while inserting into Map..
File:
Start position, line: 0 column: 0
End position, line: 0 column: 0
Error: "Can not find appropriate copy constructor or 'clone' while inserting into Map." With parameters: (OTDB_OfferDataNym) during evaluation at (3596, 28)
===> HOW can I insert my objects into this map BY REFERENCE and without having to clone the objects?
===> Cannot find anything about this in the documentation, nor in the unittests.
===> (In fact the unittests don't show at all how to add objects to an existing map -- only how to construct one. I'm using += as a guess.)
===> I also tried to search the forum but couldn't find the search functionality. Educate me?
===> Perhaps there is some reference wrapper?
Like this: sub_map = [strSellStatus: ref offerData]
Or this: sub_map = [strSellStatus: Ref_Wrapper(offerData)]
===> Or is that the solution? (That I should just write my own "reference wrapper" class.)
PS: I use ChaiScript 4.0.0.
Unfortunately, I still had problems. I will try to describe them.
1. I download zip archive from GitHub with latest version of ChaiScript
2. Extract the archive in "$PROJECT_FOLDER/chaiscript"
3. Do "cd chaiscript", "cmake ." and "make"
After that, in chaiscript folder appears binary "chai". It works fine(!).
Then I write some code in $PROJECT_FOLDER/main.cpp :
and build it. I use QtCreator to build. On output:
it build programm called "dummy" in $PROJECT_FOLDER/../.dummy-release
next if i try to exec binary i have error like in first message of this topic.
I tried to run from different locations:
$PROJECT_FOLDER
$PROJECT_FOLDER/chaiscript
$PROJECT_FOLDER/../.dummy-release
But the problem did not disappear...
Then i check chaiscript folder. I found "libreflection.so", "libstl_extra.so", "libtest_module.so", but no "libchaiscript_stdlib.so" or some other .so files.
In CMakeList.txt i found references to flection and stl_extra libraries, but nothing about chaiscript_stdlib or something similar.
Please, help me. How to build chaiscript_stdlib library?
By the way: Why not distribute everything in a library with headers like others? =)
I'll wait for the implementation of this feature =)
By the way, can I also override the class method?
And do you have a plan of work for which you are moving? =)
Can we see something like what to expect in the new versions? =)
I'm glad you found a solution that works for you. The problem is a "feature" of the C++ language. A class does not have a vtable if it has no virtual functions. If it doesn't have a vtable,
dynamic_castcannot be used. Ifdynamic_castcannot be used, I cannot supportbase_class.-Jason
Considering C++ functions are so easy to add, the best bet would be to
throwfrom inside of a C++ callback.This is on par with what other scripting engines allow you to do.
A possible other option would be to insert points into the chaiscript evaluation code that allows you to interrupt loops internally. Options like that would slow down the interpreter, however.
What are your thoughts?
-Jason
You can do it on a temporary basis in a local context:
but that's not really what you want.
I've made a feature request to add it.
https://github.com/ChaiScript/ChaiScript/issues/67
-Jason
On a side note, if you would like to support just one function to make it more accessible to your users (or yourself) you could add a ChaiScript overload:
This will work with any value that can be converted to an
unsigned_int. It will take lower priority over the strongly typed C++ version you registered so will only add overhead in the case where you call it with anything other than an unsigned_int.-Jason
It is cumbersome, I agree, but ChaiScript has a few unique challenges, trying to straddle the line between C++ and Scripting Land.
If we support automatic conversions, it makes the choice as to which version of the function to call much more complicated (say, if you had both signed and unsigned versions of a method). It also adds a fair bit of overhead to make that determination at runtime.
It might happen in the future, but it is pretty low priority right now.
-Jason
Glad to know it's working!
Jason
i had success binding it as std::function
Sorry for the long absence. I can not remember which version I used, but I decided to also check everything again.
I downloaded version 5.0.0 and try to compile test program (interpreter) with and without multithreaded support option and run it. In both cases, no errors =) I'm sorry for your time. I'll let you know if the error is repeated =)
Do you plan to support automatic conversions? Or is it one of the feature of ChaiScript?
The first thing I thought, it's situation like this:
c++:
If i export this functions, i can do like this:
but can't do:
and i must do:
I think it's a little uncomfortable. But this is my personal opinion. How do you look at this problem?
P.S. Sorry for bad English
What you are asking for is virtually impossible. We could build a library, but it could not be used in the way you ask. The problem is that most of ChaiScript is necessarily template based. Templates are required for automatically determining the types of objects and functions that are wrapped. Any change to the ChaiScript internals would invalidate the code you have wrapped and swapping out a DLL would do no good.
Your best bet would be to just keep using it as a header only library and swap out your shared code as a DLL.
-Jason
Please see this task for more info and a solution to what you need: https://github.com/ChaiScript/ChaiScript/issues/25
-Jason
Great, I'm glad you got it working. Sorry I had not yet had time to set up a mingw dev environment myself.
It's unfortunate you cannot make a debug build, just in case you needed it later.
I have no cmake available (basically all I can work with is make). I use the official MinGW distribution http://www.mingw.org/ 32 Bit latest install from repositories.
As for the gcc usage, in your documentation: http://chaiscript.com/doxygen/index.html
The command line for compiling the first sample is
EDIT:
I managed to compile the code with
(I had to download libdl.a for mingw, for some reason its not packed with all the other libraries)
The -O3 option seems to do the trick (source: http://permalink.gmane.org/gmane.comp.parsers.spirit.general/24423)
I guess this is really a problem with gas
And now if you excuse me, I have a new script language to mess around with
Another user brought up the same question. There are some technical details that I have to look into, but it might be possible to make the state switching also swap out the local variables.
-Jason