Exemplo n.º 1
0
int w_BezierCurve_insertControlPoint(lua_State *L)
{
	BezierCurve *curve = luax_checkbeziercurve(L, 1);
	float vx = (float) luaL_checknumber(L, 2);
	float vy = (float) luaL_checknumber(L, 3);
	int idx = (int) luaL_optnumber(L, 4, -1);

	if (idx > 0) // 1-indexing
		idx--;

	luax_catchexcept(L, [&](){ curve->insertControlPoint(Vector(vx,vy), idx); });
	return 0;
}
Exemplo n.º 2
0
int w_ChainShape_setPreviousVertex(lua_State *L)
{
	ChainShape *c = luax_checkchainshape(L, 1);
	if (lua_isnoneornil(L, 2))
		c->setPreviousVertex();
	else
	{
		float x = (float)luaL_checknumber(L, 2);
		float y = (float)luaL_checknumber(L, 3);
		luax_catchexcept(L, [&](){ c->setPreviousVertex(x, y); });
	}
	return 0;
}
Exemplo n.º 3
0
int w_BezierCurve_getSegment(lua_State *L)
{
	BezierCurve *curve = luax_checkbeziercurve(L, 1);
	double t1 = luaL_checknumber(L, 2);
	double t2 = luaL_checknumber(L, 3);

	BezierCurve *segment;
	luax_catchexcept(L, [&](){ segment = curve->getSegment(t1, t2); });
	luax_pushtype(L, MATH_BEZIER_CURVE_ID, segment);
	segment->release();

	return 1;
}
Exemplo n.º 4
0
int w_BezierCurve_evaluate(lua_State *L)
{
	BezierCurve *curve = luax_checkbeziercurve(L, 1);
	double t = luaL_checknumber(L, 2);

	luax_catchexcept(L, [&]() {
		Vector v = curve->evaluate(t);
		lua_pushnumber(L, v.x);
		lua_pushnumber(L, v.y);
	});

	return 2;

}
Exemplo n.º 5
0
int w_newCompressedData(lua_State *L)
{
	love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);

	CompressedImageData *t = nullptr;
	luax_catchexcept(L,
		[&]() { t = instance()->newCompressedData(data); },
		[&](bool) { data->release(); }
	);

	luax_pushtype(L, IMAGE_COMPRESSED_IMAGE_DATA_ID, t);
	t->release();
	return 1;
}
Exemplo n.º 6
0
int w_ImageData_getPixel(lua_State *L)
{
	ImageData *t = luax_checkimagedata(L, 1);
	int x = luaL_checkint(L, 2);
	int y = luaL_checkint(L, 3);
	pixel c;

	luax_catchexcept(L, [&](){ c = t->getPixel(x, y); });

	lua_pushnumber(L, c.r);
	lua_pushnumber(L, c.g);
	lua_pushnumber(L, c.b);
	lua_pushnumber(L, c.a);
	return 4;
}
Exemplo n.º 7
0
int w_Joint_getBodies(lua_State *L)
{
	Joint *t = luax_checkjoint(L, 1);
	Body *b1 = nullptr;
	Body *b2 = nullptr;

	luax_catchexcept(L, [&]() {
		b1 = t->getBodyA();
		b2 = t->getBodyB();
	});

	luax_pushtype(L, b1);
	luax_pushtype(L, b2);
	return 2;
}
Exemplo n.º 8
0
int w_Mesh_setDrawRange(lua_State *L)
{
	Mesh *t = luax_checkmesh(L, 1);

	if (lua_isnoneornil(L, 2))
		t->setDrawRange();
	else
	{
		int rangemin = luaL_checkint(L, 2) - 1;
		int rangemax = luaL_checkint(L, 3) - 1;
		luax_catchexcept(L, [&](){ t->setDrawRange(rangemin, rangemax); });
	}

	return 0;
}
Exemplo n.º 9
0
int w_BezierCurve_getControlPoint(lua_State *L)
{
	BezierCurve *curve = luax_checkbeziercurve(L, 1);
	int idx = (int) luaL_checknumber(L, 2);

	if (idx > 0) // 1-indexing
		idx--;

	luax_catchexcept(L, [&]() {
		Vector v = curve->getControlPoint(idx);
		lua_pushnumber(L, v.x);
		lua_pushnumber(L, v.y);
	});

	return 2;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
int w_Font_setFilter(lua_State *L)
{
	Font *t = luax_checkfont(L, 1);
	Texture::Filter f = t->getFilter();

	const char *minstr = luaL_checkstring(L, 2);
	const char *magstr = luaL_optstring(L, 3, minstr);

	if (!Texture::getConstant(minstr, f.min))
		return luaL_error(L, "Invalid filter mode: %s", minstr);
	if (!Texture::getConstant(magstr, f.mag))
		return luaL_error(L, "Invalid filter mode: %s", magstr);

	f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);

	luax_catchexcept(L, [&](){ t->setFilter(f); });
	return 0;
}
Exemplo n.º 12
0
int w_Mesh_getVertexMap(lua_State *L)
{
	Mesh *t = luax_checkmesh(L, 1);

	std::vector<uint32> vertex_map;
	luax_catchexcept(L, [&](){ t->getVertexMap(vertex_map); });

	size_t element_count = vertex_map.size();

	lua_createtable(L, element_count, 0);

	for (size_t i = 0; i < element_count; i++)
	{
		lua_pushinteger(L, lua_Integer(vertex_map[i]) + 1);
		lua_rawseti(L, -2, i + 1);
	}

	return 1;
}
Exemplo n.º 13
0
extern "C" int luaopen_love_thread(lua_State *L)
{
	ThreadModule *instance = instance();
	if (instance == nullptr)
	{
		luax_catchexcept(L, [&](){ instance = new love::thread::ThreadModule(); });
	}
	else
		instance->retain();

	WrappedModule w;
	w.module = instance;
	w.name = "thread";
	w.type = &Module::type;
	w.functions = module_functions;
	w.types = types;

	return luax_register_module(L, w);
}
Exemplo n.º 14
0
int w_Mesh_getVertex(lua_State *L)
{
	Mesh *t = luax_checkmesh(L, 1);
	size_t i = (size_t) (luaL_checkinteger(L, 2) - 1);

	Vertex v;
	luax_catchexcept(L, [&](){ v = t->getVertex(i); });

	lua_pushnumber(L, v.x);
	lua_pushnumber(L, v.y);
	lua_pushnumber(L, v.s);
	lua_pushnumber(L, v.t);
	lua_pushnumber(L, v.r);
	lua_pushnumber(L, v.g);
	lua_pushnumber(L, v.b);
	lua_pushnumber(L, v.a);

	return 8;
}
Exemplo n.º 15
0
extern "C" int luaopen_love_keyboard(lua_State *L)
{
	Keyboard *instance = instance();
	if (instance == nullptr)
	{
		luax_catchexcept(L, [&](){ instance = new love::keyboard::sdl::Keyboard(); });
	}
	else
		instance->retain();

	WrappedModule w;
	w.module = instance;
	w.name = "keyboard";
	w.type = MODULE_ID;
	w.functions = functions;
	w.types = 0;

	return luax_register_module(L, w);
}
Exemplo n.º 16
0
extern "C" int luaopen_love_image(lua_State *L)
{
	Image *instance = instance();
	if (instance == nullptr)
	{
		luax_catchexcept(L, [&](){ instance = new love::image::magpie::Image(); });
	}
	else
		instance->retain();

	WrappedModule w;
	w.module = instance;
	w.name = "image";
	w.type = MODULE_IMAGE_ID;
	w.functions = functions;
	w.types = types;

	return luax_register_module(L, w);
}
Exemplo n.º 17
0
int w_BezierCurve_render(lua_State *L)
{
	BezierCurve *curve = luax_checkbeziercurve(L, 1);
	int accuracy = (int) luaL_optnumber(L, 2, 5);

	std::vector<Vector> points;
	luax_catchexcept(L, [&](){ points = curve->render(accuracy); });

	lua_createtable(L, (int) points.size() * 2, 0);
	for (int i = 0; i < (int) points.size(); ++i)
	{
		lua_pushnumber(L, points[i].x);
		lua_rawseti(L, -2, 2*i+1);
		lua_pushnumber(L, points[i].y);
		lua_rawseti(L, -2, 2*i+2);
	}

	return 1;
}
Exemplo n.º 18
0
int w_Image_setMipmapFilter(lua_State *L)
{
	Image *t = luax_checkimage(L, 1);
	Texture::Filter f = t->getFilter();

	if (lua_isnoneornil(L, 2))
		f.mipmap = Texture::FILTER_NONE; // mipmapping is disabled if no argument is given
	else
	{
		const char *mipmapstr = luaL_checkstring(L, 2);
		if (!Texture::getConstant(mipmapstr, f.mipmap))
			return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
	}

	luax_catchexcept(L, [&](){ t->setFilter(f); });
	t->setMipmapSharpness((float) luaL_optnumber(L, 3, 0.0));

	return 0;
}
Exemplo n.º 19
0
extern "C" int luaopen_love_font(lua_State *L)
{
	Font *instance = instance();
	if (instance == nullptr)
	{
		luax_catchexcept(L, [&](){ instance = new freetype::Font(); });
	}
	else
		instance->retain();

	WrappedModule w;
	w.module = instance;
	w.name = "font";
	w.type = MODULE_ID;
	w.functions = functions;
	w.types = types;

	return luax_register_module(L, w);
}
Exemplo n.º 20
0
int w_newBMFontRasterizer(lua_State *L)
{
	Rasterizer *t = nullptr;

	filesystem::FileData *d = filesystem::luax_getfiledata(L, 1);
	std::vector<image::ImageData *> images;

	if (lua_istable(L, 2))
	{
		for (int i = 1; i <= (int) luax_objlen(L, 2); i++)
		{
			lua_rawgeti(L, 2, i);

			convimagedata(L, -1);
			image::ImageData *id = luax_checktype<image::ImageData>(L, -1, IMAGE_IMAGE_DATA_ID);
			images.push_back(id);
			id->retain();

			lua_pop(L, 1);
		}
	}
	else
	{
		for (int i = 2; i <= lua_gettop(L); i++)
		{
			convimagedata(L, i);
			image::ImageData *id = luax_checktype<image::ImageData>(L, i, IMAGE_IMAGE_DATA_ID);
			images.push_back(id);
			id->retain();
		}
	}

	luax_catchexcept(L,
		[&]() { t = instance()->newBMFontRasterizer(d, images); },
		[&](bool) { d->release(); for (auto id : images) id->release(); }
	);

	luax_pushtype(L, FONT_RASTERIZER_ID, t);
	t->release();
	return 1;
}
Exemplo n.º 21
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;
}
Exemplo n.º 22
0
int w_BezierCurve_renderSegment(lua_State *L)
{
	BezierCurve *curve = luax_checkbeziercurve(L, 1);
	double start = luaL_checknumber(L, 2);
	double end = luaL_checknumber(L, 3);
	int accuracy = luaL_optinteger(L, 4, 5);

	std::vector<Vector> points;
	luax_catchexcept(L, [&](){ points = curve->renderSegment(start, end, accuracy); });

	lua_createtable(L, points.size()*2, 0);
	for (size_t i = 0; i < points.size(); ++i)
	{
		lua_pushnumber(L, points[i].x);
		lua_rawseti(L, -2, 2*i+1);
		lua_pushnumber(L, points[i].y);
		lua_rawseti(L, -2, 2*i+2);
	}

	return 1;
}
Exemplo n.º 23
0
int w_File_lines(lua_State *L)
{
	File *file = luax_checkfile(L, 1);

	lua_pushnumber(L, 0); // File position.
	luax_pushboolean(L, file->getMode() != File::MODE_CLOSED); // Save current file mode.

	if (file->getMode() != File::MODE_READ)
	{
		if (file->getMode() != File::MODE_CLOSED)
			file->close();

		bool success = false;
		luax_catchexcept(L, [&](){ success = file->open(File::MODE_READ); });

		if (!success)
			return luaL_error(L, "Could not open file.");
	}

	lua_pushcclosure(L, w_File_lines_i, 3);
	return 1;
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
int w_Mesh_setVertex(lua_State *L)
{
	Mesh *t = luax_checkmesh(L, 1);
	size_t i = size_t(luaL_checkinteger(L, 2) - 1);

	Vertex v;

	if (lua_istable(L, 3))
	{
		for (int i = 1; i <= 8; i++)
			lua_rawgeti(L, 3, i);

		v.x = luaL_checknumber(L, -8);
		v.y = luaL_checknumber(L, -7);
		v.s = luaL_optnumber(L, -6, 0.0);
		v.t = luaL_optnumber(L, -5, 0.0);
		v.r = luaL_optinteger(L, -4, 255);
		v.g = luaL_optinteger(L, -3, 255);
		v.b = luaL_optinteger(L, -2, 255);
		v.a = luaL_optinteger(L, -1, 255);

		lua_pop(L, 8);
	}
	else
	{
		v.x = luaL_checknumber(L, 3);
		v.y = luaL_checknumber(L, 4);
		v.s = luaL_optnumber(L, 5, 0.0);
		v.t = luaL_optnumber(L, 6, 0.0);
		v.r = luaL_optinteger(L,  7, 255);
		v.g = luaL_optinteger(L,  8, 255);
		v.b = luaL_optinteger(L,  9, 255);
		v.a = luaL_optinteger(L, 10, 255);
	}

	luax_catchexcept(L, [&](){ t->setVertex(i, v); });
	return 0;
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
0
extern "C" int luaopen_love_filesystem(lua_State *L)
{
	Filesystem *instance = instance();
	if (instance == nullptr)
	{
		luax_catchexcept(L, [&](){ instance = new physfs::Filesystem(); });
	}
	else
		instance->retain();

	// The love loaders should be tried after package.preload.
	love::luax_register_searcher(L, loader, 2);
	love::luax_register_searcher(L, extloader, 3);

	WrappedModule w;
	w.module = instance;
	w.name = "filesystem";
	w.type = MODULE_FILESYSTEM_ID;
	w.functions = functions;
	w.types = types;

	return luax_register_module(L, w);
}
Exemplo n.º 28
0
int w_Body_resetMassData(lua_State *L)
{
	Body *t = luax_checkbody(L, 1);
	luax_catchexcept(L, [&](){ t->resetMassData(); });
	return 0;
}
Exemplo n.º 29
0
int w_Body_destroy(lua_State *L)
{
	Body *t = luax_checkbody(L, 1);
	luax_catchexcept(L, [&](){ t->destroy(); });
	return 0;
}
Exemplo n.º 30
0
int w_Joint_destroy(lua_State *L)
{
	Joint *t = luax_checkjoint(L, 1);
	luax_catchexcept(L, [&](){ t->destroyJoint(); });
	return 0;
}