An Introduction to Low-Latency Scripting With libriscv

submited by
Style Pass
2024-05-23 03:00:03

libriscv is a mature RISC-V emulator that is currently being used in game engines. As far as I know, it is the only emulator that focuses solely on latency, and provides specialized solutions and tools to accomplish fast in-and-out function calls wrapped around a safe sandbox.

Many people have asked how to use it, or how can you even think about using C++ for scripting — shouldn’t it be very hard? The answer is not really. I’ve been scripting for one big and one small game for several years now, and I’ve rarely felt it was C++ or the scripting APIs that were the reason for any troubles. I’ve been using Lua for years, and before that I used plain C. I never felt Lua helped a lot. LuaBridge creates good abstractions, but Lua still creates issues now and then. Like if you forget return, the return value is that of the last expression. Yep, that’s how it works. With C as a scripting language, you can only imagine. It was cool, but it was horrible at the same time. I learned a lot, though, and I feel the same way about Lua. Modern, idiomatic C++ hits the right spot for me. And I can use the same language both in- and outside of the game engine, with many of the same abstractions (literally). Obviously, people like different things and there are tradeoffs. So, to end the introduction here is a fun fact: C++ has a competition for the longest error message.

This will pull in the latest fmtlib and libriscv, and link them into our project executable. CMake also takes care of include directories and such. This guide follows the gamedev example from the libriscv repository.

Leave a Comment