diff --git a/autogen/src/data/codegen.cpp b/autogen/src/data/codegen.cpp index 250a23a..46dfa78 100644 --- a/autogen/src/data/codegen.cpp +++ b/autogen/src/data/codegen.cpp @@ -345,8 +345,10 @@ static void writeLuaLibraryGenerator(std::ofstream& out, ClassAnalysis& state) { if (state.staticMethods.size() == 0 && state.staticProperties.size() == 0) return; out << "static int lib_" << state.name << "_index(lua_State*);\n" + "static int lib_" << state.name << "_tostring(lua_State*);\n" "static const struct luaL_Reg lib_" << state.name << "_metatable [] = {\n" " {\"__index\", lib_" << state.name << "_index},\n" + " {\"__tostring\", lib_" << state.name << "_tostring},\n" " {NULL, NULL} /* end of array */\n" "};\n\n"; @@ -364,6 +366,13 @@ static void writeLuaLibraryGenerator(std::ofstream& out, ClassAnalysis& state) { " lua_rawset(L, -3);\n" " lua_pop(L, 1);\n" "}\n\n"; + + // tostring + + out << "\nint lib_" << state.name << "_tostring(lua_State* L) {\n" + " lua_pushstring(L, \"" << state.name << "\");\n" + " return 1;\n" + "}\n\n"; // Indexing methods and properties diff --git a/core/src/datatypes/ref.cpp b/core/src/datatypes/ref.cpp index f6b1aeb..72513ec 100644 --- a/core/src/datatypes/ref.cpp +++ b/core/src/datatypes/ref.cpp @@ -3,6 +3,7 @@ #include "error/data.h" #include "logger.h" #include "variant.h" // IWYU pragma: keep +#include #include #include #include "objects/base/instance.h" @@ -49,10 +50,12 @@ result InstanceRef::Deserialize(pugi::xml_node node static int inst_gc(lua_State*); static int inst_index(lua_State*); static int inst_newindex(lua_State*); +static int inst_tostring(lua_State*); static const struct luaL_Reg metatable [] = { {"__gc", inst_gc}, {"__index", inst_index}, {"__newindex", inst_newindex}, + {"__tostring", inst_tostring}, {NULL, NULL} /* end of array */ }; @@ -141,4 +144,13 @@ static int inst_newindex(lua_State* L) { return luaL_error(L, "%s", value.errorMessage().value().c_str()); inst->SetPropertyValue(key, value.expect()).expect(); return 0; +} + +static int inst_tostring(lua_State* L) { + auto userdata = (std::shared_ptr**)lua_touserdata(L, 1); + std::shared_ptr inst = **userdata; + + lua_pushstring(L, inst->name.c_str()); + + return 1; } \ No newline at end of file diff --git a/core/src/objects/script.cpp b/core/src/objects/script.cpp index ec24bb3..9167fd5 100644 --- a/core/src/objects/script.cpp +++ b/core/src/objects/script.cpp @@ -15,15 +15,7 @@ int script_wait(lua_State*); int script_delay(lua_State*); Script::Script(): Instance(&TYPE) { - source = "workspace.Part.Touched:Connect(function(otherPart)\n" - " print(\"Touched by: \", otherPart.Name)\n" - "end)\n" - "\n" - "workspace.Part.TouchEnded:Connect(function(otherPart)\n" - " print(\"Touched ended with: \", otherPart.Name)\n" - "end)\n" - "\n" - "error(\"Test\")"; + source = "print(\"Hello, world!\")"; } Script::~Script() { diff --git a/editor/placedocument.cpp b/editor/placedocument.cpp index 512dc2f..4dbe88a 100644 --- a/editor/placedocument.cpp +++ b/editor/placedocument.cpp @@ -93,51 +93,15 @@ void PlaceDocument::init() { gWorkspace()->SyncPartPhysics(lastPart); gWorkspace()->AddChild(lastPart = Part::New({ - .position = glm::vec3(0), - .rotation = glm::vec3(-2.6415927, 1.1415926, 2.57075), + .position = glm::vec3(-3.8), + .rotation = glm::vec3(0), .size = glm::vec3(4, 1.2, 2), .color = glm::vec3(0.639216f, 0.635294f, 0.647059f), })); gWorkspace()->SyncPartPhysics(lastPart); auto part0 = lastPart; - gWorkspace()->AddChild(lastPart = Part::New({ - .position = glm::vec3(1.7610925, 0.48568499, -0.82623518), - // .rotation = glm::vec3(0.5, 2, 1), - .rotation = glm::vec3(-2.6415927, 1.1415926, -2.141639), - .size = glm::vec3(4, 1.2, 2), - .color = glm::vec3(0.639216f, 0.635294f, 0.647059f), - })); - gWorkspace()->SyncPartPhysics(lastPart); - auto part1 = lastPart; - lastPart = Part::New(); - shit = part1; - - part0->anchored = true; - part0->UpdateProperty("Anchored"); - - // auto snap = Snap::New(); - // snap->part0 = part0; - // snap->part1 = part1; - // snap->c0 = part1->cframe; - // snap->c1 = part0->cframe; - - // gWorkspace()->AddChild(snap); - // snap->UpdateProperty("Part0"); - // snap->UpdateProperty("Part1"); - - // part0->backSurface = SurfaceWeld; - // part1->frontSurface = SurfaceWeld; - - // part0->backSurface = SurfaceHinge; - part0->backSurface = SurfaceType::Motor; - // part1->frontSurface = SurfaceHinge; - - std::shared_ptr