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
12#include "galaxy/utils/UUID.hpp"
13
14#include "../Lua.hpp"
15
16namespace galaxy
17{
18 void Lua::inject_utils() noexcept
19 {
20 auto& lua = entt::locator<sol::state>::value();
21
22 lua.set_function("str_split", &str::split);
23 lua.set_function("str_replace_first", &str::replace_first);
24 lua.set_function("str_replace_all", &str::replace_all);
25 lua.set_function("str_begins_with", &str::begins_with);
26 lua.set_function("str_rtrim", &str::rtrim);
27 lua.set_function("str_ltrim", &str::ltrim);
28 lua.set_function("str_trim", &str::trim);
29 lua.set_function("str_make_single_spaced", &str::make_single_spaced);
30
31 auto uuid_type = lua.new_usertype<UUID>("UUID", sol::constructors<UUID()>());
32 uuid_type["hash"] = &UUID::hash;
33 uuid_type["str"] = &UUID::str;
34 }
35} // namespace galaxy
static void inject_utils() noexcept
Injects misc galaxy utils into Lua.
Definition LuaUtils.cpp:18
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
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.
Animated.cpp galaxy.
Definition Animated.cpp:16