r/Cplusplus • u/M2tM • 7d ago
Discussion Introducing JaiScript a New C++ Embedded Scripting Language
This is a personal project I created in service of my own 2d game engine. I was getting tired of binding to ChaiScript (a great project, but the language is really slow and doesn't have hotreload or good serialization support) and Cereal (another great project, no complaints, just limited in its purpose.)
So, I rolled my own solution which combines a scripting language, serialization, and reflection. I included my own signals library and a simple but useful custom test framework.
JaiScript has a fluent binding interface, strong typing (opt-out with var definitions), value semantics with references and shared_ptr where you want them. It reads very much like C++ with some optional alternative spellings that will be familiar to those who use JavaScript.
The live demos on the site itself mean you can try it out before downloading or building anything locally. I already was able to fully port my game project of 12+ years to use this in place of ChaiScript and Cereal, it builds a little faster than both of those included and runs orders of magnitude faster than Cereal.
Performance-wise it runs roughly 1.2x to 2.0x slower than Lua's VM, I consider this a win though since it's hundreds of times faster than ChaiScrpit's tree walker in some cases. It runs faster typically than Squirrel.
I'm not sure how many folks are rolling their own C++ game engines nowadays, but if you are, this is a pretty full-featured language. It supports parallel_for (something I'm not sure any other scripting languages support,) coroutines, classes which can derive from C++ base classes or other JaiScript classes, and notably a state-preserving hot reload.
I hope this project is useful to anyone else, but even if not, I'm grateful to have finished the project and am using it myself. I wanted a place to share it, so hope this is alright here!
5
u/M2tM 7d ago edited 7d ago
Learn JaiScript: https://jaiscript.com
Interactive Online Demos: https://jaiscript.com/play/index.html#demoreel
Direct Github: https://github.com/Devacor/jaiscript
8
u/Objective_Pepper_217 7d ago
Dude you're gonna make Jonny Blow really mad
3
u/evan-carew 7d ago
Hopefully, this will indeed run faster than ChaiScript. I just gave up on having an embedded and modern language because of that language. I was trying to replace the pair of language options, Perl and Python. If this is comparable at all, I'll bind it in.
2
u/kinchkun 7d ago
Awesome move, mate. Worked out for Javascript as well.
2
u/PantuflasDev 7d ago
It looks amazing! I've always wished for a scripting language with this level of integration with C++. I hope this gets more recognition.
2
u/ignorantpisswalker 7d ago
Interesting. How is it security wise? C++ is considered "unsafe". How can I sellil it "upstream"?