diff options
author | Emil Renner Berthing <esmil@mailme.dk> | 2012-01-21 02:55:54 +0100 |
---|---|---|
committer | Emil Renner Berthing <esmil@mailme.dk> | 2012-01-25 21:13:57 +0100 |
commit | af5cac680c661bf424a55337ae8ce9fcf0d5e9aa (patch) | |
tree | b5837478c8fe20eecb28cd85a36361429c188c62 | |
parent | 2d10ba7a64a4cc0a0928757a8d58c25f08408fa4 (diff) | |
download | lem-af5cac680c661bf424a55337ae8ce9fcf0d5e9aa.tar.gz lem-af5cac680c661bf424a55337ae8ce9fcf0d5e9aa.tar.xz lem-af5cac680c661bf424a55337ae8ce9fcf0d5e9aa.zip |
utils: add thisthread, suspend and resume
-rw-r--r-- | utils.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -238,6 +238,35 @@ exit_lua(lua_State *T) return 0; } +static int +thisthread(lua_State *T) +{ + lua_pushthread(T); + return 1; +} + +static int +suspend(lua_State *T) +{ + return lua_yield(T, 0); +} + +static int +resume(lua_State *T) +{ + int args; + lua_State *S; + + luaL_checktype(T, 1, LUA_TTHREAD); + S = lua_tothread(T, 1); + + args = lua_gettop(T) - 1; + lua_xmove(T, S, args); + lem_queue(S, args); + + return 0; +} + int luaopen_lem_utils(lua_State *L) { @@ -288,5 +317,15 @@ luaopen_lem_utils(lua_State *L) lua_pushcfunction(L, exit_lua); lua_setfield(L, -2, "exit"); + /* set thisthread function */ + lua_pushcfunction(L, thisthread); + lua_setfield(L, -2, "thisthread"); + /* set suspend function */ + lua_pushcfunction(L, suspend); + lua_setfield(L, -2, "suspend"); + /* set resume function */ + lua_pushcfunction(L, resume); + lua_setfield(L, -2, "resume"); + return 1; } |