2022-01-25 23:50:12 +00:00
|
|
|
#include "frameworkandsol.h"
|
|
|
|
#include "ScriptInterfaceState.h"
|
2022-02-06 11:00:13 +00:00
|
|
|
#include "Logic/LogicHandler.h"
|
2022-02-05 23:50:35 +00:00
|
|
|
#include "Flow/Flow.h"
|
2022-02-05 15:56:04 +00:00
|
|
|
#include "Objects/ObjectsHandler.h"
|
2022-02-04 19:02:11 +00:00
|
|
|
#include "Strings/StringsHandler.h"
|
2022-02-05 23:50:35 +00:00
|
|
|
#include "ReservedScriptNames.h"
|
2022-01-25 23:50:12 +00:00
|
|
|
|
2022-02-05 23:50:35 +00:00
|
|
|
static sol::state g_solState;
|
|
|
|
static sol::table s_rootTable;
|
2022-01-25 23:50:12 +00:00
|
|
|
|
|
|
|
int lua_exception_handler(lua_State* L, sol::optional<std::exception const &> maybe_exception, sol::string_view description)
|
|
|
|
{
|
|
|
|
return luaL_error(L, description.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptInterfaceGame* ScriptInterfaceState::CreateGame()
|
|
|
|
{
|
|
|
|
return new GameScript(&g_solState);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptInterfaceFlow* ScriptInterfaceState::CreateFlow()
|
|
|
|
{
|
2022-02-05 23:50:35 +00:00
|
|
|
return new Flow(&g_solState, s_rootTable);
|
2022-01-25 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 16:03:54 +00:00
|
|
|
ScriptInterfaceObjectsHandler* ScriptInterfaceState::CreateObjectsHandler()
|
2022-02-02 19:49:57 +00:00
|
|
|
{
|
2022-02-05 23:50:35 +00:00
|
|
|
return new ObjectsHandler(&g_solState, s_rootTable);
|
2022-02-02 19:49:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 19:02:11 +00:00
|
|
|
ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
|
|
|
|
{
|
|
|
|
return new StringsHandler(&g_solState);
|
|
|
|
}
|
|
|
|
|
2022-01-25 23:50:12 +00:00
|
|
|
void ScriptInterfaceState::Init()
|
|
|
|
{
|
|
|
|
g_solState.open_libraries(sol::lib::base, sol::lib::math);
|
|
|
|
g_solState.set_exception_handler(lua_exception_handler);
|
2022-02-05 23:50:35 +00:00
|
|
|
|
|
|
|
s_rootTable = sol::table{ g_solState.lua_state(), sol::create };
|
|
|
|
g_solState.set(ScriptReserved_TEN, s_rootTable);
|
2022-01-25 23:50:12 +00:00
|
|
|
}
|
2022-02-02 19:49:57 +00:00
|
|
|
|