Browse Source

Rename Lua to LuaScriptg

master
Riyyi 4 years ago
parent
commit
4365160e95
  1. 4
      inferno/src/inferno/scene/components.h
  2. 18
      inferno/src/inferno/script/luascript.cpp
  3. 8
      inferno/src/inferno/script/luascript.h
  4. 4
      inferno/src/inferno/systems/script.cpp

4
inferno/src/inferno/scene/components.h

@ -15,7 +15,7 @@
namespace Inferno {
class Lua;
class LuaScript;
struct TagComponent {
std::string tag;
@ -83,7 +83,7 @@ namespace Inferno {
};
struct LuaScriptComponent {
Lua* instance = nullptr;
LuaScript* instance = nullptr;
std::string path;
// Dont allow manually setting instance during construction

18
inferno/src/inferno/script/lua.cpp → inferno/src/inferno/script/luascript.cpp

@ -4,12 +4,12 @@
#include "inferno/file.h"
#include "inferno/scene/components.h"
#include "inferno/scene/scene.h"
#include "inferno/script/lua.h"
#include "inferno/script/luascript.h"
#include "inferno/script/registration.h"
namespace Inferno {
void Lua::initialize()
void LuaScript::initialize()
{
// Type registration
// ---------------------------------
@ -32,7 +32,7 @@ namespace Inferno {
return &m_scene->getComponent<TransformComponent>(m_entity);
});
// (*m_state).set_function("GetComponent", &Lua::getComponentSol);
// (*m_state).set_function("GetComponent", &LuaScript::getComponentSol);
m_state.set_function("getCameraComponent", [this]() -> CameraComponent* {
return &m_scene->getComponent<CameraComponent>(m_entity);
});
@ -49,29 +49,29 @@ namespace Inferno {
callFunction("LuaScript", "initialize");
}
void Lua::destroy()
void LuaScript::destroy()
{
callFunction("LuaScript", "destroy");
}
void Lua::update(float deltaTime)
void LuaScript::update(float deltaTime)
{
m_state["LuaScript"]["transform"] = &m_scene->getComponent<TransformComponent>(m_entity);
callFunction("LuaScript", "update", deltaTime);
}
void Lua::loadScript()
void LuaScript::loadScript()
{
std::string script = File::read(m_path);
auto result = m_state.script(script.c_str(),
[](lua_State*, sol::protected_function_result pfr) { return pfr; });
ASSERT(result.valid(), "Lua script {}", ((sol::error)result).what());
ASSERT(result.valid(), "LuaScript {}", ((sol::error)result).what());
}
sol::table Lua::getTable(const char* name)
sol::table LuaScript::getTable(const char* name)
{
sol::table table = m_state[name];
ASSERT(table.valid(), "Lua table does not exist");
ASSERT(table.valid(), "LuaScript table does not exist");
return table;
}

8
inferno/src/inferno/script/lua.h → inferno/src/inferno/script/luascript.h

@ -1,5 +1,5 @@
#ifndef LUA_H
#define LUA_H
#ifndef LUA_SCRIPT_H
#define LUA_SCRIPT_H
#include <cstdint> // uint32_t
#include <string> // std::string
@ -18,7 +18,7 @@ namespace Inferno {
class Scene;
class Lua {
class LuaScript {
public:
void initialize();
void destroy();
@ -54,4 +54,4 @@ namespace Inferno {
}
#endif // LUA_H
#endif // LUA_SCRIPT_H

4
inferno/src/inferno/systems/script.cpp

@ -3,7 +3,7 @@
#include "inferno/assertions.h"
#include "inferno/scene/components.h"
#include "inferno/scene/scene.h"
#include "inferno/script/lua.h"
#include "inferno/script/luascript.h"
#include "inferno/script/nativescript.h"
#include "inferno/systems/script.h"
@ -63,7 +63,7 @@ namespace Inferno {
// Create Lua script if not initialized
if (!luaScript.instance) {
luaScript.instance = new Lua();
luaScript.instance = new LuaScript();
luaScript.instance->transform = &transform;
luaScript.instance->m_scene = m_scene;
luaScript.instance->m_entity = static_cast<uint32_t>(entity);

Loading…
Cancel
Save