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
LuaUtils.cpp
Go to the documentation of this file.
1
7
8#include <entt/locator/locator.hpp>
9#include <sol/sol.hpp>
10
13#include "galaxy/utils/UUID.hpp"
14
15#include "../Lua.hpp"
16
17namespace galaxy
18{
19 void Lua::inject_utils() noexcept
20 {
21 auto& lua = entt::locator<sol::state>::value();
22
23 lua.set_function("is_work_done", &async::is_work_done<void>);
24 lua.set_function("str_split", &str::split);
25 lua.set_function("str_replace_first", &str::replace_first);
26 lua.set_function("str_replace_all", &str::replace_all);
27 lua.set_function("str_begins_with", &str::begins_with);
28 lua.set_function("str_rtrim", &str::rtrim);
29 lua.set_function("str_ltrim", &str::ltrim);
30 lua.set_function("str_trim", &str::trim);
31 lua.set_function("str_make_single_spaced", &str::make_single_spaced);
32
33 auto uuid_type = lua.new_usertype<UUID>("UUID", sol::constructors<UUID()>());
34 uuid_type["hash"] = &UUID::hash;
35 uuid_type["str"] = &UUID::str;
36 }
37} // namespace galaxy
static void inject_utils() noexcept
Injects misc galaxy utils into Lua.
Definition LuaUtils.cpp:19
Contains a 128bit randomly generated UUID, along with helper functions.
Definition UUID.hpp:21
const std::string & str() const noexcept
Get the UUID as a string.
Definition UUID.cpp:93
std::size_t hash() noexcept
Get the UUID as a hash.
Definition UUID.cpp:83
bool is_work_done(const std::future< T > &task) noexcept
Check if an async thread has finished or not.
Definition Async.hpp:31
std::string rtrim(std::string input) noexcept
Trim string from start.
std::string replace_all(std::string input, std::string_view to_replace, std::string_view replace_with) noexcept
Replaces all occurrences of a string.
std::vector< std::string > split(std::string_view input, std::string_view delim) noexcept
Split a string based on a delimiter.
std::string ltrim(std::string input) noexcept
Trim string from end.
bool begins_with(const std::string &input, const std::string &find) noexcept
Check if string begins with another string.
std::string trim(std::string input) noexcept
Trim both ends of string.
std::string make_single_spaced(std::string input) noexcept
Make a string single spaced.
std::string replace_first(std::string input, std::string_view to_replace, std::string_view replace_with) noexcept
Replace first occurrence of a string.
Application.hpp galaxy.