1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-11 16:33:35 +00:00
lovr/src/api/l_thread.c

45 lines
1.1 KiB
C
Raw Normal View History

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);
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) {
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) {
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) {
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 },
{ "wait", l_lovrThreadWait },
{ "getError", l_lovrThreadGetError },
{ "isRunning", l_lovrThreadIsRunning },
2018-02-12 07:03:43 +00:00
{ NULL, NULL }
};