File: my_object.cpp

package info (click to toggle)
sol2 3.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,096 kB
  • sloc: cpp: 43,816; ansic: 1,018; python: 356; sh: 288; makefile: 202
file content (30 lines) | stat: -rw-r--r-- 780 bytes parent folder | download
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
#include <my_object/my_object.hpp>

#define SOL_ALL_SAFETIES_ON 1
#include <sol/sol.hpp>

namespace my_object {

	sol::table open_my_object(sol::this_state L) {
		sol::state_view lua(L);
		sol::table module = lua.create_table();
		module.new_usertype<test>("test",
		     sol::constructors<test(), test(int)>(),
		     "value",
		     &test::value);

		return module;
	}

} // namespace my_object

extern "C" int luaopen_my_object(lua_State* L) {
	// pass the lua_State,
	// the index to start grabbing arguments from,
	// and the function itself
	// optionally, you can pass extra arguments to the function
	// if that's necessary, but that's advanced usage and is
	// generally reserved for internals only
	return sol::stack::call_lua(
	     L, 1, my_object::open_my_object);
}