File: main.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 (42 lines) | stat: -rw-r--r-- 1,046 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
31
32
33
34
35
36
37
38
39
40
41
42
#include <lua_interop.hpp>
#include <entity.hpp>

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

#include <iostream>

int main(int, char*[]) {
	std::cout << "=== customization: vec3 as table ==="
	          << std::endl;

	sol::state lua;
	lua.open_libraries(sol::lib::base);

	std::cout << "registering entities into Lua ..."
	          << std::endl;
	register_lua(lua);
	std::cout << "running script ..." << std::endl;

	const auto& script = R"lua(
local e = entity.new()
local pos = e.position
print("pos type", type(pos))
print("pos", pos.x, pos.y, pos.z)
e.position = { x = 52, y = 5.5, z = 47.5 }
local new_pos = e.position
print("pos", pos.x, pos.y, pos.z)
print("new_pos", new_pos.x, new_pos.y, new_pos.z)
)lua";

	sol::optional<sol::error> result = lua.safe_script(script);
	if (result.has_value()) {
		std::cerr << "Something went horribly wrong: "
		          << result.value().what() << std::endl;
	}

	std::cout << "finishing ..." << std::endl;

	std::cout << std::endl;
	return 0;
}