Fold scripting runtime into Lua
This commit is contained in:
1
AUDIT.md
1
AUDIT.md
@@ -43,6 +43,7 @@ after each item.
|
|||||||
- [x] `scripting/job_store.ex`
|
- [x] `scripting/job_store.ex`
|
||||||
- [x] `desktop/server.ex`
|
- [x] `desktop/server.ex`
|
||||||
- [x] `desktop/shell_live/code_entity_editor.ex`
|
- [x] `desktop/shell_live/code_entity_editor.ex`
|
||||||
|
- [x] `scripting/runtime.ex`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ defmodule BDS.Scripting do
|
|||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
alias BDS.Scripting.Capabilities
|
alias BDS.Scripting.Capabilities
|
||||||
alias BDS.Scripting.Runtime
|
alias BDS.Scripting.Lua
|
||||||
|
|
||||||
@type job_status :: :queued | :running | :completed | :failed | :cancelled
|
@type job_status :: :queued | :running | :completed | :failed | :cancelled
|
||||||
@type job_snapshot :: %{
|
@type job_snapshot :: %{
|
||||||
@@ -31,7 +31,7 @@ defmodule BDS.Scripting do
|
|||||||
runtime().validate(source)
|
runtime().validate(source)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec execute(String.t(), String.t(), [term()], [Runtime.execution_option()]) ::
|
@spec execute(String.t(), String.t(), [term()], [Lua.execution_option()]) ::
|
||||||
{:ok, term()} | {:error, term()}
|
{:ok, term()} | {:error, term()}
|
||||||
def execute(source, entrypoint, args \\ [], opts \\ [])
|
def execute(source, entrypoint, args \\ [], opts \\ [])
|
||||||
when is_binary(source) and is_binary(entrypoint) and is_list(args) and is_list(opts) do
|
when is_binary(source) and is_binary(entrypoint) and is_list(args) and is_list(opts) do
|
||||||
@@ -39,7 +39,7 @@ defmodule BDS.Scripting do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@spec execute_project_script(String.t(), String.t(), String.t(), [term()], [
|
@spec execute_project_script(String.t(), String.t(), String.t(), [term()], [
|
||||||
Runtime.execution_option()
|
Lua.execution_option()
|
||||||
]) ::
|
]) ::
|
||||||
{:ok, term()} | {:error, term()}
|
{:ok, term()} | {:error, term()}
|
||||||
def execute_project_script(project_id, source, entrypoint, args \\ [], opts \\ [])
|
def execute_project_script(project_id, source, entrypoint, args \\ [], opts \\ [])
|
||||||
@@ -75,7 +75,7 @@ defmodule BDS.Scripting do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec start_job(String.t(), String.t(), [term()], [Runtime.execution_option()]) ::
|
@spec start_job(String.t(), String.t(), [term()], [Lua.execution_option()]) ::
|
||||||
{:ok, job_snapshot()} | {:error, term()}
|
{:ok, job_snapshot()} | {:error, term()}
|
||||||
def start_job(source, entrypoint, args \\ [], opts \\ [])
|
def start_job(source, entrypoint, args \\ [], opts \\ [])
|
||||||
when is_binary(source) and is_binary(entrypoint) and is_list(args) and is_list(opts) do
|
when is_binary(source) and is_binary(entrypoint) and is_list(args) and is_list(opts) do
|
||||||
|
|||||||
@@ -6,7 +6,23 @@ defmodule BDS.Scripting.Lua do
|
|||||||
and opt-in.
|
and opt-in.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@behaviour BDS.Scripting.Runtime
|
@type source :: String.t()
|
||||||
|
@type entrypoint :: String.t()
|
||||||
|
@type args :: [term()]
|
||||||
|
@type progress_event :: map()
|
||||||
|
@type progress_callback :: (progress_event() -> any())
|
||||||
|
@type execution_option ::
|
||||||
|
{:timeout, non_neg_integer() | :infinity}
|
||||||
|
| {:max_reductions, pos_integer() | :none}
|
||||||
|
| {:spawn_opts, [term()]}
|
||||||
|
| {:on_progress, progress_callback()}
|
||||||
|
| {:capabilities, map()}
|
||||||
|
|
||||||
|
@callback validate(source()) :: :ok | {:error, term()}
|
||||||
|
@callback execute(source(), entrypoint(), args(), [execution_option()]) ::
|
||||||
|
{:ok, term()} | {:error, term()}
|
||||||
|
|
||||||
|
@behaviour __MODULE__
|
||||||
|
|
||||||
@type lua_state :: tuple()
|
@type lua_state :: tuple()
|
||||||
@type runtime_result :: {:ok, term(), lua_state} | {:error, term()}
|
@type runtime_result :: {:ok, term(), lua_state} | {:error, term()}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
defmodule BDS.Scripting.Runtime do
|
|
||||||
@moduledoc """
|
|
||||||
Behaviour for user-script runtimes hosted by bDS.
|
|
||||||
|
|
||||||
The runtime boundary is intentionally narrow: syntax validation and
|
|
||||||
bounded entrypoint execution.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@type source :: String.t()
|
|
||||||
@type entrypoint :: String.t()
|
|
||||||
@type args :: [term()]
|
|
||||||
@type progress_event :: map()
|
|
||||||
@type progress_callback :: (progress_event() -> any())
|
|
||||||
@type execution_option ::
|
|
||||||
{:timeout, non_neg_integer() | :infinity}
|
|
||||||
| {:max_reductions, pos_integer() | :none}
|
|
||||||
| {:spawn_opts, [term()]}
|
|
||||||
| {:on_progress, progress_callback()}
|
|
||||||
| {:capabilities, map()}
|
|
||||||
|
|
||||||
@callback validate(source()) :: :ok | {:error, term()}
|
|
||||||
@callback execute(source(), entrypoint(), args(), [execution_option()]) ::
|
|
||||||
{:ok, term()} | {:error, term()}
|
|
||||||
end
|
|
||||||
@@ -2,7 +2,7 @@ defmodule BDS.Scripting.JobTest do
|
|||||||
use ExUnit.Case, async: false
|
use ExUnit.Case, async: false
|
||||||
|
|
||||||
defmodule FakeRuntime do
|
defmodule FakeRuntime do
|
||||||
@behaviour BDS.Scripting.Runtime
|
@behaviour BDS.Scripting.Lua
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def validate(_source), do: :ok
|
def validate(_source), do: :ok
|
||||||
@@ -19,7 +19,7 @@ defmodule BDS.Scripting.JobTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule BlockingRuntime do
|
defmodule BlockingRuntime do
|
||||||
@behaviour BDS.Scripting.Runtime
|
@behaviour BDS.Scripting.Lua
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def validate(_source), do: :ok
|
def validate(_source), do: :ok
|
||||||
@@ -37,7 +37,7 @@ defmodule BDS.Scripting.JobTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule ShutdownAwareRuntime do
|
defmodule ShutdownAwareRuntime do
|
||||||
@behaviour BDS.Scripting.Runtime
|
@behaviour BDS.Scripting.Lua
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def validate(_source), do: :ok
|
def validate(_source), do: :ok
|
||||||
|
|||||||
Reference in New Issue
Block a user