2021-06-16 14:32:42 +01:00
|
|
|
#pragma once
|
|
|
|
#include "framework.h"
|
|
|
|
#include "LuaHandler.h"
|
|
|
|
|
|
|
|
LuaHandler::LuaHandler(sol::state* lua) {
|
|
|
|
m_lua = lua;
|
|
|
|
}
|
|
|
|
|
2021-08-03 15:12:24 +01:00
|
|
|
void LuaHandler::ExecuteScript(std::string const& luaFilename) {
|
|
|
|
auto result = m_lua->safe_script_file(luaFilename, sol::script_pass_on_error);
|
2021-06-16 14:32:42 +01:00
|
|
|
if (!result.valid())
|
|
|
|
{
|
|
|
|
sol::error error = result;
|
2021-08-03 15:12:24 +01:00
|
|
|
throw TENScriptException{ error.what() };
|
2021-06-16 14:32:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-03 15:12:24 +01:00
|
|
|
void LuaHandler::ExecuteString(std::string const & command) {
|
2021-06-16 14:32:42 +01:00
|
|
|
auto result = m_lua->safe_script(command, sol::environment(m_lua->lua_state(), sol::create, m_lua->globals()), sol::script_pass_on_error);
|
|
|
|
if (!result.valid())
|
|
|
|
{
|
|
|
|
sol::error error = result;
|
2021-08-03 15:12:24 +01:00
|
|
|
throw TENScriptException{ error.what() };
|
2021-06-16 14:32:42 +01:00
|
|
|
}
|
|
|
|
}
|