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-06 15:02:16 +00:00
|
|
|
#include "Flow/FlowHandler.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-06 17:12:12 +00:00
|
|
|
#include "Inventory/InventoryHandler.h"
|
2022-02-05 23:50:35 +00:00
|
|
|
#include "ReservedScriptNames.h"
|
2022-02-07 20:42:40 +00:00
|
|
|
#include "Misc/Misc.h"
|
2022-01-25 23:50:12 +00:00
|
|
|
|
2022-02-06 17:12:12 +00:00
|
|
|
static sol::state s_solState;
|
2022-02-05 23:50:35 +00:00
|
|
|
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()
|
|
|
|
{
|
2022-02-06 17:12:12 +00:00
|
|
|
return new LogicHandler(&s_solState, s_rootTable);
|
2022-01-25 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
2022-02-06 15:02:16 +00:00
|
|
|
ScriptInterfaceFlowHandler* ScriptInterfaceState::CreateFlow()
|
2022-01-25 23:50:12 +00:00
|
|
|
{
|
2022-02-06 17:12:12 +00:00
|
|
|
return new FlowHandler(&s_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-06 17:12:12 +00:00
|
|
|
return new ObjectsHandler(&s_solState, s_rootTable);
|
2022-02-02 19:49:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 19:02:11 +00:00
|
|
|
ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
|
|
|
|
{
|
2022-02-06 17:12:12 +00:00
|
|
|
return new StringsHandler(&s_solState, s_rootTable);
|
2022-02-04 19:02:11 +00:00
|
|
|
}
|
|
|
|
|
2022-01-25 23:50:12 +00:00
|
|
|
void ScriptInterfaceState::Init()
|
|
|
|
{
|
2022-04-10 19:44:44 +01:00
|
|
|
s_solState.open_libraries(sol::lib::base, sol::lib::math, sol::lib::package, sol::lib::coroutine);
|
2022-03-13 19:38:25 +00:00
|
|
|
s_solState.script("package.path=\"Scripts/?.lua\"");
|
2022-02-06 17:12:12 +00:00
|
|
|
s_solState.set_exception_handler(lua_exception_handler);
|
2022-02-05 23:50:35 +00:00
|
|
|
|
2022-02-06 17:12:12 +00:00
|
|
|
s_rootTable = sol::table{ s_solState.lua_state(), sol::create };
|
|
|
|
s_solState.set(ScriptReserved_TEN, s_rootTable);
|
|
|
|
|
|
|
|
// Misc handlers not assigned above
|
|
|
|
InventoryHandler::Register(&s_solState, s_rootTable);
|
2022-02-07 20:42:40 +00:00
|
|
|
Misc::Register(&s_solState, s_rootTable);
|
2022-01-25 23:50:12 +00:00
|
|
|
}
|
2022-02-02 19:49:57 +00:00
|
|
|
|