9 ms·
ChaiScript – Easy to Use Scripting for C++
- azhenley 7y agoLooks very nice! It would be helpful to have a page that compares it to some of the other popular scripting languages for C++.
- colmvp 7y agoI just have to upvote this since Jason Turner is one of the creators and I owe a ton of my knowledge about C++ to his videos on his YT channel, as well as his talks at CppCon.
- dgellow 7y agoHe's also co-host of the podcast CppCast :) https://cppcast.com/ https://cppcast.com/
- Bootwizard 7y agoWow this looks awesome, great job! I didn't even know I wanted this until I saw it. I am worried though how memory management is handled under the hood. Is it possible to use traditional C++ memory management with any of the variables created in ChaiScript? I'm not saying that I don't trust the implementation, I'd just like more control over it in some cases.
- vishnugupta 7y agoHa! Chai == Tea in Hindi, for those who are wondering ;)
- mlevental 7y agochai is tea in many languages that either inherit from Russian or Arabic https://www.etymonline.com/word/chai https://www.etymonline.com/word/chai Edit: apparently the original source is China. Etymonline fail!
- auvi 7y agoI thought Chai originally comes from the Chinese word 茶 (Chá).
- lxe 7y agoCorrect -- the etymology of all "chai"s and "tea"s can be traced to Chinese: https://en.wikipedia.org/wiki/Etymology_of_tea https://en.wikipedia.org/wiki/Etymology_of_tea
- vezycash 7y agoWith few exceptions, the word for Tea in a country depends on how it was originally transported there. See: Tea if by sea, cha if by land: Why the world only has two words for tea https://qz.com/1176962/map-how-the-word-tea-spread-over-land-and-sea-to-conquer-the-world/ https://qz.com/1176962/map-how-the-word-tea-spread-over-land...
- vishnugupta 7y agoWow. I had absolutely no idea! Thanks for sharing that link, learned something new today
- lxe 7y agoI like this and I see the use cases, however why would I use ChaiScript over Lua for example?
- rsp1984 7y agoTo me it looks like ChaiScript is more lightweight and easier to learn.
- Erlich_Bachman 7y agoArgueably a questionable advantage over for example lua specifically, where it is already quite easy, while at the same time having all the benefits of a mature production grade system: speed, stability, portability, talent pool, etc. Even Python could be a contester here...
- jokoon 7y agoIf it's closer to C++ in its syntax I think it's more interesting.
- tcallred 7y agoWould that make it a good candidate for microcontroller programming? I have been looking for something more elegant/functional to program arduino with. Anything about memory size on the site?
- tyingq 7y ago"ChaiScript is a header only library with only one dependency: The operating system provided dynamic library loader, which has to be specified on some platforms." I believe the dynamic library loader requirement is a showstopper for AVR.
- wruza 7y agoNot exactly arduino, but you may be interested with nodemcu: https://en.wikipedia.org/wiki/NodeMCU https://en.wikipedia.org/wiki/NodeMCU
- mhh__ 7y ago> ChaiScript has been making stable releases since 2009. No bugfix or feature is made without a corresponding unit test Codecov: 72% Reality is often disappointing... In all seriousness, looks pretty nice.
- bbmario 7y agoSince when code coverage is accurate enough for you to make that judgement?
- Erlich_Bachman 7y agoI 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.
- Kiro 7y agoI'm stupid but what's the purpose? Why not just call the function directly without Chai?
- furyofantares 7y agoCalling a C++ function from your scripting language, or a scripted function from C++ are different uses, they're just combined into one for the purposes of a demo of what the code looks like. edit: For example, there's a fairly clear distinction in a game between engine code and gameplay code. Engine code is run all the time, and should be memory and computationally efficient, and robust. It won't likely need to be changed much, and is OK to spend some extra effort writing it to get all these properties. So C++ is great for this. Gameplay code doesn't tend to have these requirements, and you may not want to pay the cost to write C++ if you don't need the benefits. And additionally, gameplay code often needs to be rewritten frequently while you experiment with gameplay to find what's fun, or do expansions, or support mods to the game, so a language that's very easy to write in helps a lot.
- jokoon 7y agoI just discovered that raw multi line string don't work on visual studio 2017...
- szappetx 7y agoI really like ChaiScript and have used it in a couple of small game projects. But I stopped using it because it was insanely slow (in both compile times and runtime performance). Several hundred (if not thousand) times slower than the equivalent Lua code. That was a few years ago, but skimming through the release notes, it doesn't seem to have been fixed.
- kevin_thibedeau 7y agoI bet the compile times would improve if it wasn't header only.
- szappetx 7y agoUnfortunately ChaiScript needs to be header-only because it's like 99% templates. You can put all your ChaiScript-related code into an isolated implementation file, and try to avoid touching that file as much as possible. But that only works well for long-term projects, where once you get all the bindings you need set up, you can coast for a while without touching those files. For short-term projects it's a nightmare because you're constantly touching the ChaiScript files. There's no inherent reason a header-only library should significantly impact compile times, aside from the fact that the authors usually don't have the foresight to make it efficient. It's also very difficult to find information about how to make templates more efficient at compile time.
- geezerjay 7y ago> I bet the compile times would improve if it wasn't header only. If any hypothetical compilation time problem concerns you then rest assure that C++ enables you to develop submodules that wrap and instantiate your templates, eliminating the need to recompile them every single build.
- adev_ 7y agoFor the note: ChaiScript is from Jason Turner. He also does CPPCast ( https://www.youtube.com/channel/UCuCjADS4u3uJDTqUaG0H9dA https://www.youtube.com/channel/UCuCjADS4u3uJDTqUaG0H9dA) and is a regular presenter at CPPCon ( https://www.youtube.com/watch?v=zBkNBP00wJE https://www.youtube.com/watch?v=zBkNBP00wJE ). Many of his videos / tutorials are worth a look if you are interested in C++.
- s_y_n_t_a_x 7y agoLuaJIT w/ FFI seems better imo.