Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Oct 5, 2024
1 parent c957a5c commit 2c52437
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 473 deletions.
2 changes: 1 addition & 1 deletion src/popup.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ method handleMouseMove*(self: Popup, mousePosWindow: Vec2, mousePosDelta: Vec2,
import document_editor

method getActiveEditor*(self: Popup): Option[DocumentEditor] {.base.} =
discard
discard
25 changes: 15 additions & 10 deletions src/scripting/scripting_base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import misc/[custom_logger, custom_async]
import expose, document_editor, compilation_config
import platform/filesystem

{.push gcsafe.}
{.push raises: [].}

type ScriptContext* = ref object of RootObj
fs*: Filesystem

method init*(self: ScriptContext, path: string, fs: Filesystem): Future[void] {.base, gcsafe, raises: [].} = discard
method deinit*(self: ScriptContext) {.base, gcsafe, raises: [].} = discard
method reload*(self: ScriptContext): Future[void] {.base, gcsafe, raises: [].} = discard
method init*(self: ScriptContext, path: string, fs: Filesystem): Future[void] {.base.} = discard
method deinit*(self: ScriptContext) {.base.} = discard
method reload*(self: ScriptContext): Future[void] {.base.} = discard

method handleEditorModeChanged*(self: ScriptContext, editor: DocumentEditor, oldMode: string, newMode: string) {.base.} = discard
method postInitialize*(self: ScriptContext): bool {.base.} = discard
method handleCallback*(self: ScriptContext, id: int, arg: JsonNode): bool {.base.} = discard
method handleAnyCallback*(self: ScriptContext, id: int, arg: JsonNode): JsonNode {.base.} = discard
method handleScriptAction*(self: ScriptContext, name: string, args: JsonNode): JsonNode {.base.} = discard
method getCurrentContext*(self: ScriptContext): string {.base.} = ""

method handleEditorModeChanged*(self: ScriptContext, editor: DocumentEditor, oldMode: string, newMode: string) {.base, gcsafe, raises: [].} = discard
method postInitialize*(self: ScriptContext): bool {.base, gcsafe, raises: [].} = discard
method handleCallback*(self: ScriptContext, id: int, arg: JsonNode): bool {.base, gcsafe, raises: [].} = discard
method handleAnyCallback*(self: ScriptContext, id: int, arg: JsonNode): JsonNode {.base, gcsafe, raises: [].} = discard
method handleScriptAction*(self: ScriptContext, name: string, args: JsonNode): JsonNode {.base, gcsafe, raises: [].} = discard
method getCurrentContext*(self: ScriptContext): string {.base, gcsafe, raises: [].} = ""
{.pop.} # raises

proc generateScriptingApiPerModule*() {.compileTime.} =
var imports_content = "import \"../src/scripting_api\"\nexport scripting_api\n\n## This file is auto generated, don't modify.\n\n"
Expand Down Expand Up @@ -84,4 +89,4 @@ import scripting_api, misc/myjsonutils
imports_content.add "\nconst enableAst* = false\n"

echo fmt"Writing scripting/plugin_api.nim"
writeFile(fmt"scripting/plugin_api.nim", imports_content)
writeFile(fmt"scripting/plugin_api.nim", imports_content)
16 changes: 10 additions & 6 deletions src/scripting/scripting_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ when not defined(js):

export scripting_base, wasm

{.push gcsafe.}

logCategory "scripting-wasm"

type
Expand All @@ -32,7 +34,7 @@ method readImpl*(self: VFSWasmContext, path: string): Future[Option[string]] {.a
log lvlError, &"[VFSWasmContext] read({path}): not found"
return string.none

var createEditorWasmImports: proc(): WasmImports {.gcsafe, raises: [].}
var createEditorWasmImports: proc(): WasmImports {.raises: [].}

method getCurrentContext*(self: ScriptContextWasm): string =
result = "plugs://"
Expand Down Expand Up @@ -94,6 +96,8 @@ proc loadModules(self: ScriptContextWasm, path: string): Future[void] {.async.}
except:
log lvlError, &"Failde to load wasm module '{file}': {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}"

{.push raises: [].}

method init*(self: ScriptContextWasm, path: string, fs: Filesystem): Future[void] {.async.} =
self.fs = fs
await self.loadModules("./config/wasm")
Expand All @@ -111,14 +115,14 @@ method reload*(self: ScriptContextWasm): Future[void] {.async.} =

await self.loadModules("./config/wasm")

method handleEditorModeChanged*(self: ScriptContextWasm, editor: DocumentEditor, oldMode: string, newMode: string) {.gcsafe, raises: [].} =
method handleEditorModeChanged*(self: ScriptContextWasm, editor: DocumentEditor, oldMode: string, newMode: string) =
try:
for (m, f) in self.editorModeChangedCallbacks:
f(editor.id.int32, oldMode.cstring, newMode.cstring)
except:
log lvlError, &"Failed to run handleEditorModeChanged: {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}"

method postInitialize*(self: ScriptContextWasm): bool {.gcsafe, raises: [].} =
method postInitialize*(self: ScriptContextWasm): bool =
result = false
try:
for (m, f) in self.postInitializeCallbacks:
Expand All @@ -128,7 +132,7 @@ method postInitialize*(self: ScriptContextWasm): bool {.gcsafe, raises: [].} =
except:
log lvlError, &"Failed to run post initialize: {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}"

method handleCallback*(self: ScriptContextWasm, id: int, arg: JsonNode): bool {.gcsafe, raises: [].} =
method handleCallback*(self: ScriptContextWasm, id: int, arg: JsonNode): bool =
result = false
try:
let argStr = $arg
Expand All @@ -140,7 +144,7 @@ method handleCallback*(self: ScriptContextWasm, id: int, arg: JsonNode): bool {.
except:
log lvlError, &"Failed to run callback: {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}"

method handleAnyCallback*(self: ScriptContextWasm, id: int, arg: JsonNode): JsonNode {.gcsafe, raises: [].} =
method handleAnyCallback*(self: ScriptContextWasm, id: int, arg: JsonNode): JsonNode =
try:
result = nil
let argStr = $arg
Expand All @@ -160,7 +164,7 @@ method handleAnyCallback*(self: ScriptContextWasm, id: int, arg: JsonNode): Json
log lvlError, &"Failed to run handleAnyCallback: {getCurrentExceptionMsg()}\n{getCurrentException().getStackTrace()}"


method handleScriptAction*(self: ScriptContextWasm, name: string, args: JsonNode): JsonNode {.gcsafe, raises: [].} =
method handleScriptAction*(self: ScriptContextWasm, name: string, args: JsonNode): JsonNode =
try:
result = nil
let argStr = $args
Expand Down
Loading

0 comments on commit 2c52437

Please sign in to comment.