sol 2.20¶
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.
get going:¶
- tutorial: quick ‘n’ dirty
- 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
“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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "../assert.hpp"
int main() {
sol::state lua;
int x = 0;
lua.set_function("beep", [&x]{ ++x; });
lua.script("beep()");
c_assert(x == 1);
sol::function beep = lua["beep"];
beep();
c_assert(x == 2);
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "../assert.hpp"
struct vars {
int boop = 0;
int bop () const {
return boop + 1;
}
};
int main() {
sol::state lua;
lua.new_usertype<vars>("vars",
"boop", &vars::boop,
"bop", &vars::bop);
lua.script("beep = vars.new()\n"
"beep.boop = 1\n"
"bopvalue = beep:bop()");
vars& beep = lua["beep"];
int bopvalue = lua["bopvalue"];
c_assert(beep.boop == 1);
c_assert(lua.get<vars>("beep").boop == 1);
c_assert(beep.bop() == 2);
c_assert(bopvalue == 2);
return 0;
}
|
helping out¶
You can support sol2 development by donating here. This is a time-consuming effort, so individuals who donate get to:
- steer the direction and time spent on sol
- get a role on the Discord server
- get their name put up in the CONTRIBUTORS list
- put something of their choice on sol2’s README or the documentation’s front page
You can also help out the library by submitting pull requests to fix anything or add anything you think would be helpful! This includes making small, useful examples of something you haven’t seen, or fixing typos and bad code in the documentation.
Finally, come join in Discord!