2018-02-12 07:03:43 +00:00
|
|
|
#include "api.h"
|
|
|
|
#include "thread/thread.h"
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrThreadStart(lua_State* L) {
|
2018-02-12 07:03:43 +00:00
|
|
|
Thread* thread = luax_checktype(L, 1, Thread);
|
2019-12-13 23:50:10 +00:00
|
|
|
Variant arguments[MAX_THREAD_ARGUMENTS];
|
|
|
|
size_t argumentCount = MIN(MAX_THREAD_ARGUMENTS, lua_gettop(L) - 1);
|
|
|
|
for (size_t i = 0; i < argumentCount; i++) {
|
|
|
|
luax_checkvariant(L, 2 + i, &arguments[i]);
|
|
|
|
}
|
|
|
|
lovrThreadStart(thread, arguments, argumentCount);
|
2018-02-12 07:03:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrThreadWait(lua_State* L) {
|
2018-02-13 05:30:00 +00:00
|
|
|
Thread* thread = luax_checktype(L, 1, Thread);
|
|
|
|
lovrThreadWait(thread);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrThreadGetError(lua_State* L) {
|
2018-02-13 05:30:00 +00:00
|
|
|
Thread* thread = luax_checktype(L, 1, Thread);
|
|
|
|
const char* error = lovrThreadGetError(thread);
|
|
|
|
if (error) {
|
|
|
|
lua_pushstring(L, error);
|
|
|
|
} else {
|
|
|
|
lua_pushnil(L);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-17 22:52:22 +00:00
|
|
|
static int l_lovrThreadIsRunning(lua_State* L) {
|
2018-02-13 05:30:00 +00:00
|
|
|
Thread* thread = luax_checktype(L, 1, Thread);
|
|
|
|
lua_pushboolean(L, thread->running);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-02-12 07:03:43 +00:00
|
|
|
const luaL_Reg lovrThread[] = {
|
|
|
|
{ "start", l_lovrThreadStart },
|
2018-02-13 05:30:00 +00:00
|
|
|
{ "wait", l_lovrThreadWait },
|
|
|
|
{ "getError", l_lovrThreadGetError },
|
|
|
|
{ "isRunning", l_lovrThreadIsRunning },
|
2018-02-12 07:03:43 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|