C++20 + Lua = Flexibility

By James Pascoe

This talk describes an approach for combining C++20 with Lua. A key benefit of this combination is its flexibility i.e. performance critical features can be implemented in C++, whereas, behavioural aspects can be expressed in Lua. As Lua is interpreted, the program’s behaviour can be changed on-the-fly or in the field without a compilation environment. Thus, hypotheses can be tested, workarounds can be explored and previously unknown requirements can be accommodated without requiring a full release cycle.

This session presents the technical details for how to implement such an architecture. The aim of the session is to provide the audience with enough knowledge to be able to implement these ideas in their own projects. In particular, the session will show how to use SWIG to generate bindings and type mappings between C++20 and Lua, how to combine Lua coroutines (which are stateful) with stateless C++20 coroutines and how to integrate SWIG, Lua and C++20 into a CMake build flow. SWIG type mappings (with code available on GitHub) are provided for: std::span, std::any, std::optional and std::variant.

This presentation is a significantly updated and expanded follow-on to a talk given at CppOnSea 2020. Audience members do not need to have seen the CppOnSea talk i.e. the session is completely standalone. However, those that have seen the CppOnSea presentation will benefit from the new content, in particular, the update to C++20, the new SWIG type mappings and a more comprehensive treatment of the interplay between C++ and Lua coroutines.

A further benefit is that these ideas have been tested in a large commercial deployment. As a running exemplar, the talk will describe how Blu Wireless (the author’s employer) has migrated a mission-critical application from a monolithic C++98 code-base to the C++20/Lua architecture described here. In addition to the talk, the author will provide a C++20/Lua application called 'LuaChat' (available on GitHub) to consolidate the concepts and to provide a basis for audience experimentation.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.