aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sol2/examples/source/docs/inheritance.cpp
blob: b1c87f066b4792d4b4d6610e6058477bf3bc220d (plain)
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
#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>

struct A { 
	int a = 10;
	virtual int call() { return 0; }
	virtual ~A(){}
};
struct B : A { 
	int b = 11; 
	virtual int call() override { return 20; } 
};

int main (int, char*[]) {

	sol::state lua;

	lua.new_usertype<B>( "A",
		"call", &A::call
	);

	lua.new_usertype<B>( "B",
		"call", &B::call,
		sol::base_classes, sol::bases<A>()
	);

	return 0;
}