galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Script.cpp
Go to the documentation of this file.
1
7
8#include <entt/locator/locator.hpp>
9
13
14#include "Script.hpp"
15
16namespace galaxy
17{
18 Script::Script() noexcept
19 {
20 }
21
22 Script::Script(const std::string& file)
23 {
24 GALAXY_UNUSED(load(file));
25 }
26
27 Script::~Script() noexcept
28 {
29 }
30
31 bool Script::load(const std::string& file)
32 {
33 auto& fs = entt::locator<VirtualFileSystem>::value();
34
35 const auto script = fs.read(file);
36 if (!script.empty())
37 {
38 m_script = entt::locator<sol::state>::value().load(script);
39
40 if (!m_script.valid())
41 {
42 GALAXY_LOG(GALAXY_ERROR, "Failed to load script '{0}' because '{1}'.", file, magic_enum::enum_name(m_script.status()));
43 }
44 }
45 else
46 {
47 GALAXY_LOG(GALAXY_ERROR, "Failed to read script '{0}'.", file);
48 }
49
50 return m_script.valid();
51 }
52
53 sol::protected_function_result Script::run()
54 {
55 if (m_script.valid())
56 {
57 return m_script();
58 }
59
60 return {};
61 }
62} // namespace galaxy
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:28
#define GALAXY_ERROR
Definition Log.hpp:24
#define GALAXY_UNUSED(var)
Pragma.hpp galaxy.
Definition Pragma.hpp:16
~Script() noexcept
Destructor.
Definition Script.cpp:27
Script() noexcept
Constructor.
Definition Script.cpp:18
sol::protected_function_result run()
Run a lua script and get a return value.
Definition Script.cpp:53
bool load(const std::string &file)
Load a script.
Definition Script.cpp:31
sol::load_result m_script
Script loaded into sol3 memory.
Definition Script.hpp:58
Animated.cpp galaxy.
Definition Animated.cpp:16