comparison src/modules/thread/wrap_LuaThread.cpp @ 1098:a74672ba1320 minor

Merge in channels from love-experiments Rewritten love.thread and changed communication method from weird system before, to channels.
author Bart van Strien <bart.bes+projects@gmail.com>
date Wed, 04 Jul 2012 17:15:16 +0200
parents
children
comparison
equal deleted inserted replaced
1097:4819322d9cdc 1098:a74672ba1320
1 /**
2 * Copyright (c) 2006-2010 LOVE Development Team
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 * 3. This notice may not be removed or altered from any source distribution.
19 **/
20
21 #include "wrap_LuaThread.h"
22
23 namespace love
24 {
25 namespace thread
26 {
27
28 LuaThread *luax_checkthread(lua_State *L, int idx)
29 {
30 return luax_checktype<LuaThread>(L, idx, "Thread", THREAD_THREAD_T);
31 }
32
33 int w_Thread_start(lua_State *L)
34 {
35 LuaThread *t = luax_checkthread(L, 1);
36 luax_pushboolean(L, t->start());
37 return 1;
38 }
39
40 int w_Thread_wait(lua_State *L)
41 {
42 LuaThread *t = luax_checkthread(L, 1);
43 t->wait();
44 return 0;
45 }
46
47 int w_Thread_getError(lua_State *L)
48 {
49 LuaThread *t = luax_checkthread(L, 1);
50 std::string err = t->getError();
51 if (err.length() == 0)
52 lua_pushnil(L);
53 else
54 luax_pushstring(L, err);
55 return 1;
56 }
57
58 static const luaL_Reg type_functions[] = {
59 { "start", w_Thread_start },
60 { "wait", w_Thread_wait },
61 { "getError", w_Thread_getError },
62 { 0, 0 }
63 };
64
65 extern "C" int luaopen_thread(lua_State *L)
66 {
67 return luax_register_type(L, "Thread", type_functions);
68 }
69
70 } // thread
71 } // love