From 33fed251303917f3a9bdc250df6af97f6246731c Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Mon, 20 Jul 2020 08:07:09 +0300 Subject: [PATCH 1/4] Blocks access to ffi in LuaJIT before the user script is loaded --- src/LuaJITEngine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index dc0dada..2ce826b 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -112,7 +112,10 @@ struct LuaJITEngine : ScriptEngine { << "float *switchLights[" << NUM_ROWS + 1 << "];" << std::endl << "};]]" << std::endl // Declare the function `_castBlock` used to transform `luaBlock` pointer into a LuaJIT cdata - << "function _castBlock(b) return ffi.cast('struct LuaProcessBlock*', b) end"; + << "_ffi_cast = ffi.cast" << std::endl + << "function _castBlock(b) return _ffi_cast('struct LuaProcessBlock*', b) end" << std::endl + // Unload ffi and require + << "ffi = nil; require = nil;" << std::endl; std::string ffi_script = ffi_stream.str(); // Compile the ffi script From 29d633cbdddaee5b06b80e168dba0b1ee9ff2937 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 22 Jul 2020 13:45:53 -0400 Subject: [PATCH 2/4] LuaJIT: Remove more global functions that could be abused. --- src/LuaJITEngine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index 2ce826b..0ec77ef 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -114,8 +114,8 @@ struct LuaJITEngine : ScriptEngine { // Declare the function `_castBlock` used to transform `luaBlock` pointer into a LuaJIT cdata << "_ffi_cast = ffi.cast" << std::endl << "function _castBlock(b) return _ffi_cast('struct LuaProcessBlock*', b) end" << std::endl - // Unload ffi and require - << "ffi = nil; require = nil;" << std::endl; + // Remove global functions that could be abused + << "jit = nil; require = nil; ffi = nil; load = nil; loadfile = nil; loadstring = nil; dofile = nil;" << std::endl; std::string ffi_script = ffi_stream.str(); // Compile the ffi script From 157906982d52dc964724008200eba3b6f10072ab Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 22 Jul 2020 13:47:44 -0400 Subject: [PATCH 3/4] Add "Set Pure Data application" menu item and open it when editing pd files. --- src/Prototype.cpp | 80 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 20 deletions(-) diff --git a/src/Prototype.cpp b/src/Prototype.cpp index 8f3fe2a..92c4f1d 100644 --- a/src/Prototype.cpp +++ b/src/Prototype.cpp @@ -28,19 +28,30 @@ ScriptEngine* createScriptEngine(std::string extension) { } -static std::string editorPath; +static std::string settingsEditorPath; +static std::string settingsPdEditorPath = +#if defined ARCH_LIN + "\"/usr/bin/pd\""; +#else + ""; +#endif json_t* settingsToJson() { json_t* rootJ = json_object(); - json_object_set_new(rootJ, "editorPath", json_string(editorPath.c_str())); + json_object_set_new(rootJ, "editorPath", json_string(settingsEditorPath.c_str())); + json_object_set_new(rootJ, "pdEditorPath", json_string(settingsPdEditorPath.c_str())); return rootJ; } void settingsFromJson(json_t* rootJ) { json_t* editorPathJ = json_object_get(rootJ, "editorPath"); if (editorPathJ) - editorPath = json_string_value(editorPathJ); + settingsEditorPath = json_string_value(editorPathJ); + + json_t* pdEditorPathJ = json_object_get(rootJ, "pdEditorPath"); + if (pdEditorPathJ) + settingsPdEditorPath = json_string_value(pdEditorPathJ); } void settingsLoad() { @@ -75,27 +86,43 @@ void settingsSave() { json_decref(rootJ); } -void setEditorDialog() { - char* editorPathC = NULL; +std::string getApplicationPathDialog() { + char* pathC = NULL; #if defined ARCH_LIN - editorPathC = osdialog_file(OSDIALOG_OPEN, "/usr/bin/", NULL, NULL); + pathC = osdialog_file(OSDIALOG_OPEN, "/usr/bin/", NULL, NULL); #elif defined ARCH_WIN osdialog_filters* filters = osdialog_filters_parse("Executable:exe"); - editorPathC = osdialog_file(OSDIALOG_OPEN, "C:/", NULL, filters); + pathC = osdialog_file(OSDIALOG_OPEN, "C:/", NULL, filters); osdialog_filters_free(filters); #elif defined ARCH_MAC osdialog_filters* filters = osdialog_filters_parse("Application:app"); - editorPathC = osdialog_file(OSDIALOG_OPEN, "/Applications/", NULL, filters); + pathC = osdialog_file(OSDIALOG_OPEN, "/Applications/", NULL, filters); osdialog_filters_free(filters); #endif - if (!editorPathC) + if (!pathC) + return ""; + + std::string path = "\""; + path += pathC; + path += "\""; + std::free(pathC); + return path; +} + +void setEditorDialog() { + std::string path = getApplicationPathDialog(); + if (path == "") return; + settingsEditorPath = path; + settingsSave(); +} - editorPath = "\""; - editorPath += editorPathC; - editorPath += "\""; +void setPdEditorDialog() { + std::string path = getApplicationPathDialog(); + if (path == "") + return; + settingsPdEditorPath = path; settingsSave(); - std::free(editorPathC); } @@ -463,6 +490,13 @@ struct Prototype : Module { } void editScript() { + std::string editorPath; + // HACK check if extension is .pd + if (string::filenameExtension(string::filename(path)) == "pd") + editorPath = settingsPdEditorPath; + else + editorPath = settingsEditorPath; + if (editorPath.empty()) return; if (path.empty()) @@ -539,22 +573,28 @@ struct Prototype : Module { }; EditScriptItem* editScriptItem = createMenuItem("Edit script"); editScriptItem->module = this; - editScriptItem->disabled = !doesPathExist() || editorPath == ""; + + // TODO fix for pdEditorPath + editScriptItem->disabled = !doesPathExist() || settingsEditorPath == "" && false; menu->addChild(editScriptItem); + menu->addChild(new MenuSeparator); + struct SetEditorItem : MenuItem { void onAction(const event::Action& e) override { setEditorDialog(); } }; - SetEditorItem* setEditorItem = createMenuItem("Set editor application"); + SetEditorItem* setEditorItem = createMenuItem("Set text editor application"); menu->addChild(setEditorItem); - // if (!editorPath.empty()) { - // std::string editorBase = string::filenameBase(string::filename(editorPath)); - // MenuLabel* editorBaseLabel = createMenuLabel(editorBase); - // menu->addChild(editorBaseLabel); - // } + struct SetPdEditorItem : MenuItem { + void onAction(const event::Action& e) override { + setPdEditorDialog(); + } + }; + SetPdEditorItem* setPdEditorItem = createMenuItem("Set Pure Data application"); + menu->addChild(setPdEditorItem); } }; From d19b94de3bad814907bd242d3bf338c59311ab73 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 22 Jul 2020 13:50:20 -0400 Subject: [PATCH 4/4] Bump version to 1.3.0. --- CHANGELOG.md | 2 +- README.md | 2 +- plugin.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f73a2d6..0214990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,4 +28,4 @@ - Use ArrayBuffers instead of arrays, improving performance \~5x. ### 1.0.0 (2019-09-15) -- Initial release. \ No newline at end of file +- Initial release. diff --git a/README.md b/README.md index 8d6bc4b..851a631 100644 --- a/README.md +++ b/README.md @@ -149,5 +149,5 @@ make - [Andrew Belt](https://github.com/AndrewBelt): host code, Duktape (JavaScript, not used), LuaJIT (Lua), Python (in development) - [Jerry Sievert](https://github.com/JerrySievert): QuickJS (JavaScript) - [Leonardo Laguna Ruiz](https://github.com/modlfo): Vult -- [CHAIR](https://chair.audio) [Clemens Wegener (libpd), Max Neupert (patches)] : libpd +- [CHAIR](https://chair.audio) (Clemens Wegener, Max Neupert): libpd - add your name here diff --git a/plugin.json b/plugin.json index ce953cc..5e748bb 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "slug": "VCV-Prototype", "name": "Prototype", - "version": "1.2.0", + "version": "1.3.0", "license": "GPL-3.0-or-later", "brand": "VCV", "author": "VCV",