Difference between revisions of "love.textinput"
m |
m (→Notes) |
||
Line 13: | Line 13: | ||
== Notes == | == Notes == | ||
Although Lua strings can store UTF-8 encoded unicode text just fine, many functions in Lua's string library will not treat the text as you might expect. For example, <code>#text</code> (and <code>string.len(text)</code>) will give the number of ''bytes'' in the string, rather than the number of unicode characters. The [http://lua-users.org/wiki/LuaUnicode Lua wiki] and a [http://www.lua.org/wshop12/Ierusalimschy.pdf presentation by one of Lua's creators] give more in-depth explanations, with some tips. | Although Lua strings can store UTF-8 encoded unicode text just fine, many functions in Lua's string library will not treat the text as you might expect. For example, <code>#text</code> (and <code>string.len(text)</code>) will give the number of ''bytes'' in the string, rather than the number of unicode characters. The [http://lua-users.org/wiki/LuaUnicode Lua wiki] and a [http://www.lua.org/wshop12/Ierusalimschy.pdf presentation by one of Lua's creators] give more in-depth explanations, with some tips. | ||
+ | |||
+ | The [[utf8]] library can be used to handle UTF-8 encoded unicode text. | ||
== Examples == | == Examples == |
Revision as of 04:25, 12 March 2015
Available since LÖVE 0.9.0 |
This function is not supported in earlier versions. |
Called when text has been entered by the user. For example if shift-2 is pressed on an American keyboard layout, the text "@" will be generated.
Contents
Function
Synopsis
love.textinput( text )
Arguments
string text
- The UTF-8 encoded unicode text.
Returns
Nothing.
Notes
Although Lua strings can store UTF-8 encoded unicode text just fine, many functions in Lua's string library will not treat the text as you might expect. For example, #text
(and string.len(text)
) will give the number of bytes in the string, rather than the number of unicode characters. The Lua wiki and a presentation by one of Lua's creators give more in-depth explanations, with some tips.
The utf8 library can be used to handle UTF-8 encoded unicode text.
Examples
Record and print text the user writes.
function love.load()
text = "Type away! -- "
end
function love.textinput(t)
text = text .. t
end
function love.draw()
love.graphics.printf(text, 0, 0, love.graphics.getWidth())
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info