diff --git a/lib/rhai/engine.ex b/lib/rhai/engine.ex index ca250a6..3bf8d63 100644 --- a/lib/rhai/engine.ex +++ b/lib/rhai/engine.ex @@ -26,6 +26,14 @@ defmodule Rhai.Engine do wrap_resource(Rhai.Native.engine_new()) end + @doc """ + Create a new Engine with minimal built-in functions. + """ + @spec new_raw :: t() + def new_raw do + wrap_resource(Rhai.Native.engine_new_raw()) + end + @doc """ Register a shared dylib Module into the global namespace of Engine. diff --git a/lib/rhai/native.ex b/lib/rhai/native.ex index c5e8915..b790c93 100644 --- a/lib/rhai/native.ex +++ b/lib/rhai/native.ex @@ -29,6 +29,7 @@ defmodule Rhai.Native do def eval(_, _), do: err() # engine def engine_new, do: err() + def engine_new_raw, do: err() def engine_register_global_module(_engine, _path), do: err() def engine_register_static_module(_engine, _namespace, _path), do: err() def engine_compile(_engine, _script), do: err() diff --git a/native/rhai_rustler/src/engine.rs b/native/rhai_rustler/src/engine.rs index 28b8b14..fd5b979 100644 --- a/native/rhai_rustler/src/engine.rs +++ b/native/rhai_rustler/src/engine.rs @@ -42,6 +42,15 @@ fn engine_new() -> ResourceArc { }) } +#[rustler::nif] +fn engine_new_raw() -> ResourceArc { + let engine = Engine::new_raw(); + + ResourceArc::new(EngineResource { + engine: Mutex::new(engine), + }) +} + #[rustler::nif] fn engine_register_global_module( resource: ResourceArc, diff --git a/native/rhai_rustler/src/lib.rs b/native/rhai_rustler/src/lib.rs index 25a3dfa..9f33af6 100644 --- a/native/rhai_rustler/src/lib.rs +++ b/native/rhai_rustler/src/lib.rs @@ -62,6 +62,7 @@ rustler::init!( eval, // engine engine_new, + engine_new_raw, engine_compile, engine_compile_with_scope, engine_compile_expression, diff --git a/test/rhai/engine_test.exs b/test/rhai/engine_test.exs index a86c4ad..489cd28 100644 --- a/test/rhai/engine_test.exs +++ b/test/rhai/engine_test.exs @@ -9,6 +9,12 @@ defmodule Rhai.EngineTest do end end + describe "new_raw/0" do + test "should create a new raw engine" do + assert %Engine{} = Engine.new_raw() + end + end + describe "module resolvers" do test "should load a dylib module via the import directive" do assert {:ok, [6, "inner", "value"]} =