sol2 (sol2, version 4.0)¶
a fast, simple C++ and Lua Binding
When you need to hit the ground running with Lua and C++, sol is the go-to framework for high-performance binding with an easy to use API.
solpp¶
solpp is a fork that attempts to deliver some improvements over upstream. As of December 2025, the last commit was nine months ago, yet there are bugs with active PRs containing fixes that aren’t merged.
additional features¶
Lua 5.5 support
Luau support
Added CI with more configurations (more compiler and Lua versions)
Enabled and fixed the
run_timetests.
Luau support¶
Luau is in some aspects significantly different from Lua 5.1 (see Differences from Lua). These are the differences and important points for sol users:
Vectors use
sol::luau::vector.Buffers use
sol::luau::(const_)buffer_view. To pass a buffer to Lua, usesol::copy_buffer.If the target
lua_Statewas not created by sol, you need to usesol::state_view::init_userdata_tags()on the state at the start.Currently, sol uses
LUA_UTAG_LIMIT - 1as the tag for its usertypes. This is mainly due to a limitation of Luau to change the destructor for the inline userdata.Luau doesn’t have a built-in
require()implementation, hence, sol’s APIs for this won’t work.Most policies won’t work, because
lua_setfenvcan’t be used on userdata.Dumping function bytecode is unsupported.
The
lua_ReaderAPIs are unsupported.Due to the absence of
__gc, the destructors can’t be customized withsol::meta_function::garbage_collect.Once a usertype is defined in a state (
new_usertype), it can’t be removed, because the destructors can’t modify the Luau state.
The following features are missing and would be nice to have:
Ability to specify the userdata tag for certain types. This could also the type to be marked as non-dynamic.
Userdata could use a table for
__indexif possible. Needs to be profiled, but Luau claims this is faster. An even faster method would be to use atoms.Userdata could support
lua_UserdataDirectFieldGet`. Though it’s tricky to detect when that’s possible.Provide a sane implementation of
require()out of the box.The bytecode produced from
script()and friends can’t be customized (e.g. optimization level).
get going:¶
- tutorial
- errors
- supported compilers, binary size, compile time
- features
- functions
- usertypes
- containers
- threading
- customization traits
- api reference manual
- mentions
- benchmarks
- getting performance
- config and safety
- exceptions
- run-time type information (rtti)
- unicode transformation format handling
- build
- licenses
- origin
connect¶
Come to the Github Issues! We’ve got a friendly community, and they can help you out or you can come just to talk about the things you are working on!
support¶
You can support the project and other related endeavors in various ways.
This is a time-consuming effort, so individuals who donate get to:
steer the direction and time spent on sol
get their name put up in the CONTRIBUTORS list
put something of their choice on sol2’s README or the documentation’s front page
“I need feature X, maybe you have it?”¶
Take a look at the Features page: it links to much of the API. You can also just straight up browse the api or ease in with the tutorials. To know more about the implementation for usertypes, see here To know how function arguments are handled, see this note. Don’t see a feature you want? Send inquiries for support for a particular abstraction to the issues tracker.
the basics:¶
Note
The code below and more examples can be found in the examples directory.
1#define SOL_ALL_SAFETIES_ON 1
2
3#include <sol/sol.hpp>
4
5int main() {
6 sol::state lua;
7 int x = 0;
8 lua.set_function("beep", [&x] { ++x; });
9 lua.script("beep()");
10 SOL_ASSERT(x == 1);
11
12 sol::function beep = lua["beep"];
13 beep();
14 SOL_ASSERT(x == 2);
15
16 return 0;
17}
1#define SOL_ALL_SAFETIES_ON 1
2
3#include <sol/sol.hpp>
4
5struct vars {
6 int boop = 0;
7
8 int bop() const {
9 return boop + 1;
10 }
11};
12
13int main() {
14 sol::state lua;
15 lua.new_usertype<vars>(
16 "vars", "boop", &vars::boop, "bop", &vars::bop);
17 lua.script(
18 "beep = vars.new()\n"
19 "beep.boop = 1\n"
20 "bopvalue = beep:bop()");
21
22 vars& beep = lua["beep"];
23 int bopvalue = lua["bopvalue"];
24
25 SOL_ASSERT(beep.boop == 1);
26 SOL_ASSERT(lua.get<vars>("beep").boop == 1);
27 SOL_ASSERT(beep.bop() == 2);
28 SOL_ASSERT(bopvalue == 2);
29
30 return 0;
31}





