From e8a12210e0a5a0d86b5bacfd10e673b36d56fb38 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 23 Feb 2017 15:14:11 +0100 Subject: coroutine.wrap --- tests/lcorolib.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests') diff --git a/tests/lcorolib.js b/tests/lcorolib.js index dfecd71..78024dd 100644 --- a/tests/lcorolib.js +++ b/tests/lcorolib.js @@ -181,4 +181,41 @@ test('coroutine.running', function (t) { lapi.lua_toboolean(L, -1), "Correct element(s) on the stack" ); +}); + + +test('coroutine.wrap', function (t) { + let luaCode = ` + local co = coroutine.wrap(function (start) + local b = coroutine.yield(start * start); + coroutine.yield(b * b) + end) + + pow = co(5) + pow = co(pow) + + return pow + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-coroutine.wrap"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tonumber(L, -1), + 625, + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2