Issues

Issue #427 wontfix

love.graphics.print(text, ...) should use tostring() on text argument

pkmays avatarpkmays created an issue

Filed against LOVE 0.8.0

The function love.graphics.print() serves a similar purpose to Lua's built-in print() function. However LOVE's printing behavior is surprising in that it does not automatically convert nil, booleans, functions, tables, etc., to strings.

The following code will print values to the console without error:

function love.load()
	null = nil
	bool = true
	num = 3.14159
	str = "hello, world"
	func = function() end
	tbl = {}

	print(null)
	print(true)
	print(num)
	print(str)
	print(func)
	print(tbl)
end

Whereas the following code requires tostring() coercion to print without errors:

-- snip!

function love.draw()
	love.graphics.print(tostring(null), 100, 100)
	love.graphics.print(tostring(true), 100, 115)
	love.graphics.print(num, 100, 130)
	love.graphics.print(str, 100, 145)
	love.graphics.print(tostring(func), 100, 160)
	love.graphics.print(tostring(tbl), 100, 175)
end

It would be useful--especially during building and debugging a project--if LOVE's print function followed Lua's printing idioms regarding basic types, rather than generate errors.

Comments (6)

  1. Bart van Strien

    I'd like to note that love.graphics.print is in no way meant to serve "a similar purpose to Lua's built-in print() function". It is meant to put text on the screen.

  2. pkmays

    I do realize that while print() and love.graphics.print() aren't mathematically equivalent, they are biologically isomorphic.

    One defines the universal string output of a table, boolean or function as tostring(table, boolean or function).

  3. Bart van Strien

    Lua's print is sufficiently different from the rest of lua in how it does that, io.write doesn't do anything like it, for instance. In fact, the lua API doesn't even have an easy way of doing this. I'm still not convinced there's a good reason to handle this.

  4. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.