forked from scarsty/kys-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript.cpp
More file actions
36 lines (28 loc) · 698 Bytes
/
Copy pathScript.cpp
File metadata and controls
36 lines (28 loc) · 698 Bytes
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
#include "Script.h"
#include "others/libconvert.h"
Script Script::script_;
Script::Script()
{
lua_state_ = luaL_newstate();
luaL_openlibs(lua_state_);
luaopen_base(lua_state_);
luaopen_table(lua_state_);
luaopen_math(lua_state_);
luaopen_string(lua_state_);
registerEventFunctions();
}
Script::~Script()
{
lua_close(lua_state_);
}
int Script::runScript(std::string filename)
{
std::string content = convert::readStringFromFile(filename);
luaL_loadbuffer(lua_state_, content.c_str(), content.size(), "code");
return lua_pcall(lua_state_, 0, 0, 0);
}
int Script::registerEventFunctions()
{
SCRIPT_VOID(additem, addItem, FUNC2);
return 0;
}