-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptapi.cpp
More file actions
38 lines (27 loc) · 892 Bytes
/
scriptapi.cpp
File metadata and controls
38 lines (27 loc) · 892 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
36
37
38
#include "scriptapi.hpp"
#include <string>
#include <iostream>
using namespace std;
ScriptAPI::ScriptAPI() {
}
ScriptAPI::~ScriptAPI() {
}
string ScriptAPI::Execute(std::string epName) {
string luaResponse;
internalLuaState = luaL_newstate();
luaL_openlibs(internalLuaState);
if(luaL_loadfile(internalLuaState, string("." + epName + ".lua").c_str())) {
cerr << "Could not load " << epName << endl;
}
if(lua_pcall(internalLuaState,0,0,0)) {
cerr << "Could not prime LUA script" << endl;
}
lua_getglobal(internalLuaState, "runapi");
if(lua_pcall(internalLuaState,0,1,0)) {
cerr << "Could not find runapi method in LUA" << endl;
}
luaResponse = string(lua_tostring(internalLuaState, -1));
cout << "Value returned from LUA: " << luaResponse << endl;
lua_close(internalLuaState);
return luaResponse;
}