Пример #1
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;
}
Пример #2
0
	int w_newThread(lua_State *L)
	{
		std::string name = luax_checkstring(L, 1);
		love::Data *data;
		if (lua_isstring(L, 2))
			luax_convobj(L, 2, "filesystem", "newFile");
		if (luax_istype(L, 2, FILESYSTEM_FILE_T))
		{
			try
			{
				data = luax_checktype<love::filesystem::File>(L, 2, "File", FILESYSTEM_FILE_T)->read();
			}
			catch (love::Exception & e)
			{
				return luaL_error(L, e.what());
			}
		}
		else
		{
			data = luax_checktype<love::Data>(L, 2, "Data", DATA_T);
			data->retain();
		}
		Thread *t = instance->newThread(name, data);
		// do not worry, file->read() returns retained data
		data->release();
		if (!t)
			return luaL_error(L, "A thread with that name already exists.");
		luax_newtype(L, "Thread", THREAD_THREAD_T, (void*)t);
		return 1;
	}
Пример #3
0
int w_getChannel(lua_State *L)
{
	std::string name = luax_checkstring(L, 1);
	Channel *c = instance()->getChannel(name);
	luax_pushtype(L, c);
	c->release();
	return 1;
}
Пример #4
0
	int w_Thread_set(lua_State *L)
	{
		Thread *t = luax_checkthread(L, 1);
		std::string name = luax_checkstring(L, 2);
		Variant *v = Variant::fromLua(L, 3);
		if (!v)
			return luaL_error(L, "Expected boolean, number, string or userdata");
		t->set(name, v);
		t->lock();
		v->release();
		t->unlock();
		return 0;
	}
Пример #5
0
int w_setRequirePath(lua_State *L)
{
	std::string element = luax_checkstring(L, 1);
	auto &requirePath = instance()->getRequirePath();

	requirePath.clear();
	std::stringstream path;
	path << element;

	while(std::getline(path, element, ';'))
		requirePath.push_back(element);

	return 0;
}
Пример #6
0
int w_newImageRasterizer(lua_State *L)
{
	Rasterizer *t = nullptr;

	convimagedata(L, 1);

	image::ImageData *d = luax_checktype<image::ImageData>(L, 1, IMAGE_IMAGE_DATA_ID);
	std::string glyphs = luax_checkstring(L, 2);
	int extraspacing = (int) luaL_optnumber(L, 3, 0);

	luax_catchexcept(L, [&](){ t = instance()->newImageRasterizer(d, glyphs, extraspacing); });

	luax_pushtype(L, FONT_RASTERIZER_ID, t);
	t->release();
	return 1;
}
Пример #7
0
	int w_Thread_peek(lua_State *L)
	{
		Thread *t = luax_checkthread(L, 1);
		std::string name = luax_checkstring(L, 2);
		t->lock();
		Variant *v = t->get(name);
		t->unlock();
		if (!v)
		{
			lua_pushnil(L);
			return 1;
		}
		v->toLua(L);
		t->lock();
		v->release();
		t->unlock();
		return 1;
	}
Пример #8
0
	Message *Message::fromLua(lua_State *L, int n)
	{
		std::string name = luax_checkstring(L, n);
		n++;
		Message *m = new Message(name);
		for (int i = 0; i < 4; i++)
		{
			if (lua_isnoneornil(L, n+i))
				break;
			m->args[i] = Variant::fromLua(L, n+i);
			if (!m->args[i])
			{
				delete m;
				luaL_error(L, "Argument %d can't be stored safely\nExpected boolean, number, string or userdata.", n+i);
				return NULL;
			}
			m->nargs++;
		}
		return m;
	}
Пример #9
0
int w_newGlyphData(lua_State *L)
{
	Rasterizer *r = luax_checkrasterizer(L, 1);
	GlyphData *t = nullptr;

	// newGlyphData accepts a unicode character or a codepoint number.
	if (lua_type(L, 2) == LUA_TSTRING)
	{
		std::string glyph = luax_checkstring(L, 2);
		luax_catchexcept(L, [&](){ t = instance()->newGlyphData(r, glyph); });
	}
	else
	{
		uint32 g = (uint32) luaL_checknumber(L, 2);
		t = instance()->newGlyphData(r, g);
	}

	luax_pushtype(L, FONT_GLYPH_DATA_ID, t);
	t->release();
	return 1;
}
Пример #10
0
	int w_getThread(lua_State *L)
	{
		if (lua_isnoneornil(L, 1))
		{
			lua_getglobal(L, "love");
			lua_getfield(L, -1, "_curthread");
			return 1;
		}
		std::string name = luax_checkstring(L, 1);
		Thread *t = instance->getThread(name);
		if (t)
		{
			luax_newtype(L, "Thread", THREAD_THREAD_T, (void*)t);
			t->lock();
			t->retain();
			t->unlock();
		}
		else
			lua_pushnil(L);
		return 1;
	}
Пример #11
0
int w_Font_hasGlyphs(lua_State *L)
{
	Font *t = luax_checkfont(L, 1);
	bool hasglyph = false;

	int count = std::max(lua_gettop(L) - 1, 1);

	luax_catchexcept(L, [&]() {
		 for (int i = 2; i < count + 2; i++)
		 {
			 if (lua_type(L, i) == LUA_TSTRING)
				 hasglyph = t->hasGlyphs(luax_checkstring(L, i));
			 else
				 hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, i));

			 if (!hasglyph)
				 break;
		 }
	});

	luax_pushboolean(L, hasglyph);
	return 1;
}
Пример #12
0
int w_openURL(lua_State *L)
{
	std::string url = luax_checkstring(L, 1);
	luax_pushboolean(L, instance()->openURL(url));
	return 1;
}