7 ms·
I have been looking through it, and examples, and code, and I guess the main question condensing in my mind is one big "Why"? Why use this, why yet another scri
by Erlich_Bachman 7y ago
I have been looking through it, and examples, and code, and I guess the main question condensing in my mind is one big "Why"? Why use this, why yet another scripting language?
Why not just use Lua, one of JavaScript engines, Python, etc? They all have C++ bindings, all relatively easy to use. All are already used in many C++ apps for this exact purpose... (I guess it's not commonly known in all coder circles, but all those languages can just as easily be embedded in a C++ codebase as this.)
- bbmario 7y agoDifferent projects have different needs. My current game project requires complex game code. I don't want to write complex code in Lua, but I also don't want to kill my productivity with raw C++. Therefore, I prototype and experiment with a scripting language that fits my needs. In my case, it is Wren. Some people prefer Chai, AngelScript, Lua, mruby, etc.
- Erlich_Bachman 7y agoVery interesting, can you outline your thought process on why you did not want to write complex code in lua? It's very stable and fast, and has many language constructs etc? It would be completely understandable if your answer is just "this other thing looked cool and I wanted to try it", which is everyone's own choice, but I am wondering if there were any technical reasons for that decision?
- bbmario 7y agoI can't talk about the others, so I'll compare Wren and Lua. I dislike Lua's approach to objects, feels clunky and prototype-ish. I also dislike the local/global stuff. Wren has exception-like error handling and concurrency. And the object model is very similar to C#.
- bsenftner 7y agoI used to develop a game engine that used an embedded version of Visual Studio to allow C/C++ scripting which compiled into dlls and were hot loaded with any change. And if I recall correctly, that is exactly how the feature film compositor Shake worked: their shader language and entire node graph system is C macros and templates to disguise the fact that it's really C++, and one's compositor projects are really disguised visual studio projects.
- bbmario 7y agoYou might like this: https://fungos.github.io/blog/2017/11/20/cr.h-a-simple-c-hot-reload-header-only-library/ https://fungos.github.io/blog/2017/11/20/cr.h-a-simple-c-hot... And this: https://chrismdp.com/2015/08/how-to-add-live-code-reload-to-your-game/ https://chrismdp.com/2015/08/how-to-add-live-code-reload-to-...
- earenndil 7y agoYep. I write my engine in D, which is nicer than c++ for prototyping, but regardless I embed a scheme for scripting.
- zem 7y agocould you tell me more about the D/scheme integration - specifically what scheme you used, and what you had to do to integrate it with D? i spent a couple of days trying to integrate chibi with D, but gave up because it made too much use of preprocessor macros.
- earenndil 7y agoI shopped around quite a bit and eventually decided that s7 scheme[1] would be the best for me. It's been fairly painless to integrate so far, I've just copy-pasted the function prototypes I've needed, as I've needed them. No macros. Engine is closed-source atm so I can't show code, but it's a pretty straight translation from the c examples. 1: https://ccrma.stanford.edu/software/snd/snd/s7.html https://ccrma.stanford.edu/software/snd/snd/s7.html
- zem 7y agothanks, that looks great!
- mehrdadn 7y agoJS and Python are slow [see below] and heavyweight. Lua might work, I don't know... but this being header-only makes it pretty nice for simpler situations. EDIT: Sorry, I wrote this a little too quickly and ended up writing a bit too coarse of a description. I meant JS and Python are both heavyweight to include in a project, and Python is slow both to initialize and to run. I didn't mean JS is slow to run. I don't know how fast it starts up either.
- Erlich_Bachman 7y agoI'm not sure about JS being necessarily that slow... The browser engines have done tremendous work in the last decade to make it very performant. It approaches java in some regards... It would be interesting to even see applications where this difference would be noticeable, let alone application examples where there would need to be so much complex logic in scripting itself, and also so much sheer computation requirements where this would ever make any difference... Also then, if this would be the selling point of ChaiScript, I would want to see some benchmarks (I have a hard time believing it will outperform lua with the built-in JIT or one of the faster JS engines with optimizations (it's not like performance is a novel desire in embeddable scripting languages, tons of manhours have been put into them already))... The website doesn't seem to have any such benchmarks.
- mehrdadn 7y agoSee my edit, I think I was a little unclear with what precisely each adjective was referring to...
- Erlich_Bachman 7y agoAlright, makes some sense and explains why they are doubling down on this "header only" thing.
- rienbdj 7y agoIt is ridiculous that header-only is considered an advantage. The state of C++ build tools is very poor, and it is harming the language as a whole.
- eigenbom 7y agoFrom their GitHub page: "ChaiScript is one of the only embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques, working with the developer how they would expect it to work. Being a native C++ application, it has some advantages over existing embedded scripting languages: It uses a header-only approach, which makes it easy to integrate with existing projects. It maintains type safety between your C++ application and the user scripts. It supports a variety of C++ techniques including callbacks, overloaded functions, class methods, and stl containers."
- humanrebar 7y ago> ...modern C++ development techniques... Shipping header only is really admitting that modern C++ still has a lack of technique, sidestepping the lack of modules and packaging for instance.
- geezerjay 7y agoThe decision to go with a headers-only design is only required if you want/need to provide templates. Furthermore, it's ignorant to conflate headers-only libraries with a problem or a shortcoming.
- humanrebar 7y agoBeing realistic and admitting that C++ has tooling and packaging issues isn't being ignorant. Quite the opposite. The fact that Header Only is one of the five bolded features of this project indicates that "modern C++ development" includes basically giving up on many desirable features of software projects. It's probably fair enough, but I wouldn't necessarily hold it up over other less "modern" designs like providing a C ABI, which you can still do with C++ using C++17, following basically all of CppCoreGuidelines in the implementation, using state of the art tooling, etc.
- Const-me 7y ago> giving up on many desirable features of software projects Some C++ libraries are header only because they were designed for highest performance possible. Classic example is std::sort versus qsort, C++ usually wins because inlining. My favorite example is Eigen, they use template metaprogramming to save RAM traffic. When you write x=a+b+c for matrices or vectors, the library doesn't compute a+b intermediate vector. That C++ expression returns a placeholder object of a weird type, CPU computes a+b+c in a single loop over them, reading a,b,c, and writing to x.