feat(lua): added missing tostrings and removed debug starter objects

This commit is contained in:
maelstrom 2025-06-05 15:29:25 +02:00
parent 5f726ad92b
commit f5931c746d
4 changed files with 24 additions and 47 deletions

View file

@ -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";
@ -365,6 +367,13 @@ static void writeLuaLibraryGenerator(std::ofstream& out, ClassAnalysis& state) {
" 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
out << "static int lib_" << state.name << "_index(lua_State* L) {\n"

View file

@ -3,6 +3,7 @@
#include "error/data.h"
#include "logger.h"
#include "variant.h" // IWYU pragma: keep
#include <luajit-2.1/lua.h>
#include <memory>
#include <optional>
#include "objects/base/instance.h"
@ -49,10 +50,12 @@ result<InstanceRef, DataParseError> 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 */
};
@ -142,3 +145,12 @@ static int inst_newindex(lua_State* L) {
inst->SetPropertyValue(key, value.expect()).expect();
return 0;
}
static int inst_tostring(lua_State* L) {
auto userdata = (std::shared_ptr<Instance>**)lua_touserdata(L, 1);
std::shared_ptr<Instance> inst = **userdata;
lua_pushstring(L, inst->name.c_str());
return 1;
}

View file

@ -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() {

View file

@ -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<Script> script = Script::New();
gWorkspace()->AddChild(script);
MainWindow* mainWnd = dynamic_cast<MainWindow*>(window());
// mainWnd->openScriptDocument(script);
}
void PlaceDocument::dragEnterEvent(QDragEnterEvent* evt) {