File Helpers.hpp¶
File List > Engine > include > Scripting > LuaAPI > Internal > Helpers.hpp
Go to the documentation of this file
#ifndef ENGINE_SCRIPTING_LUAAPI_INTERNAL_HELPERS_HPP_
#define ENGINE_SCRIPTING_LUAAPI_INTERNAL_HELPERS_HPP_
#include "Components/Position.hpp"
#include "Components/Rotation.hpp"
#include "ECS/Entity.hpp"
#include "ECS/Registry.hpp"
#include <sol/sol.hpp>
namespace Engine::LuaAPI::Internal {
inline sol::table ensureNamespace(sol::state_view lua, const char* name) {
sol::object existing = lua[name];
if (existing.is<sol::table>()) {
return existing.as<sol::table>();
}
sol::table t = lua.create_table();
lua[name] = t;
return t;
}
inline void ensureTransform(Registry& registry, Entity entity, bool withRotation) {
if (!registry.HasComponent<Position>(entity)) {
registry.AddComponent<Position>(entity, Position{0.0f, 0.0f});
}
if (withRotation && !registry.HasComponent<Rotation>(entity)) {
registry.AddComponent<Rotation>(entity, Rotation{0.0f});
}
}
} // namespace Engine::LuaAPI::Internal
#endif // ENGINE_SCRIPTING_LUAAPI_INTERNAL_HELPERS_HPP_