Compare commits
2 commits
cc1da0804e
...
c58c262ccf
Author | SHA1 | Date | |
---|---|---|---|
c58c262ccf | |||
e00aa46911 |
4 changed files with 20 additions and 10 deletions
|
@ -7,7 +7,6 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
extern const char* WRAPPER_SRC; // TODO: Move this to a shared header
|
||||
int script_errhandler(lua_State*); // extern
|
||||
|
||||
SignalSource::SignalSource() : std::shared_ptr<Signal>(std::make_shared<Signal>()) {}
|
||||
|
@ -62,7 +61,7 @@ void LuaSignalConnection::Call(std::vector<Variant> args) {
|
|||
lua_State* thread = lua_newthread(state);
|
||||
|
||||
// Push wrapepr as thread function
|
||||
luaL_loadbuffer(thread, WRAPPER_SRC, strlen(WRAPPER_SRC), "=PCALL_WRAPPER");
|
||||
lua_getfield(thread, LUA_REGISTRYINDEX, "LuaPCallWrapper");
|
||||
|
||||
// Push function as upvalue for wrapper
|
||||
lua_rawgeti(thread, LUA_REGISTRYINDEX, function);
|
||||
|
|
|
@ -16,9 +16,6 @@ int script_wait(lua_State*);
|
|||
int script_delay(lua_State*);
|
||||
int script_errhandler(lua_State*);
|
||||
|
||||
// TODO: Move this to a shared header
|
||||
const char* WRAPPER_SRC = "local func, errhandler = ... return function(...) local args = {...} xpcall(function() func(unpack(args)) end, errhandler) end";
|
||||
|
||||
Script::Script(): Instance(&TYPE) {
|
||||
source = "print(\"Hello, world!\")";
|
||||
}
|
||||
|
@ -59,7 +56,7 @@ void Script::Run() {
|
|||
lua_pop(Lt, 1); // _G
|
||||
|
||||
// Push wrapper as thread function
|
||||
luaL_loadbuffer(Lt, WRAPPER_SRC, strlen(WRAPPER_SRC), "=PCALL_WRAPPER");
|
||||
lua_getfield(Lt, LUA_REGISTRYINDEX, "LuaPCallWrapper");
|
||||
|
||||
// Load source code and push onto thread as upvalue for wrapper
|
||||
int status = luaL_loadbuffer(Lt, source.c_str(), source.size(), this->GetFullName().c_str());
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <string>
|
||||
#include "luaapis.h" // IWYU pragma: keep
|
||||
|
||||
const char* WRAPPER_SRC = "local func, errhandler = ... return function(...) local args = {...} xpcall(function() func(unpack(args)) end, errhandler) end";
|
||||
|
||||
static int g_print(lua_State*);
|
||||
static int g_require(lua_State*);
|
||||
static const struct luaL_Reg luaglobals [] = {
|
||||
|
@ -48,6 +50,10 @@ void ScriptContext::InitService() {
|
|||
Color3::PushLuaLibrary(state);
|
||||
Instance::PushLuaLibrary(state);
|
||||
|
||||
// Add wrapper function
|
||||
luaL_loadbuffer(state, WRAPPER_SRC, strlen(WRAPPER_SRC), "=PCALL_WRAPPER");
|
||||
lua_setfield(state, LUA_REGISTRYINDEX, "LuaPCallWrapper");
|
||||
|
||||
// TODO: custom os library
|
||||
|
||||
// Override print
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <QStyledItemDelegate>
|
||||
#include <QPainter>
|
||||
#include <QTime>
|
||||
#include <cfloat>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <qapplication.h>
|
||||
|
@ -24,6 +23,14 @@
|
|||
#include <qnamespace.h>
|
||||
#include <qtreewidget.h>
|
||||
|
||||
QDoubleSpinBox* makeDoubleSpinBox(QWidget* parent = nullptr) {
|
||||
QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
|
||||
spinBox->setMaximum(INFINITY);
|
||||
spinBox->setMinimum(-INFINITY);
|
||||
spinBox->setDecimals(4);
|
||||
return spinBox;
|
||||
}
|
||||
|
||||
class PropertiesItemDelegate : public QStyledItemDelegate {
|
||||
PropertiesView* view;
|
||||
public:
|
||||
|
@ -64,7 +71,7 @@ public:
|
|||
Vector3 vector = currentValue.get<Vector3>();
|
||||
float value = componentName == "X" ? vector.X() : componentName == "Y" ? vector.Y() : componentName == "Z" ? vector.Z() : 0;
|
||||
|
||||
QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
|
||||
QDoubleSpinBox* spinBox = makeDoubleSpinBox(parent);
|
||||
spinBox->setValue(value);
|
||||
|
||||
return spinBox;
|
||||
|
@ -75,9 +82,9 @@ public:
|
|||
|
||||
if (meta.type.descriptor == &FLOAT_TYPE) {
|
||||
QDoubleSpinBox* spinBox = new QDoubleSpinBox(parent);
|
||||
spinBox->setValue(currentValue.get<float>());
|
||||
spinBox->setMinimum(-INFINITY);
|
||||
spinBox->setMaximum(INFINITY);
|
||||
spinBox->setValue(currentValue.get<float>());
|
||||
|
||||
if (meta.flags & PROP_UNIT_FLOAT) {
|
||||
spinBox->setMinimum(0);
|
||||
|
@ -221,7 +228,8 @@ public:
|
|||
: componentName == "Z" ? Vector3(prev.X(), prev.Y(), value) : prev;
|
||||
|
||||
inst->SetProperty(propertyName, newVector).expect();
|
||||
view->rebuildCompositeProperty(view->itemFromIndex(index.parent()), &Vector3::TYPE, newVector);
|
||||
// SetProperty above already causes the composite to be rebuilt. So we get rid of it here to prevent errors
|
||||
// view->rebuildCompositeProperty(view->itemFromIndex(index.parent()), &Vector3::TYPE, newVector);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue