Difference between revisions of "Tostring"

From ComputerCraft Wiki
Jump to: navigation, search
(os.toString)
 
(Changing int to number)
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The  ToString function is very common function through out programming languages. The use of this function is just to
+
{{lowercase}}
take an integer and turn it into a string. The opposite of this function is ToInteger.'
+
{{Function
 +
|name=tostring
 +
|args=Object o
 +
|returns={{type|string}} representation of the Object <var>o</var>
 +
|api=
 +
|addon=ComputerCraft
 +
|desc=Converts any passed object to it's string-representation.
 +
|examples=
 +
{{Example
 +
|desc=Convert an {{type|number}} to a {{type|string}}
 +
|code=local a = tostring(1)
 +
|output= a = "1" ({{type|string}})
 +
}}
 +
{{Example
 +
|desc=Convert a {{type|number}} to a {{type|string}}
 +
|code=local b = tostring(3.1415)
 +
|output= b = "3.1415" ({{type|string}})
 +
}}
 +
}}
  
Example Use: A Lua Clock
 
  
time = os.getTime()
+
[[Category:Lua_Core_Functions]]
TimeString = os.toString(time)
+
 
+
print(time)
+
 
+
Corrections and critism accepted!!
+

Latest revision as of 12:54, 18 July 2013


Grid Redstone.png  Function tostring
Converts any passed object to it's string-representation.
Syntax tostring(Object o)
Returns string representation of the Object o
Part of ComputerCraft
API none

Examples

Grid paper.png  Example
Convert an number to a string
Code
local a = tostring(1)
Output a = "1" (string)



Grid paper.png  Example
Convert a number to a string
Code
local b = tostring(3.1415)
Output b = "3.1415" (string)