Commits

Alex Szpakowski  committed b427e17

Fixed love.graphics.print[f] truncating strings with embedded zeros

  • Participants
  • Parent commits 1b28563

Comments (0)

Files changed (3)

File src/modules/graphics/opengl/Graphics.cpp

 	return (int)max;
 }
 
-void Graphics::print(const char *str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
+void Graphics::print(const std::string &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
 	if (currentFont != 0)
-	{
-		std::string text(str);
-		currentFont->print(text, x, y, 0.0, angle, sx, sy, ox, oy, kx, ky);
-	}
+		currentFont->print(str, x, y, 0.0, angle, sx, sy, ox, oy, kx, ky);
 }
 
-void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
+void Graphics::printf(const std::string &str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
 	if (currentFont == 0)
 		return;
 	using std::string;
 	using std::vector;
 
-	string text(str);
-	vector<string> lines_to_draw = currentFont->getWrap(text, wrap);
+	vector<string> lines_to_draw = currentFont->getWrap(str, wrap);
 
 	glPushMatrix();
 

File src/modules/graphics/opengl/Graphics.h

 	 * @param kx Shear along the x-axis.
 	 * @param ky Shear along the y-axis.
 	 **/
-	void print(const char *str, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
+	void print(const std::string &str, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
 
 	/**
 	 * Draw formatted text on screen at the specified coordinates.
 	 * @param kx Shear along the x-axis.
 	 * @param ky Shear along the y-axis.
 	 **/
-	void printf(const char *str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
+	void printf(const std::string &str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
 
 	/**
 	 * Draws a point at (x,y).

File src/modules/graphics/opengl/wrap_Graphics.cpp

 
 int w_print(lua_State *L)
 {
-	const char *str = luaL_checkstring(L, 1);
+	std::string str = luax_checkstring(L, 1);
 	float x = (float)luaL_checknumber(L, 2);
 	float y = (float)luaL_checknumber(L, 3);
 	float angle = (float)luaL_optnumber(L, 4, 0.0f);
 
 int w_printf(lua_State *L)
 {
-	const char *str = luaL_checkstring(L, 1);
+	std::string str = luax_checkstring(L, 1);
 	float x = (float)luaL_checknumber(L, 2);
 	float y = (float)luaL_checknumber(L, 3);
 	float wrap = (float)luaL_checknumber(L, 4);