Creating Native Extension with Clojure

Hello. I need to make a native extension using Clojure. For the extension I need to make I will need to add a key shortcut to the editor or at least just add a new entry in the Outline context menu. Nevertheless, before I do that I need to at least have a working minimal template for Clojure that can just load in editor and do nothing as starting point.
There are very few native extensions that use Clojure at all and all of them during their initialization register asset types, but in my case I won’t have to register asset types or do anything at the time plugin initializes. So I tried and came up with this code:

(ns editor.pasteextended
  (:require [clojure.java.io :as io]
            [clojure.string :as string]
            [dynamo.graph :as g]
            [editor.app-view :as app-view]
            [editor.build-target :as bt]
            [editor.colors :as colors]
            [editor.defold-project :as project]
            [editor.dialogs :as dialogs]
            [editor.geom :as geom]
            [editor.gl :as gl]
            [editor.gl.pass :as pass]
            [editor.gl.shader :as shader]
            [editor.gl.texture :as texture]
            [editor.gl.vertex2 :as vtx]
            [editor.graph-util :as gu]
            [editor.handler :as handler]
            [editor.outline :as outline]
            [editor.pipeline :as pipeline]
            [editor.pipeline.tex-gen :as tex-gen]
            [editor.properties :as properties]
            [editor.protobuf :as protobuf]
            [editor.render :as render]
            [editor.resource :as resource]
            [editor.resource-node :as resource-node]
            [editor.scene-picking :as scene-picking]
            [editor.texture-set :as texture-set]
            [editor.types :as types]
            [editor.util :as util]
            [editor.validation :as validation]
            [editor.workspace :as workspace]
            [internal.java :as java]
            [schema.core :as s]
            [util.coll :refer [pair]]
            [util.digestable :as digestable])
  (:import [com.dynamo.gamesys.proto Gui$NodeDesc$ClippingMode]
           [editor.gl.texture TextureLifecycle]
           [javax.vecmath Matrix4d Point3d]))

(set! *warn-on-reflection* true)

; The plugin
(defn- load-plugin-pasteext [workspace]
  ())

(defn- return-plugin []
  (fn [x] (load-plugin-pasteext x)))
(return-plugin)

When I try to load the editor I’m getting the following error:
image

What could I be missing? Thanks for help in advance.
Target Defold version: 1.6.4

Hi! Defold editor dev here. While we’ve made some extensions to the editor as part of our Spine, Rive and TexurePacker extensions, this way of extending the editor is not really officially supported at the moment. Often, making something work requires exposing functionality from the editor code to the plugins, and the API hasn’t been stabilized for public consumption. If you use it, you’re likely to see your extension break quite often as we make changes to the editor. You probably have a call stack in the editor logs with information about the exception, but I would advise you to not go down this route at present. For our own Clojure-based extensions, we have test suites that verify we don’t break stuff, but we simply cannot cover every extension the community makes.

Our “official” method for extending the editor is currently to use Editor Scripts, which are written in Lua. Unfortunately the exposed API is still very limited. Nevertheless, some users have had success with a combination of editor scripts and external executables or Python scripts and the like. We intend to grow the Editor Scripts API organically as new needs arise, but we’ve unfortunately not been able to dedicate the required resources to it for quite some time.

3 Likes