summaryrefslogtreecommitdiffstats
path: root/src/livecode/context.cpp
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2019-12-02 20:41:05 +0000
committers-ol <s-ol@users.noreply.github.com>2019-12-02 20:41:05 +0000
commit1820294e9ea199058ba4d0626b23992e08210b44 (patch)
tree8b6574d814b991dbcca3eaa92e557402bfee6b3e /src/livecode/context.cpp
parentmore janet bindings (diff)
downloadinkscape-1820294e9ea199058ba4d0626b23992e08210b44.tar.gz
inkscape-1820294e9ea199058ba4d0626b23992e08210b44.zip
move script to its own file
Diffstat (limited to 'src/livecode/context.cpp')
-rw-r--r--src/livecode/context.cpp46
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)