sol repository

sol 3.2

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.

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!

sol3 Github Issues Page

support

You can support the project and other related endeavors in various ways.

sol3 Sponsors Page sol3 Patreon sol3 ko-fi sol3 ko-fi sol3 PayPal

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 sol3’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
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#define SOL_ALL_SAFETIES_ON 1

#include <sol/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_ALL_SAFETIES_ON 1

#include <sol/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;
}