|
@@ -28,99 +28,99 @@ namespace love
|
|
{
|
|
{
|
|
namespace thread
|
|
namespace thread
|
|
{
|
|
{
|
|
- static ThreadModule *instance = 0;
|
|
|
|
|
|
+static ThreadModule *instance = 0;
|
|
|
|
|
|
- int w_newThread(lua_State *L)
|
|
|
|
|
|
+int w_newThread(lua_State *L)
|
|
|
|
+{
|
|
|
|
+ std::string name = "Thread code";
|
|
|
|
+ love::Data *data;
|
|
|
|
+ if (lua_isstring(L, 1))
|
|
|
|
+ luax_convobj(L, 1, "filesystem", "newFile");
|
|
|
|
+ if (luax_istype(L, 1, FILESYSTEM_FILE_T))
|
|
{
|
|
{
|
|
- std::string name = "Thread code";
|
|
|
|
- love::Data *data;
|
|
|
|
- if (lua_isstring(L, 1))
|
|
|
|
- luax_convobj(L, 1, "filesystem", "newFile");
|
|
|
|
- if (luax_istype(L, 1, FILESYSTEM_FILE_T))
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
|
|
|
- name = std::string("@") + file->getFilename();
|
|
|
|
- data = file->read();
|
|
|
|
- }
|
|
|
|
- catch (love::Exception & e)
|
|
|
|
- {
|
|
|
|
- return luaL_error(L, "%s", e.what());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else if (luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- love::filesystem::FileData * fdata = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
|
|
|
|
- name = std::string("@") + fdata->getFilename();
|
|
|
|
- data = fdata;
|
|
|
|
- data->retain();
|
|
|
|
|
|
+ love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
|
|
|
|
+ name = std::string("@") + file->getFilename();
|
|
|
|
+ data = file->read();
|
|
}
|
|
}
|
|
- else
|
|
|
|
|
|
+ catch (love::Exception & e)
|
|
{
|
|
{
|
|
- data = luax_checktype<love::Data>(L, 1, "Data", DATA_T);
|
|
|
|
- data->retain();
|
|
|
|
|
|
+ return luaL_error(L, "%s", e.what());
|
|
}
|
|
}
|
|
- LuaThread *t = instance->newThread(name, data);
|
|
|
|
- // do not worry, file->read() returns retained data
|
|
|
|
- data->release();
|
|
|
|
- luax_newtype(L, "Thread", THREAD_THREAD_T, (void*)t);
|
|
|
|
- return 1;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
- int w_newChannel(lua_State *L)
|
|
|
|
|
|
+ else if (luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
|
{
|
|
{
|
|
- Channel *c = instance->newChannel();
|
|
|
|
- luax_newtype(L, "Channel", THREAD_CHANNEL_T, (void*)c);
|
|
|
|
- return 1;
|
|
|
|
|
|
+ love::filesystem::FileData * fdata = luax_checktype<love::filesystem::FileData>(L, 1, "FileData", FILESYSTEM_FILE_DATA_T);
|
|
|
|
+ name = std::string("@") + fdata->getFilename();
|
|
|
|
+ data = fdata;
|
|
|
|
+ data->retain();
|
|
}
|
|
}
|
|
-
|
|
|
|
- int w_getChannel(lua_State *L)
|
|
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- std::string name = luax_checkstring(L, 1);
|
|
|
|
- Channel *c = instance->getChannel(name);
|
|
|
|
- luax_newtype(L, "Channel", THREAD_CHANNEL_T, (void*)c);
|
|
|
|
- return 1;
|
|
|
|
|
|
+ data = luax_checktype<love::Data>(L, 1, "Data", DATA_T);
|
|
|
|
+ data->retain();
|
|
}
|
|
}
|
|
|
|
+ LuaThread *t = instance->newThread(name, data);
|
|
|
|
+ // do not worry, file->read() returns retained data
|
|
|
|
+ data->release();
|
|
|
|
+ luax_newtype(L, "Thread", THREAD_THREAD_T, (void *)t);
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int w_newChannel(lua_State *L)
|
|
|
|
+{
|
|
|
|
+ Channel *c = instance->newChannel();
|
|
|
|
+ luax_newtype(L, "Channel", THREAD_CHANNEL_T, (void *)c);
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
|
|
- // List of functions to wrap.
|
|
|
|
- static const luaL_Reg module_functions[] = {
|
|
|
|
- { "newThread", w_newThread },
|
|
|
|
- { "newChannel", w_newChannel },
|
|
|
|
- { "getChannel", w_getChannel },
|
|
|
|
- { 0, 0 }
|
|
|
|
- };
|
|
|
|
|
|
+int w_getChannel(lua_State *L)
|
|
|
|
+{
|
|
|
|
+ std::string name = luax_checkstring(L, 1);
|
|
|
|
+ Channel *c = instance->getChannel(name);
|
|
|
|
+ luax_newtype(L, "Channel", THREAD_CHANNEL_T, (void *)c);
|
|
|
|
+ return 1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// List of functions to wrap.
|
|
|
|
+static const luaL_Reg module_functions[] = {
|
|
|
|
+ { "newThread", w_newThread },
|
|
|
|
+ { "newChannel", w_newChannel },
|
|
|
|
+ { "getChannel", w_getChannel },
|
|
|
|
+ { 0, 0 }
|
|
|
|
+};
|
|
|
|
|
|
- static const lua_CFunction types[] = {
|
|
|
|
- luaopen_thread,
|
|
|
|
- luaopen_channel,
|
|
|
|
- 0
|
|
|
|
- };
|
|
|
|
|
|
+static const lua_CFunction types[] = {
|
|
|
|
+ luaopen_thread,
|
|
|
|
+ luaopen_channel,
|
|
|
|
+ 0
|
|
|
|
+};
|
|
|
|
|
|
- extern "C" int luaopen_love_thread(lua_State *L)
|
|
|
|
|
|
+extern "C" int luaopen_love_thread(lua_State *L)
|
|
|
|
+{
|
|
|
|
+ if (instance == 0)
|
|
{
|
|
{
|
|
- if (instance == 0)
|
|
|
|
|
|
+ try
|
|
{
|
|
{
|
|
- try
|
|
|
|
- {
|
|
|
|
- instance = new ThreadModule();
|
|
|
|
- }
|
|
|
|
- catch (Exception & e)
|
|
|
|
- {
|
|
|
|
- return luaL_error(L, "%s", e.what());
|
|
|
|
- }
|
|
|
|
|
|
+ instance = new ThreadModule();
|
|
}
|
|
}
|
|
- else
|
|
|
|
- instance->retain();
|
|
|
|
|
|
+ catch (Exception & e)
|
|
|
|
+ {
|
|
|
|
+ return luaL_error(L, "%s", e.what());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ instance->retain();
|
|
|
|
|
|
- WrappedModule w;
|
|
|
|
- w.module = instance;
|
|
|
|
- w.name = "thread";
|
|
|
|
- w.flags = MODULE_T;
|
|
|
|
- w.functions = module_functions;
|
|
|
|
- w.types = types;
|
|
|
|
|
|
+ WrappedModule w;
|
|
|
|
+ w.module = instance;
|
|
|
|
+ w.name = "thread";
|
|
|
|
+ w.flags = MODULE_T;
|
|
|
|
+ w.functions = module_functions;
|
|
|
|
+ w.types = types;
|
|
|
|
|
|
- return luax_register_module(L, w);
|
|
|
|
- }
|
|
|
|
|
|
+ return luax_register_module(L, w);
|
|
|
|
+}
|
|
}
|
|
}
|
|
}
|
|
}
|