diff options
Diffstat (limited to 'src/livecode/context.cpp')
| -rw-r--r-- | src/livecode/context.cpp | 46 |
1 files changed, 1 insertions, 45 deletions
diff --git a/src/livecode/context.cpp b/src/livecode/context.cpp index a22191400..b63641411 100644 --- a/src/livecode/context.cpp +++ b/src/livecode/context.cpp @@ -18,56 +18,12 @@ #include "display/sp-canvas-item.h" #include "livecode/context.h" +#include "livecode/script.h" #include "livecode/api/api.h" namespace Inkscape { namespace Livecode { -Script::Script(JanetTable *env, std::string const &path) - : env(env) - , function(nullptr) - , file(Gio::File::create_for_path(path)) - , monitor(file->monitor_file()) -{ - monitor->signal_changed().connect(sigc::mem_fun(this, &Script::file_changed)); - reload(); -} - -void Script::frame() { - if (function) { - Janet result; - janet_pcall(function, 0, NULL, &result, NULL); - } -} - -void Script::commit() { -} - -void Script::reload() { - try { - uint8_t *data; - size_t length; - file->load_contents((char *&)data, (gsize &)length); - - Janet result; - janet_dobytes(env, data, length, file->get_path().c_str(), &result); - if (janet_checktype(result, JANET_FUNCTION)) { - function = janet_unwrap_function(result); - } else { - g_message("Janet script didn't return a function"); - } - } catch (...) { - g_message("error loading file"); - } -} - -void Script::file_changed(const Glib::RefPtr<Gio::File>& file, - const Glib::RefPtr<Gio::File>& other_file, - Gio::FileMonitorEvent event) -{ - reload(); -} - Context::Context(SPDesktop *desktop) : desktop(desktop) , _mouse(*this) |
