Compare commits

...

2 commits

5 changed files with 39 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";
@ -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

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 */
};
@ -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<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

@ -13,8 +13,12 @@
#include <QStyledItemDelegate>
#include <QPainter>
#include <QTime>
#include <cfloat>
#include <cmath>
#include <functional>
#include <qapplication.h>
#include <qcombobox.h>
#include <qevent.h>
#include <qnamespace.h>
#include <qtreewidget.h>
@ -72,6 +76,8 @@ public:
if (meta.type.descriptor == &FLOAT_TYPE) {
QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
spinBox->setValue(currentValue.get<float>());
spinBox->setMinimum(-INFINITY);
spinBox->setMaximum(INFINITY);
if (meta.flags & PROP_UNIT_FLOAT) {
spinBox->setMinimum(0);
@ -82,6 +88,8 @@ public:
return spinBox;
} else if (meta.type.descriptor == &INT_TYPE) {
QSpinBox* spinBox = new QSpinBox(parent);
spinBox->setMinimum(INT_MIN);
spinBox->setMaximum(INT_MAX);
spinBox->setValue(currentValue.get<int>());
return spinBox;
@ -108,6 +116,13 @@ public:
comboBox->setCurrentIndex(i);
}
// If a selection is made
// https://forum.qt.io/post/426902
connect(comboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this, comboBox, index]() {
setModelData(comboBox, view->model(), index);
view->closeEditor(comboBox, QAbstractItemDelegate::EndEditHint::NoHint);
});
return comboBox;
} else if (meta.type.descriptor->fromString) {
QLineEdit* lineEdit = new QLineEdit(parent);

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