summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lua/src/lcorolib.c
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lua/src/lcorolib.c')
-rw-r--r--3rdparty/lua/src/lcorolib.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/3rdparty/lua/src/lcorolib.c b/3rdparty/lua/src/lcorolib.c
index ce4f6ad42c6..0c0b7fa6b31 100644
--- a/3rdparty/lua/src/lcorolib.c
+++ b/3rdparty/lua/src/lcorolib.c
@@ -1,15 +1,16 @@
/*
-** $Id: lcorolib.c,v 1.5.1.1 2013/04/12 18:48:47 roberto Exp $
+** $Id: lcorolib.c,v 1.9 2014/11/02 19:19:04 roberto Exp $
** Coroutine Library
** See Copyright Notice in lua.h
*/
+#define lcorolib_c
+#define LUA_LIB
-#include <stdlib.h>
+#include "lprefix.h"
-#define lcorolib_c
-#define LUA_LIB
+#include <stdlib.h>
#include "lua.h"
@@ -17,6 +18,13 @@
#include "lualib.h"
+static lua_State *getco (lua_State *L) {
+ lua_State *co = lua_tothread(L, 1);
+ luaL_argcheck(L, co, 1, "thread expected");
+ return co;
+}
+
+
static int auxresume (lua_State *L, lua_State *co, int narg) {
int status;
if (!lua_checkstack(co, narg)) {
@@ -47,9 +55,8 @@ static int auxresume (lua_State *L, lua_State *co, int narg) {
static int luaB_coresume (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
+ lua_State *co = getco(L);
int r;
- luaL_argcheck(L, co, 1, "coroutine expected");
r = auxresume(L, co, lua_gettop(L) - 1);
if (r < 0) {
lua_pushboolean(L, 0);
@@ -59,7 +66,7 @@ static int luaB_coresume (lua_State *L) {
else {
lua_pushboolean(L, 1);
lua_insert(L, -(r + 1));
- return r + 1; /* return true + `resume' returns */
+ return r + 1; /* return true + 'resume' returns */
}
}
@@ -102,8 +109,7 @@ static int luaB_yield (lua_State *L) {
static int luaB_costatus (lua_State *L) {
- lua_State *co = lua_tothread(L, 1);
- luaL_argcheck(L, co, 1, "coroutine expected");
+ lua_State *co = getco(L);
if (L == co) lua_pushliteral(L, "running");
else {
switch (lua_status(co)) {
@@ -129,6 +135,12 @@ static int luaB_costatus (lua_State *L) {
}
+static int luaB_yieldable (lua_State *L) {
+ lua_pushboolean(L, lua_isyieldable(L));
+ return 1;
+}
+
+
static int luaB_corunning (lua_State *L) {
int ismain = lua_pushthread(L);
lua_pushboolean(L, ismain);
@@ -143,6 +155,7 @@ static const luaL_Reg co_funcs[] = {
{"status", luaB_costatus},
{"wrap", luaB_cowrap},
{"yield", luaB_yield},
+ {"isyieldable", luaB_yieldable},
{NULL, NULL}
};