static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int startidx, int index)
{
	Quad *quad = nullptr;

	if (luax_istype(L, startidx, GRAPHICS_QUAD_ID))
	{
		quad = luax_totype<Quad>(L, startidx, GRAPHICS_QUAD_ID);
		startidx++;
	}
	else if (lua_isnil(L, startidx) && !lua_isnoneornil(L, startidx + 1))
		return luax_typerror(L, startidx, "Quad");

	float x  = (float) luaL_optnumber(L, startidx + 0, 0.0);
	float y  = (float) luaL_optnumber(L, startidx + 1, 0.0);
	float a  = (float) luaL_optnumber(L, startidx + 2, 0.0);
	float sx = (float) luaL_optnumber(L, startidx + 3, 1.0);
	float sy = (float) luaL_optnumber(L, startidx + 4, sx);
	float ox = (float) luaL_optnumber(L, startidx + 5, 0.0);
	float oy = (float) luaL_optnumber(L, startidx + 6, 0.0);
	float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
	float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);

	luax_catchexcept(L, [&]() {
		if (quad)
			index = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, index);
		else
			index = t->add(x, y, a, sx, sy, ox, oy, kx, ky, index);
	});

	return index;
}
示例#2
0
int w_newSource(lua_State *L)
{
	if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_ID) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_ID))
		luax_convobj(L, 1, "sound", "newDecoder");

	Source::Type stype = Source::TYPE_STREAM;

	const char *stypestr = lua_isnoneornil(L, 2) ? 0 : lua_tostring(L, 2);
	if (stypestr && !Source::getConstant(stypestr, stype))
		return luaL_error(L, "Invalid source type: %s", stypestr);

	if (stype == Source::TYPE_STATIC && luax_istype(L, 1, SOUND_DECODER_ID))
		luax_convobj(L, 1, "sound", "newSoundData");

	Source *t = 0;

	luax_catchexcept(L, [&]() {
		if (luax_istype(L, 1, SOUND_SOUND_DATA_ID))
			t = instance()->newSource(luax_totype<love::sound::SoundData>(L, 1, SOUND_SOUND_DATA_ID));
		else if (luax_istype(L, 1, SOUND_DECODER_ID))
			t = instance()->newSource(luax_totype<love::sound::Decoder>(L, 1, SOUND_DECODER_ID));
	});

	if (t)
	{
		luax_pushtype(L, AUDIO_SOURCE_ID, t);
		t->release();
		return 1;
	}
	else
		return luax_typerror(L, 1, "Decoder or SoundData");
}
示例#3
0
int w_Mesh_setVertices(lua_State *L)
{
	Mesh *t = luax_checkmesh(L, 1);

	size_t vertex_count = lua_objlen(L, 2);
	std::vector<Vertex> vertices;
	vertices.reserve(vertex_count);

	// Get the vertices from the table.
	for (size_t i = 1; i <= vertex_count; i++)
	{
		lua_rawgeti(L, 2, i);

		if (lua_type(L, -1) != LUA_TTABLE)
			return luax_typerror(L, 2, "table of tables");

		for (int j = 1; j <= 8; j++)
			lua_rawgeti(L, -j, j);

		Vertex v;

		v.x = (float) luaL_checknumber(L, -8);
		v.y = (float) luaL_checknumber(L, -7);

		v.s = (float) luaL_optnumber(L, -6, 0.0);
		v.t = (float) luaL_optnumber(L, -5, 0.0);

		v.r = (unsigned char) luaL_optinteger(L, -4, 255);
		v.g = (unsigned char) luaL_optinteger(L, -3, 255);
		v.b = (unsigned char) luaL_optinteger(L, -2, 255);
		v.a = (unsigned char) luaL_optinteger(L, -1, 255);

		lua_pop(L, 9);
		vertices.push_back(v);
	}

	luax_catchexcept(L, [&](){ t->setVertices(vertices); });
	return 0;
}