summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--src/lcorolib.js4
-rw-r--r--src/lvm.js1
-rw-r--r--tests/lcorolib.js51
4 files changed, 52 insertions, 10 deletions
diff --git a/README.md b/README.md
index fd3b3bd..2eec1ff 100644
--- a/README.md
+++ b/README.md
@@ -56,6 +56,7 @@
- [x] lua_pushnil
- [x] lua_pushnumber
- [x] lua_pushstring
+ - [x] lua_pushthread
- [x] lua_pushvalue
- [x] lua_rawequal
- [x] lua_rawget
@@ -121,7 +122,6 @@
- [ ] lua_pcallk
- [ ] lua_pushfstring
- [ ] lua_pushlightuserdata
- - [ ] lua_pushthread
- [ ] lua_pushvfstring
- [ ] lua_rawgetp
- [ ] lua_rawseti
@@ -224,11 +224,11 @@
- [ ] load
- [ ] Coroutine
- [x] coroutine.create
+ - [x] coroutine.isyieldable
- [x] coroutine.resume
+ - [x] coroutine.status
- [x] coroutine.yield
- - [ ] coroutine.isyieldable
- [ ] coroutine.running
- - [ ] coroutine.status
- [ ] coroutine.wrap
- [ ] Debug (errors)
- [ ] DOM API binding
diff --git a/src/lcorolib.js b/src/lcorolib.js
index b595d4d..32532a6 100644
--- a/src/lcorolib.js
+++ b/src/lcorolib.js
@@ -32,7 +32,7 @@ const auxresume = function(L, co, narg) {
lapi.lua_xmove(L, co, narg);
let status = ldo.lua_resume(co, L, narg);
if (status === TS.LUA_OK || status === TS.LUA_YIELD) {
- let nres = lapi.lua_gettop(L);
+ let nres = lapi.lua_gettop(co);
if (!lapi.lua_checkstack(L, nres + 1)) {
lapi.lua_pop(co, nres); /* remove results anyway */
lapi.lua_pushliteral(L, "too many results to resume");
@@ -123,7 +123,7 @@ const luaB_costatus = function(L) {
};
const luaB_yieldable = function(L) {
- lapi.lua_pushboolean(L, lapi.lua_isyieldable(L));
+ lapi.lua_pushboolean(L, ldo.lua_isyieldable(L));
return 1;
};
diff --git a/src/lvm.js b/src/lvm.js
index 15a11e4..5615acd 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -521,6 +521,7 @@ const luaV_execute = function(L) {
for (let aux = 0; nfuncOff + aux < lim; aux++)
L.stack[ofuncOff + aux] = L.stack[nfuncOff + aux];
oci.func = nci.func;
+ oci.funcOff = nci.funcOff;
oci.u.l.base = ofuncOff + (nci.u.l.base - nfuncOff);
L.top = ofuncOff + (L.top - nfuncOff);
oci.top = L.top;
diff --git a/tests/lcorolib.js b/tests/lcorolib.js
index 400e721..5f6d43d 100644
--- a/tests/lcorolib.js
+++ b/tests/lcorolib.js
@@ -17,7 +17,7 @@ const linit = require('../src/linit.js');
const CT = lua.constant_types;
-test('simple coroutine', function (t) {
+test('coroutine.create, coroutine.yield, coroutine.resume', function (t) {
let luaCode = `
local co = coroutine.create(function (start)
local b = coroutine.yield(start * start);
@@ -54,7 +54,7 @@ test('simple coroutine', function (t) {
});
-test('simple coroutine', function (t) {
+test('coroutine.status', function (t) {
let luaCode = `
local co = coroutine.create(function (start)
local b = coroutine.yield(start * start);
@@ -75,7 +75,7 @@ test('simple coroutine', function (t) {
t.plan(3);
- // t.doesNotThrow(function () {
+ t.doesNotThrow(function () {
let bc = toByteCode(luaCode).dataView;
@@ -83,11 +83,11 @@ test('simple coroutine', function (t) {
linit.luaL_openlibs(L);
- lapi.lua_load(L, bc, "test-coroutine");
+ lapi.lua_load(L, bc, "test-coroutine.status");
lapi.lua_call(L, 0, -1);
- // }, "JS Lua program ran without error");
+ }, "JS Lua program ran without error");
t.strictEqual(
lapi.lua_tostring(L, -2),
@@ -100,4 +100,45 @@ test('simple coroutine', function (t) {
"dead",
"Correct element(s) on the stack"
);
+});
+
+
+test('coroutine.isyieldable', function (t) {
+ let luaCode = `
+ local co = coroutine.create(function ()
+ coroutine.yield(coroutine.isyieldable());
+ end)
+
+ local succes, yieldable = coroutine.resume(co)
+
+ return yieldable, coroutine.isyieldable()
+ `, 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.isyieldable");
+
+ lapi.lua_call(L, 0, -1);
+
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lapi.lua_toboolean(L, -2),
+ true,
+ "Correct element(s) on the stack"
+ );
+
+ t.strictEqual(
+ lapi.lua_toboolean(L, -1),
+ false,
+ "Correct element(s) on the stack"
+ );
}); \ No newline at end of file