diff --git a/include/Ark/VM/VM.inl b/include/Ark/VM/VM.inl index b447e777..22f08568 100644 --- a/include/Ark/VM/VM.inl +++ b/include/Ark/VM/VM.inl @@ -21,9 +21,12 @@ Value VM::call(const std::string& name, Args&&... args) push(Value(ValueType::InstPtr, static_cast(0)), context); // convert and push arguments - std::vector fnargs { { Value(std::forward(args))... } }; - for (auto&& arg : fnargs | std::views::reverse) - push(arg, context); + if (sizeof...(args) > 0) + { + std::vector fnargs { { Value(std::forward(args))... } }; + for (auto&& arg : fnargs | std::views::reverse) + push(arg, context); + } // find function object and push it if it's a pageaddr/closure if (const auto dist = std::distance(m_state.m_symbols.begin(), it); std::cmp_less(dist, std::numeric_limits::max())) diff --git a/tests/unittests/Suites/EmbeddingSuite.cpp b/tests/unittests/Suites/EmbeddingSuite.cpp index ee4e1ff9..52d4fdda 100644 --- a/tests/unittests/Suites/EmbeddingSuite.cpp +++ b/tests/unittests/Suites/EmbeddingSuite.cpp @@ -63,6 +63,30 @@ Ark::UserType::ControlFuncs* get_cfs() ut::suite<"Embedding"> embedding_suite = [] { using namespace ut; + "[run string and call arkscript function from cpp without args]"_test = [] { + Ark::State state; + + should("compile the string without any error") = [&] { + expect(mut(state).doString("(let foo (fun () 4))")); + }; + + Ark::VM vm(state); + should("return exit code 0") = [&] { + expect(mut(vm).run() == 0_i); + }; + + should("have symbol foo registered") = [&] { + const auto func = mut(vm)["foo"]; + expect(func.isFunction()); + }; + + should("(foo) have a value of 4") = [&] { + const auto value = mut(vm).call("foo"); + expect(value.valueType() == Ark::ValueType::Number); + expect(value.number() == 4.0_d); + }; + }; + "[run string and call arkscript function from cpp]"_test = [] { Ark::State state;