Brunot
Loading...
Searching...
No Matches
ScriptingManager.h
Go to the documentation of this file.
1
11// ____ __ __ __
12// /\__ _\/\ \ /\ \/\ \
13// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
14// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
15// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
16// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
17// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
18
19
20#pragma once
21
22#include "Framework/Engine.h"
23#include "Framework/System.h"
24
25#define SOL_NO_CHECK_NUMBER_PRECISION 1
26#define SOL_ALL_SAFETIES_ON 1
27#include "sol/sol.hpp"
28
29#include "Framework/Script.h"
30
31namespace sys
32{
34{
35public:
36
37
38#pragma region static_functions
42 static auto getEnum() -> Type
43 {
45 }
46
53 static auto OpenScript(const std::string& path) -> sol::load_result
54 {
55 return Engine::getSystem<ScriptingManager>()->openScript(path);
56 }
57
62 static auto NULL_SCRIPT() -> Script&
63 {
64 return Engine::getSystem<ScriptingManager>()->null_script;
65 }
66
67#pragma endregion
68
70 ~ScriptingManager() override = default;
71 ScriptingManager(const ScriptingManager& other) = delete;
72 ScriptingManager(ScriptingManager&& other) noexcept = delete;
73 auto operator=(const ScriptingManager& other) -> ScriptingManager& = delete;
74 auto operator=(ScriptingManager&& other) noexcept -> ScriptingManager& = delete;
75
76
77#pragma region overridden_functions
78
80 auto clone() const -> std::unique_ptr<GameObject> override
81 {
82 return std::make_unique<ScriptingManager>();
83 }
84
85 auto onUpdate(float dt) -> void override;
86
87 auto endWindow() -> void override
88 {
89 }; // for debug ImGUI
90
91 auto onRender() -> void override;
92 auto load(const Stream& stream) -> void override;
93 auto save(Stream& stream) const -> void override;
94
95#pragma endregion
96
97#pragma region ScriptManager_Functions
98
104 auto openScript(const std::string& path) -> sol::load_result;
105
111 auto getFunction(const std::string& name) -> sol::protected_function;
112
118 auto getState() -> sol::state&
119 {
120 return lua;
121 }
122
123
124#pragma endregion
125
126private:
127#pragma region member_variables
128
130 sol::state lua;
131
132#pragma endregion
133
134#pragma region helper_functions
135
137 void bindPathType();
138
139#pragma endregion
140
141#pragma region static_variables
142
145
146#pragma endregion
147
148
149};
150
151
152}
sys::Json Stream
Definition AudioObject.h:20
The class that holds the top node, and manages the main game loop, as well as startup and shutdown.
loads a lua file, and constructs an object based on it, then lets it run in the engine like a compone...
static auto getSystem() -> system *
A function to get a system.
Definition Engine.h:50
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
Type
Definition System.h:20
@ ScriptingManager
Definition System.h:35
System(const std::string &typeName, Type systemType)
Definition System.cpp:75
ScriptingManager()
Definition ScriptingManager.cpp:33
auto operator=(ScriptingManager &&other) noexcept -> ScriptingManager &=delete
static auto OpenScript(const std::string &path) -> sol::load_result
opens a script and returns it's result. static way to call ScriptingManager::openScript()
Definition ScriptingManager.h:53
Script null_script
a script that doesn't exist, used for returning when finding scripts
Definition ScriptingManager.h:144
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition ScriptingManager.cpp:73
ScriptingManager(ScriptingManager &&other) noexcept=delete
static auto NULL_SCRIPT() -> Script &
gets the null script
Definition ScriptingManager.h:62
auto getState() -> sol::state &
get's a reference to the lua state (or stack) temporary while scripting is still not finalized
Definition ScriptingManager.h:118
sol::state lua
the lua stack. this IS lua, and everything that talks to lua at some point goes through this
Definition ScriptingManager.h:130
auto onUpdate(float dt) -> void override
called once every frame.
Definition ScriptingManager.cpp:64
auto getFunction(const std::string &name) -> sol::protected_function
get a function from the global table in lua
Definition ScriptingManager.cpp:120
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition ScriptingManager.h:87
static auto getEnum() -> Type
function required by all systems
Definition ScriptingManager.h:42
void bindPathType()
helper function to create lua bindings for paths, since it doesn't work well as a static member funct...
Definition ScriptingManager.cpp:83
~ScriptingManager() override=default
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition ScriptingManager.cpp:78
ScriptingManager(const ScriptingManager &other)=delete
auto openScript(const std::string &path) -> sol::load_result
opens a script and returns it's result.
Definition ScriptingManager.cpp:107
auto clone() const -> std::unique_ptr< GameObject > override
Clone is unimplemented b/c we aren't allowed to move lua state.
Definition ScriptingManager.h:80
auto onRender() -> void override
called every frame after update has been called for every object.
Definition ScriptingManager.cpp:69
auto operator=(const ScriptingManager &other) -> ScriptingManager &=delete
the type of elements in a basic_json container
Definition GameObject.h:37
Definition Script.h:32