From 6d88293ea029a2372250297bd014b78d40507aa7 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 23 Feb 2017 11:19:59 +0100 Subject: coroutine.status, coroutine.wrap, coroutine.running, coroutine.isyieldable --- tests/lcorolib.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests') diff --git a/tests/lcorolib.js b/tests/lcorolib.js index 6b48912..400e721 100644 --- a/tests/lcorolib.js +++ b/tests/lcorolib.js @@ -16,6 +16,7 @@ const lua = require('../src/lua.js'); const linit = require('../src/linit.js'); const CT = lua.constant_types; + test('simple coroutine', function (t) { let luaCode = ` local co = coroutine.create(function (start) @@ -50,4 +51,53 @@ test('simple coroutine', function (t) { 625, "Correct element(s) on the stack" ); +}); + + +test('simple coroutine', function (t) { + let luaCode = ` + local co = coroutine.create(function (start) + local b = coroutine.yield(start * start); + coroutine.yield(b * b) + end) + + local s1 = coroutine.status(co) + + local success, pow = coroutine.resume(co, 5) + success, pow = coroutine.resume(co, pow) + + coroutine.resume(co, pow) + + local s2 = coroutine.status(co) + + return s1, s2 + `, L; + + t.plan(3); + + // t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, bc, "test-coroutine"); + + lapi.lua_call(L, 0, -1); + + // }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tostring(L, -2), + "suspended", + "Correct element(s) on the stack" + ); + + t.strictEqual( + lapi.lua_tostring(L, -1), + "dead", + "Correct element(s) on the stack" + ); }); \ No newline at end of file -- cgit v1.2.3-70-g09d2