diff --git a/test/test_04_lua_function.cpp b/test/test_04_lua_function.cpp index fdbaa2b..767809a 100644 --- a/test/test_04_lua_function.cpp +++ b/test/test_04_lua_function.cpp @@ -175,6 +175,38 @@ void corresult_to_main2(kaguya::VariadicArgType args) } +int coroutine_exec(kaguya::LuaThread cor) +{ + return cor.resume() * 2; +} + +KAGUYA_TEST_FUNCTION_DEF(coroutine_on_the_coroutine)(kaguya::State& state) +{ + TEST_CHECK(state("cor1 = coroutine.create( function()" + "coroutine.yield(32) " + "coroutine.yield(53) " + "return 2 " + " end)")); + + state["coroutine_exec"] = coroutine_exec; + + TEST_CHECK(state("cor2 = coroutine.wrap( function()" + "coroutine.yield(coroutine_exec(cor1)) " + "coroutine.yield(coroutine_exec(cor1)) " + "return 4 " + " end)")); + + kaguya::LuaRef cor = state["cor2"]; + int r1 = cor(); + int r2 = cor(); + int r3 = cor(); + + TEST_EQUAL(r1, 32*2); + TEST_EQUAL(r2, 53*2); + TEST_EQUAL(r3, 4); +} + + KAGUYA_TEST_FUNCTION_DEF(coroutine_stack)(kaguya::State& state) { state["corresult_to_main"] = &corresult_to_main; @@ -226,7 +258,7 @@ KAGUYA_TEST_FUNCTION_DEF(bind_to_std_function)(kaguya::State& state) } -KAGUYA_TEST_FUNCTION_DEF(zero_to_nullpointer)(kaguya::State& state) +KAGUYA_TEST_FUNCTION_DEF(call_error)(kaguya::State& state) { state.setErrorHandler(ignore_error_fun); @@ -243,12 +275,28 @@ KAGUYA_TEST_FUNCTION_DEF(zero_to_nullpointer)(kaguya::State& state) kaguya::LuaFunction nilfn; nilfn.call(); } - + { + last_error_message = ""; + kaguya::LuaFunction notfn = state.newTable(); + TEST_COMPARE_NE(last_error_message, ""); + notfn.call(); + } } -KAGUYA_TEST_FUNCTION_DEF(result_range_based_for)(kaguya::State& state) +KAGUYA_TEST_FUNCTION_DEF(function_result_for)(kaguya::State& state) { + { + const kaguya::FunctionResults empty; + TEST_EQUAL(empty.result_size(), 0); + std::vector res; + for (kaguya::FunctionResults::iterator it = empty.begin(); it != empty.end(); ++it) + { + res.push_back(*it); + } + TEST_EQUAL(res.size(), 0); + } + state("fn =function() return 1,2,4,8,16 end"); { std::vector res; diff --git a/test/test_05_lua_ref.cpp b/test/test_05_lua_ref.cpp index 944ff50..3cb062b 100644 --- a/test/test_05_lua_ref.cpp +++ b/test/test_05_lua_ref.cpp @@ -506,6 +506,12 @@ KAGUYA_TEST_FUNCTION_DEF(nostate_ref_error)(kaguya::State& state) TEST_CHECK(!v.setFunctionEnv(state.newTable())); TEST_CHECK(!v.getFunctionEnv()); TEST_CHECK(!v.getField("s")); + TEST_CHECK(!v.setField("s", 2)); + TEST_CHECK(!v.setField("s", "a")); + TEST_CHECK(!v.setField("s", std::string("a"))); + TEST_CHECK(!v.setField("s", table)); + TEST_CHECK(!v.setField("s", kaguya::NilValue())); + TEST_CHECK(!v.setField(kaguya::NilValue(), kaguya::NilValue())); TEST_CHECK(!table.getFunctionEnv()); @@ -523,6 +529,7 @@ KAGUYA_TEST_FUNCTION_DEF(nostate_ref_error)(kaguya::State& state) TEST_CHECK(!cv.getFunctionEnv()); TEST_CHECK(!cv.getField("s")); + TEST_CHECK(!cv.getField("s")); TEST_CHECK(!ctable.getFunctionEnv()); diff --git a/test/test_09_utility.cpp b/test/test_09_utility.cpp new file mode 100644 index 0000000..a3c50e3 --- /dev/null +++ b/test/test_09_utility.cpp @@ -0,0 +1,26 @@ +#include "kaguya/kaguya.hpp" +#include "test_util.hpp" + +KAGUYA_TEST_GROUP_START(test_09_utility) + +using namespace kaguya_test_util; + + +KAGUYA_TEST_FUNCTION_DEF(resume)(kaguya::State& s) +{ + using namespace kaguya; + + + LuaThread t = s.newThread(s.loadstring("v={...}")); + + lua_State* co = t.get(); + lua_pushnumber(co, 2); + lua_pushnumber(co, 3); + + lua_resume(co,s.state(),2); + + TEST_EQUAL(s["v"][1], 2); + TEST_EQUAL(s["v"][2], 3); +} + +KAGUYA_TEST_GROUP_END(test_09_utility)