Skip to content

Commit

Permalink
Added to string methods on both vector classes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomheeleynz committed Jul 19, 2023
1 parent a12b57e commit 8e368c4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
35 changes: 35 additions & 0 deletions Arcane/src/Arcane/Scripting/ScriptGlue.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "ScriptGlue.h"

#include "Arcane/Scripting/ScriptingEngine.h"
#include "Arcane/ECS/Component.h"
#include "Arcane/Core/InputManager.h"
#include "Script.h"


namespace Arcane
{
static void PrintStack(lua_State* L)
Expand Down Expand Up @@ -144,13 +146,26 @@ namespace Arcane
return 0;
};

auto Vec2ToString = [](lua_State* L) -> int {
glm::vec2* vec2 = (glm::vec2*)lua_touserdata(L, -3);

std::string returnString = "X: " + std::to_string(vec2->x) + ", Y: " + std::to_string(vec2->y);
lua_pushstring(L, returnString.c_str());
return 1;
};

lua_pushstring(L, "__index");
lua_pushcfunction(L, Vector2Index);
lua_settable(L, -3);

lua_pushstring(L, "__newindex");
lua_pushcfunction(L, Vector2NewIndex);
lua_settable(L, -3);


lua_pushstring(L, "__tostring");
lua_pushcfunction(L, Vec2ToString);
lua_settable(L, -3);
}

void ScriptGlue::CreateVec3Metatable(lua_State* L)
Expand Down Expand Up @@ -207,19 +222,39 @@ namespace Arcane
return 0;
};

auto Vec3ToString = [](lua_State* L) -> int {
glm::vec3* vec3 = (glm::vec3*)lua_touserdata(L, -3);

std::string returnString = "X: " + std::to_string(vec3->x) + ", Y: " + std::to_string(vec3->y) + ", Z: " + std::to_string(vec3->z);
lua_pushstring(L, returnString.c_str());
return 1;
};

lua_pushstring(L, "__index");
lua_pushcfunction(L, Vector3Index);
lua_settable(L, -3);

lua_pushstring(L, "__newindex");
lua_pushcfunction(L, Vector3NewIndex);
lua_settable(L, -3);

lua_pushstring(L, "__tostring");
lua_pushcfunction(L, Vec3ToString);
lua_settable(L, -3);
}

void ScriptGlue::CreateEntityIdMetatable(lua_State* L)
{
}

void ScriptGlue::CreateTransformComponentMetatable(lua_State* L)
{
}

void ScriptGlue::CreateTransformComponentTable(lua_State* L)
{
}

void ScriptGlue::CreateEntityIdTable(lua_State* L)
{
}
Expand Down
3 changes: 2 additions & 1 deletion Arcane/src/Arcane/Scripting/ScriptGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ namespace Arcane
static void CreateVec2Metatable(lua_State* L);
static void CreateVec3Metatable(lua_State* L);
static void CreateEntityIdMetatable(lua_State* L);

static void CreateTransformComponentMetatable(lua_State* L);
private:
static void CreateVec2Table(lua_State* L);
static void CreateVec3Table(lua_State* L);
static void CreateEntityIdTable(lua_State* L);
static void CreateTransformComponentTable(lua_State* L);
};
}
11 changes: 7 additions & 4 deletions Arcane/src/Arcane/Scripting/ScriptingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ namespace Arcane

int ScriptingEngine::GetComponent(lua_State* L)
{
PrintStack(L);
lua_getfield(L, -1, "EntityId");
PrintStack(L);
std::string componentType = lua_tostring(L, -1);
lua_getfield(L, -2, "EntityId");
Entity entity = *(Entity*)lua_touserdata(L, -1);
std::cout << (uint32_t)entity << std::endl;

if (componentType == "Transform") {

}

return 1;
}

Expand Down

0 comments on commit 8e368c4

Please sign in to comment.