2022-05-08 06:52:04 +02:00
|
|
|
#include "framework.h"
|
2023-05-08 14:24:16 +10:00
|
|
|
#include "Scripting/Include/ScriptInterfaceState.h"
|
|
|
|
|
|
|
|
#include "Scripting/Internal/ReservedScriptNames.h"
|
2025-03-05 03:13:48 -05:00
|
|
|
#include "Scripting/Internal/TEN/Collision/Probe.h"
|
2023-05-08 14:24:16 +10:00
|
|
|
#include "Scripting/Internal/TEN/Effects/EffectsFunctions.h"
|
2023-06-25 16:59:59 +10:00
|
|
|
#include "Scripting/Internal/TEN/Flow/FlowHandler.h"
|
2023-10-20 11:53:59 +03:00
|
|
|
#include "Scripting/Internal/TEN/Input/InputHandler.h"
|
2023-05-08 14:24:16 +10:00
|
|
|
#include "Scripting/Internal/TEN/Inventory/InventoryHandler.h"
|
|
|
|
#include "Scripting/Internal/TEN/Logic/LogicHandler.h"
|
|
|
|
#include "Scripting/Internal/TEN/Objects/ObjectsHandler.h"
|
|
|
|
#include "Scripting/Internal/TEN/Strings/StringsHandler.h"
|
2023-10-20 11:53:59 +03:00
|
|
|
#include "Scripting/Internal/TEN/Sound/SoundHandler.h"
|
|
|
|
#include "Scripting/Internal/TEN/Util/Util.h"
|
|
|
|
#include "Scripting/Internal/TEN/View/ViewHandler.h"
|
2022-01-25 23:50:12 +00:00
|
|
|
|
2023-10-06 14:16:54 +11:00
|
|
|
static sol::state SolState;
|
|
|
|
static sol::table RootTable;
|
2022-01-25 23:50:12 +00:00
|
|
|
|
2023-05-08 14:24:16 +10:00
|
|
|
int lua_exception_handler(lua_State* luaStatePtr, sol::optional<const std::exception&> exception, sol::string_view description)
|
2022-01-25 23:50:12 +00:00
|
|
|
{
|
2023-05-08 14:24:16 +10:00
|
|
|
return luaL_error(luaStatePtr, description.data());
|
2022-01-25 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptInterfaceGame* ScriptInterfaceState::CreateGame()
|
|
|
|
{
|
2023-10-06 14:16:54 +11:00
|
|
|
return new LogicHandler(&SolState, 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
|
|
|
{
|
2023-10-06 14:16:54 +11:00
|
|
|
return new FlowHandler(&SolState, 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
|
|
|
{
|
2023-10-06 14:16:54 +11:00
|
|
|
return new ObjectsHandler(&SolState, RootTable);
|
2022-02-02 19:49:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 19:02:11 +00:00
|
|
|
ScriptInterfaceStringsHandler* ScriptInterfaceState::CreateStringsHandler()
|
|
|
|
{
|
2023-10-06 14:16:54 +11:00
|
|
|
return new StringsHandler(&SolState, RootTable);
|
2022-02-04 19:02:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 15:19:23 +10:00
|
|
|
void ScriptInterfaceState::Init(const std::string& assetsDir)
|
2022-01-25 23:50:12 +00:00
|
|
|
{
|
2023-10-06 14:16:54 +11:00
|
|
|
SolState.open_libraries(
|
2023-10-06 13:39:29 +11:00
|
|
|
sol::lib::base, sol::lib::math, sol::lib::package, sol::lib::coroutine,
|
|
|
|
sol::lib::table, sol::lib::string, sol::lib::debug);
|
2023-05-08 00:12:09 +01:00
|
|
|
|
2023-10-06 14:16:54 +11:00
|
|
|
SolState.script("package.path=\"" + assetsDir + "Scripts/?.lua\"");
|
|
|
|
SolState.set_exception_handler(lua_exception_handler);
|
2022-02-05 23:50:35 +00:00
|
|
|
|
2023-10-06 14:16:54 +11:00
|
|
|
RootTable = sol::table(SolState.lua_state(), sol::create);
|
|
|
|
SolState.set(ScriptReserved_TEN, RootTable);
|
2022-02-06 17:12:12 +00:00
|
|
|
|
2023-04-01 16:27:28 +11:00
|
|
|
// Misc. handlers not assigned above.
|
2023-11-11 00:24:55 +11:00
|
|
|
TEN::Scripting::InventoryHandler::Register(&SolState, RootTable);
|
2025-03-05 03:13:48 -05:00
|
|
|
TEN::Scripting::Collision::Register(&SolState, RootTable);
|
2023-11-11 00:24:55 +11:00
|
|
|
TEN::Scripting::Effects::Register(&SolState, RootTable);
|
|
|
|
TEN::Scripting::Input::Register(&SolState, RootTable);
|
|
|
|
TEN::Scripting::Sound::Register(&SolState, RootTable);
|
|
|
|
TEN::Scripting::Util::Register(&SolState, RootTable);
|
2023-11-10 19:23:36 +11:00
|
|
|
TEN::Scripting::View::Register(&SolState, RootTable);
|
2022-01-25 23:50:12 +00:00
|
|
|
}
|