forked from elonafoobar/elonafoobar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat.cpp
45 lines (32 loc) · 822 Bytes
/
cat.cpp
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
43
44
45
#include "cat.hpp"
#include <iostream>
#include <string>
using namespace std::string_literals;
namespace elona
{
namespace cat
{
engine global;
void engine::initialize()
{
L.reset(luaL_newstate());
luaL_openlibs(ptr());
load(filesystem::path(u8"__init__.lua"));
}
void engine::load(const fs::path& filepath)
{
std::string filepath_str = filesystem::to_narrow_path(filepath);
if (luaL_dofile(ptr(), filepath_str.c_str()) != 0)
{
const char* error_msg = lua_tostring(ptr(), -1);
throw std::runtime_error(
u8"Error when loading Lua script:\n"s + std::string(error_msg));
}
}
void engine::register_function(const char* name, lua_CFunction func)
{
lua_pushcfunction(ptr(), func);
lua_setglobal(ptr(), name);
}
} // namespace cat
} // namespace elona