https://wiki.gideros.rocks/api.php?action=feedcontributions&user=John26&feedformat=atomGiderosMobile - User contributions [en-gb]2024-03-28T17:17:31ZUser contributionsMediaWiki 1.35.11https://wiki.gideros.rocks/index.php?title=The_Language&diff=13284The Language2019-06-26T14:54:19Z<p>John26: </p>
<hr />
<div>=== Assignments and Variables ===<br />
<br />
Lua is a dynamically-typed language, that is, variables don't have types, only the values. All values carry their own type. Consider the following as an example:<br />
<br />
<source lang="lua"><br />
MyTable = wide<br />
width = 3; height = 1.5<br />
area = width * height<br />
print (area)<br />
</source><br />
<br />
You can nest several lines using semicolons, but it’s optional and generally not a good programming habit as it decreases the readability of your code.Be careful not to use reserved words. Gideros Studio will complain when you use a reserved word in Lua. Consider this example:<br />
<br />
<source lang="lua"><br />
local = 1<br />
</source><br />
<br />
Since Lua is a small language, it only has 8 basic data types:<br />
<br />
# nil (null)<br />
# Booleans<br />
# Numbers<br />
# Strings<br />
# Functions<br />
# Userdata<br />
# Threads<br />
# Tables<br />
<br />
Global variables in Lua do not need to be declared. If you want to declare a variable, just assign a value to it. Giving it a nil value removes the variable. In fact, when a variable is removed, and it’s not referenced by another variable, it’s ready to be cleared up from memory, thanks to the wonderful Lua garbage collector.<br />
<br />
Lua can support multiple assignments. Check the following assignment:<br />
<br />
<source lang="lua"><br />
a, b, c = 1, 2, 3<br />
<br />
-- Easy method to swap two variables<br />
x, y = y, z <br />
<br />
-- Function can return multiple values<br />
n, m = calculate (phi, zeta) <br />
</source><br />
<br />
=== Control Structures ===<br />
<br />
Lua provides a strong control mechanism between different variable types. As an example for logical decisions, consider the following:<br />
<br />
{| class="wikitable"<br />
|-<br />
! Logical Decision !! Meaning<br />
|-<br />
| A and B || If A is true, then return the result of expression B.<br />
If A is false, then return A<br />
|-<br />
| A or B || If A is true, then return the result of expression A<br />
If A is false, then return B<br />
|}<br />
<br />
=== Arrays ===<br />
<br />
Arrays that can be indexed not only with numbers, but with any value. Arrays do not have to be defined a size, and they can grow as needed. When an array is defined, and you try to reach a value exceeding the boundary, you get a nil (instead of zero).<br />
<br />
Arrays can have any index, e.g you can start with an array with -5, 0 or 1 - it’s all up to you. Consider the following example:<br />
<br />
<source lang="lua"><br />
-- creates an array with indices from -2 to 2<br />
array = {}<br />
for i=-2, 2 do<br />
array[i] = "apples"<br />
end<br />
</source><br />
<br />
Lua also supports multi-dimensional arrays, which we call "matrices".<br />
<br />
Consider the following example. A similar array syntax can be used to create string lists. The statement below:<br />
<br />
<source lang="lua"><br />
animals = {"giraffe", "boar", "wolf", "frog"}<br />
</source><br />
<br />
is equal to: <br />
<br />
<source lang="lua"><br />
animals = {}<br />
animals[1] = "giraffe"; animals[2] = "boar"<br />
animals[3] = "wolf"; animals[4] = "frog"<br />
</source><br />
<br />
=== Lua Tables (arrays) ===<br />
<br />
In Lua, Tables and Arrays are terms so used interchangeably, However this is true to an extent.<br />
<br />
<br />
<br />
=== Basic Functions ===<br />
<br />
Lua has the ability to call its own functions or C functions, and it handles functions as a "data type". Note that functions can return multiple values, and you can use multiple assignments to collect these functions.<br />
<br />
<source lang="lua"><br />
function calculate(w, d, h)<br />
if h > 4 then<br />
print ("height of the room cannot be more than 4")<br />
return<br />
end<br />
volume = w * d * h<br />
return volume<br />
end<br />
<br />
-- Calculate the volume of the room<br />
print (calculate (4,3,4))<br />
</source><br />
<br />
Try the function above, this time with values 4,5,5.</div>John26https://wiki.gideros.rocks/index.php?title=Geolocation&diff=13283Geolocation2019-06-26T14:50:37Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:Geolocation --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform winrt.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2012.8<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
The [[Special:MyLanguage/Geolocation|Geolocation]] class is used to configure the parameters and dispatching of location and heading related events.<br /><br />
<br /></translate><br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">geolocation = Geolocation.new()<br />
<br />
local function onLocationUpdate(event)<br />
print("location: ", event.latitude, event.longitude, event.altitude)<br />
end<br />
<br />
local function onHeadingUpdate(event)<br />
print("heading: ", event.magneticHeading, event.trueHeading)<br />
end<br />
<br />
geolocation:addEventListener(Event.LOCATION_UPDATE, onLocationUpdate)<br />
geolocation:addEventListener(Event.HEADING_UPDATE, onHeadingUpdate)<br />
geolocation:start()</source><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/Geolocation.getAccuracy|Geolocation.getAccuracy]] ''<translate>returns the previously set desired accuracy</translate>''<br/><!-- GIDEROSMTD:Geolocation.getAccuracy() returns the previously set desired accuracy --><br />
[[Special:MyLanguage/Geolocation.getThreshold|Geolocation.getThreshold]] ''<translate>returns the previously set minimum distance threshold</translate>''<br/><!-- GIDEROSMTD:Geolocation.getThreshold() returns the previously set minimum distance threshold --><br />
[[Special:MyLanguage/Geolocation.isAvailable|Geolocation.isAvailable]] ''<translate>does this device have the capability to determine current location?</translate>''<br/><!-- GIDEROSMTD:Geolocation.isAvailable() does this device have the capability to determine current location? --><br />
[[Special:MyLanguage/Geolocation.isHeadingAvailable|Geolocation.isHeadingAvailable]] ''<translate>does this device have the capability to determine heading?</translate>''<br/><!-- GIDEROSMTD:Geolocation.isHeadingAvailable() does this device have the capability to determine heading? --><br />
[[Special:MyLanguage/Geolocation.new|Geolocation.new]] ''<translate>Creates new Geolocation instance</translate>''<br/><!-- GIDEROSMTD:Geolocation.new() Creates new Geolocation instance --><br />
[[Special:MyLanguage/Geolocation.setAccuracy|Geolocation.setAccuracy]] ''<translate>of the location data</translate>''<br/><!-- GIDEROSMTD:Geolocation.setAccuracy(accuracy) of the location data --><br />
[[Special:MyLanguage/Geolocation.setThreshold|Geolocation.setThreshold]] ''<translate>threshold</translate>''<br/><!-- GIDEROSMTD:Geolocation.setThreshold(threshold) threshold --><br />
[[Special:MyLanguage/Geolocation:start|Geolocation:start]] ''<translate>starts the generation of updates that report the current location and heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:start() starts the generation of updates that report the current location and heading --><br />
[[Special:MyLanguage/Geolocation:startUpdatingHeading|Geolocation:startUpdatingHeading]] ''<translate>starts the generation of updates that report the heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:startUpdatingHeading() starts the generation of updates that report the heading --><br />
[[Special:MyLanguage/Geolocation:startUpdatingLocation|Geolocation:startUpdatingLocation]] ''<translate>starts the generation of updates that report the current location</translate>''<br/><!-- GIDEROSMTD:Geolocation:startUpdatingLocation() starts the generation of updates that report the current location --><br />
[[Special:MyLanguage/Geolocation:stop|Geolocation:stop]] ''<translate>stops the generation of updates that report the current location and heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:stop() stops the generation of updates that report the current location and heading --><br />
[[Special:MyLanguage/Geolocation:stopUpdatingHeading|Geolocation:stopUpdatingHeading]] ''<translate>stops the generation of updates that report the heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:stopUpdatingHeading() stops the generation of updates that report the heading --><br />
[[Special:MyLanguage/Geolocation:stopUpdatingLocation|Geolocation:stopUpdatingLocation]] ''<translate>stops the generation of updates that report the current location</translate>''<br/><!-- GIDEROSMTD:Geolocation:stopUpdatingLocation() stops the generation of updates that report the current location --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
[[Special:MyLanguage/Event.ERROR|Event.ERROR]]<br/><!-- GIDEROSEVT:Event.ERROR error--><br />
[[Special:MyLanguage/Event.HEADING_UPDATE|Event.HEADING_UPDATE]]<br/><!-- GIDEROSEVT:Event.HEADING_UPDATE headingUpdate--><br />
[[Special:MyLanguage/Event.LOCATION_UPDATE|Event.LOCATION_UPDATE]]<br/><!-- GIDEROSEVT:Event.LOCATION_UPDATE locationUpdate--><br />
=== <translate>Constants</translate> ===<br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=Geolocation&diff=13282Geolocation2019-06-26T14:50:18Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:Geolocation --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform winrt.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2012.8<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
The [[Special:MyLanguage/Geolocation|Geolocation]] class is used to configure the parameters and dispatching of location and heading related events.<br /><br />
<br /></translate><br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">geolocation = Geolocation.new()<br />
<br />
local function onLocationUpdate(event)<br />
print("location: ", event.latitude, event.longitude, event.altitude)<br />
end<br />
<br />
local function onHeadingUpdate(event)<br />
print("heading: ";, event.magneticHeading, event.trueHeading)<br />
end<br />
<br />
geolocation:addEventListener(Event.LOCATION_UPDATE, onLocationUpdate)<br />
geolocation:addEventListener(Event.HEADING_UPDATE, onHeadingUpdate)<br />
geolocation:start()</source><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/Geolocation.getAccuracy|Geolocation.getAccuracy]] ''<translate>returns the previously set desired accuracy</translate>''<br/><!-- GIDEROSMTD:Geolocation.getAccuracy() returns the previously set desired accuracy --><br />
[[Special:MyLanguage/Geolocation.getThreshold|Geolocation.getThreshold]] ''<translate>returns the previously set minimum distance threshold</translate>''<br/><!-- GIDEROSMTD:Geolocation.getThreshold() returns the previously set minimum distance threshold --><br />
[[Special:MyLanguage/Geolocation.isAvailable|Geolocation.isAvailable]] ''<translate>does this device have the capability to determine current location?</translate>''<br/><!-- GIDEROSMTD:Geolocation.isAvailable() does this device have the capability to determine current location? --><br />
[[Special:MyLanguage/Geolocation.isHeadingAvailable|Geolocation.isHeadingAvailable]] ''<translate>does this device have the capability to determine heading?</translate>''<br/><!-- GIDEROSMTD:Geolocation.isHeadingAvailable() does this device have the capability to determine heading? --><br />
[[Special:MyLanguage/Geolocation.new|Geolocation.new]] ''<translate>Creates new Geolocation instance</translate>''<br/><!-- GIDEROSMTD:Geolocation.new() Creates new Geolocation instance --><br />
[[Special:MyLanguage/Geolocation.setAccuracy|Geolocation.setAccuracy]] ''<translate>of the location data</translate>''<br/><!-- GIDEROSMTD:Geolocation.setAccuracy(accuracy) of the location data --><br />
[[Special:MyLanguage/Geolocation.setThreshold|Geolocation.setThreshold]] ''<translate>threshold</translate>''<br/><!-- GIDEROSMTD:Geolocation.setThreshold(threshold) threshold --><br />
[[Special:MyLanguage/Geolocation:start|Geolocation:start]] ''<translate>starts the generation of updates that report the current location and heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:start() starts the generation of updates that report the current location and heading --><br />
[[Special:MyLanguage/Geolocation:startUpdatingHeading|Geolocation:startUpdatingHeading]] ''<translate>starts the generation of updates that report the heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:startUpdatingHeading() starts the generation of updates that report the heading --><br />
[[Special:MyLanguage/Geolocation:startUpdatingLocation|Geolocation:startUpdatingLocation]] ''<translate>starts the generation of updates that report the current location</translate>''<br/><!-- GIDEROSMTD:Geolocation:startUpdatingLocation() starts the generation of updates that report the current location --><br />
[[Special:MyLanguage/Geolocation:stop|Geolocation:stop]] ''<translate>stops the generation of updates that report the current location and heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:stop() stops the generation of updates that report the current location and heading --><br />
[[Special:MyLanguage/Geolocation:stopUpdatingHeading|Geolocation:stopUpdatingHeading]] ''<translate>stops the generation of updates that report the heading</translate>''<br/><!-- GIDEROSMTD:Geolocation:stopUpdatingHeading() stops the generation of updates that report the heading --><br />
[[Special:MyLanguage/Geolocation:stopUpdatingLocation|Geolocation:stopUpdatingLocation]] ''<translate>stops the generation of updates that report the current location</translate>''<br/><!-- GIDEROSMTD:Geolocation:stopUpdatingLocation() stops the generation of updates that report the current location --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
[[Special:MyLanguage/Event.ERROR|Event.ERROR]]<br/><!-- GIDEROSEVT:Event.ERROR error--><br />
[[Special:MyLanguage/Event.HEADING_UPDATE|Event.HEADING_UPDATE]]<br/><!-- GIDEROSEVT:Event.HEADING_UPDATE headingUpdate--><br />
[[Special:MyLanguage/Event.LOCATION_UPDATE|Event.LOCATION_UPDATE]]<br/><!-- GIDEROSEVT:Event.LOCATION_UPDATE locationUpdate--><br />
=== <translate>Constants</translate> ===<br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=Gyroscope&diff=13281Gyroscope2019-06-26T14:49:35Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:Gyroscope --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform winrt.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2012.8<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
The [[Special:MyLanguage/Gyroscope|Gyroscope]] class is used to access gyroscope data. <br /><br />
<br /></translate><br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">local gyroscope = Gyroscope.new()<br />
gyroscope:start()<br />
<br />
local angx = 0<br />
local angy = 0<br />
local angz = 0<br />
local function onEnterFrame(event)<br />
local x, y, z = gyroscope:getRotationRate()<br />
<br />
angx = angx x * event.deltaTime<br />
angy = angy y * event.deltaTime<br />
angz = angz z * event.deltaTime<br />
<br />
print(angx * 180 / math.pi, angy * 180 / math.pi, angz * 180 / math.pi)<br />
end<br />
<br />
stage:addEventListener("enterFrame")</source><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/Gyroscope.isAvailable|Gyroscope.isAvailable]] ''<translate>does the gyroscope available?</translate>''<br/><!-- GIDEROSMTD:Gyroscope.isAvailable() does the gyroscope available? --><br />
[[Special:MyLanguage/Gyroscope.new|Gyroscope.new]] ''<translate>Creates new Gyroscope instance</translate>''<br/><!-- GIDEROSMTD:Gyroscope.new() Creates new Gyroscope instance --><br />
[[Special:MyLanguage/Gyroscope:getRotationRate|Gyroscope:getRotationRate]] ''<translate>returns the rotation rate in radians per second</translate>''<br/><!-- GIDEROSMTD:Gyroscope:getRotationRate() returns the rotation rate in radians per second --><br />
[[Special:MyLanguage/Gyroscope:start|Gyroscope:start]] ''<translate>starts gyroscope updates</translate>''<br/><!-- GIDEROSMTD:Gyroscope:start() starts gyroscope updates --><br />
[[Special:MyLanguage/Gyroscope:stop|Gyroscope:stop]] ''<translate>stops gyroscope updates</translate>''<br/><!-- GIDEROSMTD:Gyroscope:stop() stops gyroscope updates --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
=== <translate>Constants</translate> ===<br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=TexturePack:getTextureRegion&diff=13280TexturePack:getTextureRegion2019-06-26T14:46:24Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TexturePack|TexturePack]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Returns the texture region of texture pack.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
(TextureRegion) = TexturePack:getTextureRegion(texturename)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texturename''': (string) <translate></translate> <br/><br />
=== <translate>Return values</translate> ===<br />
'''<translate>Returns</translate>''' (TextureRegion) <translate>TextureRegion by specified name</translate><br/><br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">local pack = TexturePack.new({"gfx/1.png", "gfx/2.png", "gfx/3.png", "gfx/4.png"})<br />
<br />
local region1 = pack:getTextureRegion("gfx/1.png")<br />
local region2 = pack:getTextureRegion("gfx/2.png")<br />
local region3 = pack:getTextureRegion("gfx/3.png")<br />
local region4 = pack:getTextureRegion("gfx/4.png")</source></div>John26https://wiki.gideros.rocks/index.php?title=TexturePack&diff=13279TexturePack2019-06-26T14:44:58Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:TexturePack --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/TextureBase|TextureBase]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate>The [[Special:MyLanguage/TexturePack|TexturePack]] class specifies a texture pack (or texture atlas). A texture atlas is a large image which contains many smaller sub-images.<br /><br />
Gideros supports dynamic creation of texture atlases and pre-packed texture atlasses by using &quot;Gideros Texture Packer&quot; tool.<br /><br />
<br /><br />
<br /><br />
<h3>Dynamic Creation of Texture Packs</h3><br /><br />
<br /><br />
To create a texture pack dynamically (at run-time), create [[Special:MyLanguage/TexturePack|TexturePack]] object with a table of file names of textures.<br /><br />
<br /><br />
<source lang="lua">local pack = TexturePack.new({"1.png", "2.png", "3.png", "4.png")}</source><br /><br />
<h3>Static Creation of Texture Packs</h3><br /><br />
<br /><br />
To create a pre-packed texture atlas, use "Gideros Texture Packer" tool:<br /><br />
<br /><br />
[[File:Texture packer.png]]<br />
<br /><br />
<br /><br />
This tool exports two files: A ''.txt'' file that specifes the positions of texture regions and a ''.png'' file of packed texture.<br /><br />
Use these two files to create texture pack:<br /><br />
<source lang="lua">local pack = TexturePack.new("pack.txt", "pack.png")</source><br /></translate><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/TexturePack.new|TexturePack.new]] ''<translate>creates a new TexturePack object</translate>''<br/><!-- GIDEROSMTD:TexturePack.new(textures,padding,filtering,options) creates a new TexturePack object --><br />
[[Special:MyLanguage/TexturePack.new|TexturePack.new]] <br/><!-- GIDEROSMTD:TexturePack.new(txtfile,imagefile,filtering,options) --><br />
[[Special:MyLanguage/TexturePack:getTextureRegion|TexturePack:getTextureRegion]] ''<translate>returns the texture region of texture pack</translate>''<br/><!-- GIDEROSMTD:TexturePack:getTextureRegion(texturename) returns the texture region of texture pack --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
=== <translate>Constants</translate> ===<br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=TexturePack&diff=13278TexturePack2019-06-26T14:44:04Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:TexturePack --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/TextureBase|TextureBase]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate>The [[Special:MyLanguage/TexturePack|TexturePack]] class specifies a texture pack (or texture atlas). A texture atlas is a large image which contains many smaller sub-images.<br /><br />
Gideros supports dynamic creation of texture atlases and pre-packed texture atlasses by using &quot;Gideros Texture Packer&quot; tool.<br /><br />
<br /><br />
<br /><br />
<h3>Dynamic Creation of Texture Packs</h3><br /><br />
<br /><br />
To create a texture pack dynamically (at run-time), create [[Special:MyLanguage/TexturePack|TexturePack]] object with a table of file names of textures.<br /><br />
<br /><br />
<source lang="lua">local pack = TexturePack.new({"1.png", "2.png", "3.png", "4.png")}</source><br /><br />
<h3>Static Creation of Texture Packs</h3><br /><br />
<br /><br />
To create a pre-packed texture atlas, use "Gideros Texture Packer" tool:<br /><br />
<br /><br />
[[File:Texture packer.png]]<br />
<br /><br />
<br /><br />
This tool exports two files: A ''.txt'' file that specifes the positions of texture regions and a ''.png'' file of packed texture.<br /><br />
Use these two files to create texture pack:<br /><br />
<source lang="lua">local pack = TexturePack.new(&quot;pack.txt&quot;, &quot;pack.png&quot;)</source><br /></translate><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/TexturePack.new|TexturePack.new]] ''<translate>creates a new TexturePack object</translate>''<br/><!-- GIDEROSMTD:TexturePack.new(textures,padding,filtering,options) creates a new TexturePack object --><br />
[[Special:MyLanguage/TexturePack.new|TexturePack.new]] <br/><!-- GIDEROSMTD:TexturePack.new(txtfile,imagefile,filtering,options) --><br />
[[Special:MyLanguage/TexturePack:getTextureRegion|TexturePack:getTextureRegion]] ''<translate>returns the texture region of texture pack</translate>''<br/><!-- GIDEROSMTD:TexturePack:getTextureRegion(texturename) returns the texture region of texture pack --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
=== <translate>Constants</translate> ===<br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=TextureBase&diff=13277TextureBase2019-06-26T14:42:24Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:TextureBase --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
[[Special:MyLanguage/TextureBase|TextureBase]] is the base class for [[Special:MyLanguage/Texture|Texture]] and [[Special:MyLanguage/TexturePack|TexturePack]] classes. It provides a common functionaly to texture related classes.<br />
<br />
<br />
TextureBase.CLAMP = "clamp"<br />
<br />
<br />
TextureBase.REPEAT = "repeat"<br />
</translate><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/TextureBase:getHeight|TextureBase:getHeight]] ''<translate>returns the height of the texture in pixels</translate>''<br/><!-- GIDEROSMTD:TextureBase:getHeight() returns the height of the texture in pixels --><br />
[[Special:MyLanguage/TextureBase:getWidth|TextureBase:getWidth]] ''<translate>returns the width of the texture in pixels</translate>''<br/><!-- GIDEROSMTD:TextureBase:getWidth() returns the width of the texture in pixels --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
=== <translate>Constants</translate> ===<br />
[[Special:MyLanguage/TextureBase.CLAMP|TextureBase.CLAMP]]<br/><!-- GIDEROSCST:TextureBase.CLAMP clamp--><br />
[[Special:MyLanguage/TextureBase.REPEAT|TextureBase.REPEAT]]<br/><!-- GIDEROSCST:TextureBase.REPEAT repeat--><br />
[[Special:MyLanguage/TextureBase.RGB565|TextureBase.RGB565]]<br/><!-- GIDEROSCST:TextureBase.RGB565 rgb565--><br />
[[Special:MyLanguage/TextureBase.RGB888|TextureBase.RGB888]]<br/><!-- GIDEROSCST:TextureBase.RGB888 rgb888--><br />
[[Special:MyLanguage/TextureBase.RGBA4444|TextureBase.RGBA4444]]<br/><!-- GIDEROSCST:TextureBase.RGBA4444 rgba4444--><br />
[[Special:MyLanguage/TextureBase.RGBA5551|TextureBase.RGBA5551]]<br/><!-- GIDEROSCST:TextureBase.RGBA5551 rgba5551--><br />
[[Special:MyLanguage/TextureBase.RGBA8888|TextureBase.RGBA8888]]<br/><!-- GIDEROSCST:TextureBase.RGBA8888 rgba8888--><br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=TextInputDialog&diff=13276TextInputDialog2019-06-26T14:39:24Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:TextInputDialog --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2012.8<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/AlertDialog|AlertDialog]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
The [[Special:MyLanguage/TextInputDialog|TextInputDialog]] class is used to display native text input dialogs with one text edit field, one button (as cancel button) and two optional buttons. When the user presses any buttons in the alert dialog, it is dismissed and [[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]] event is dispatched.<br />
<br />
<br />
If text input dialog is dismissed by any other means (by pressing back button on Android or by pressing close button on desktop), it behaves as cancel button is pressed.</translate><br />
<br />
<br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">local textInputDialog = TextInputDialog.new("my title", "my message", "some text", "Cancel", "OK")<br />
<br />
local function onComplete(event)<br />
print(event.text, event.buttonIndex, event.buttonText)<br />
end<br />
<br />
textInputDialog:addEventListener(Event.COMPLETE, onComplete)<br />
textInputDialog:show()</source><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/TextInputDialog.new|TextInputDialog.new]] <br/><!-- GIDEROSMTD:TextInputDialog.new(title,message,text,cancelButton,button1,button2) --><br />
[[Special:MyLanguage/TextInputDialog:getInputType|TextInputDialog:getInputType]] <br/><!-- GIDEROSMTD:TextInputDialog:getInputType() --><br />
[[Special:MyLanguage/TextInputDialog:getText|TextInputDialog:getText]] <br/><!-- GIDEROSMTD:TextInputDialog:getText() --><br />
[[Special:MyLanguage/TextInputDialog:isSecureInput|TextInputDialog:isSecureInput]] <br/><!-- GIDEROSMTD:TextInputDialog:isSecureInput() --><br />
[[Special:MyLanguage/TextInputDialog:setInputType|TextInputDialog:setInputType]] <br/><!-- GIDEROSMTD:TextInputDialog:setInputType(type) --><br />
[[Special:MyLanguage/TextInputDialog:setSecureInput|TextInputDialog:setSecureInput]] <br/><!-- GIDEROSMTD:TextInputDialog:setSecureInput(secureInput) --><br />
[[Special:MyLanguage/TextInputDialog:setText|TextInputDialog:setText]] <br/><!-- GIDEROSMTD:TextInputDialog:setText(text) --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
[[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]]<br/><!-- GIDEROSEVT:Event.COMPLETE complete--><br />
=== <translate>Constants</translate> ===<br />
[[Special:MyLanguage/TextInputDialog.EMAIL|TextInputDialog.EMAIL]]<br/><!-- GIDEROSCST:TextInputDialog.EMAIL email--><br />
[[Special:MyLanguage/TextInputDialog.NUMBER|TextInputDialog.NUMBER]]<br/><!-- GIDEROSCST:TextInputDialog.NUMBER number--><br />
[[Special:MyLanguage/TextInputDialog.PHONE|TextInputDialog.PHONE]]<br/><!-- GIDEROSCST:TextInputDialog.PHONE phone--><br />
[[Special:MyLanguage/TextInputDialog.TEXT|TextInputDialog.TEXT]]<br/><!-- GIDEROSCST:TextInputDialog.TEXT text--><br />
[[Special:MyLanguage/TextInputDialog.URL|TextInputDialog.URL]]<br/><!-- GIDEROSCST:TextInputDialog.URL url--><br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=TTFont.new&diff=13275TTFont.new2019-06-26T14:35:28Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TTFont|TTFont]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br />
Creates a new [[Special:MyLanguage/TTFont|TTFont]] object.<br />
<br />
<br />
Starting from gideros 2017.9, 'text' optional parameter can be the empty string, in which case Gideros will automatically cache characters as they are used.<br />
<br />
<br />
Also, 2017.9 allows filename to be a table of several file names and associated size factor. <br />
Two forms are accepted: <br />
<br />
<source lang="lua">{"font1.ttf","font2.ttf",..} </source><br />
<br />
or <br />
<br />
<source lang="lua"> {{file="font1.ttf", sizeMult=1},{file="font2.ttf", sizeMult=1.1},...} </source><br />
<br />
Characters will be looked up in each file in sequence until a glyph is found.</translate><br />
<br />
<br />
<source lang="lua"><br />
TTFont.new(filename,size,text,filtering,outlineSize)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''filename''': (string) <translate>The name of the TTF file to be loaded</translate> <br/><br />
'''size''': (number) <translate>size of the font</translate> <br/><br />
'''text''': (string, optional) <translate>if specified, TTFont caches the characters of specified text to speed up the rendering. If instead of specified symbols empty quotes "" are provided, then all font symbols are cached.</translate> <br/><br />
'''filtering''': (boolean, default = false) <translate>Whether or not the font texture is filtered</translate> '''optional'''<br/><br />
'''outlineSize''': (number) <translate>If set, the font will be rendered with an outline of the given size</translate> '''optional'''<br/></div>John26https://wiki.gideros.rocks/index.php?title=TTFont.new&diff=13274TTFont.new2019-06-26T14:34:27Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TTFont|TTFont]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br />
Creates a new [[Special:MyLanguage/TTFont|TTFont]] object.<br />
<br />
<br />
Starting from gideros 2017.9, 'text' optional parameter can be the empty string, in which case Gideros will automatically cache characters as they are used.<br />
<br />
<br />
Also, 2017.9 allows filename to be a table of several file names and associated size factor. <br />
Two forms are accepted: <br />
<br />
{"font1.ttf","font2.ttf",..} or <br />
<br />
{{file="font1.ttf", sizeMult=1},{file="font2.ttf", sizeMult=1.1},...}.<br />
<br />
Characters will be looked up in each file in sequence until a glyph is found.</translate><br />
<br />
<br />
<source lang="lua"><br />
TTFont.new(filename,size,text,filtering,outlineSize)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''filename''': (string) <translate>The name of the TTF file to be loaded</translate> <br/><br />
'''size''': (number) <translate>size of the font</translate> <br/><br />
'''text''': (string, optional) <translate>if specified, TTFont caches the characters of specified text to speed up the rendering. If instead of specified symbols empty quotes "" are provided, then all font symbols are cached.</translate> <br/><br />
'''filtering''': (boolean, default = false) <translate>Whether or not the font texture is filtered</translate> '''optional'''<br/><br />
'''outlineSize''': (number) <translate>If set, the font will be rendered with an outline of the given size</translate> '''optional'''<br/></div>John26https://wiki.gideros.rocks/index.php?title=TextureRegion.new&diff=13273TextureRegion.new2019-06-26T14:26:33Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
TextureRegion.new(texture)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br />
<br />
<br />
If TextureRegion object is created with 1 parameter (texture), it specifies the whole texture.<br /><br />
If TextureRegion object is created with 5 parameters (texture, x, y, width, height), if specifies a rectangular region within texture.<br /><br />
</translate><br />
<br />
<br />
<source lang="lua"><br />
TextureRegion.new(texture,x,y,width,height)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
'''x''': (number) <translate>left coordinate of the region</translate> <br/><br />
'''y''': (number) <translate>top coordinate of the region</translate> <br/><br />
'''width''': (number) <translate>width of the region</translate> <br/><br />
'''height''': (number) <translate>height of the region</translate> <br/></div>John26https://wiki.gideros.rocks/index.php?title=TextureRegion.new&diff=13272TextureRegion.new2019-06-26T14:26:03Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
TextureRegion.new(texture)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br />
<br />
<br />
If TextureRegion object is created with 1 parameter (texture), it specifies the whole texture.<br /><br />
If TextureRegion object is created with 5 parameters (texture, x, y, width, height), if specifies a rectangular region within texture.<br /><br />
</translate><br />
<br />
<br />
<source lang="lua"><br />
TextureRegion.new(texture,x,y,width,height)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
'''x''': (number) <translate>left coordinate of the region</translate> <br/><br />
'''y''': (number) <translate>top coordinate of the region</translate> <br/><br />
'''width''': (number) <translate>width of the region</translate> <br/><br />
'''height''': (number) <translate>height of the region</translate> <br/></div>John26https://wiki.gideros.rocks/index.php?title=TextureRegion.new&diff=13271TextureRegion.new2019-06-26T14:23:52Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
TextureRegion.new(texture)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br />
<br />
If TextureRegion object is created with 1 parameter (texture), it specifies the whole texture.<br /><br />
If TextureRegion object is created with 5 parameters (texture, x, y, width, height), if specifies a rectangular region within texture.<br /><br />
<br />
</translate><br />
<source lang="lua"><br />
TextureRegion.new(texture,x,y,width,height)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
'''x''': (number) <translate>left coordinate of the region</translate> <br/><br />
'''y''': (number) <translate>top coordinate of the region</translate> <br/><br />
'''width''': (number) <translate>width of the region</translate> <br/><br />
'''height''': (number) <translate>height of the region</translate> <br/></div>John26https://wiki.gideros.rocks/index.php?title=TextureRegion.new&diff=13270TextureRegion.new2019-06-26T14:23:08Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
TextureRegion.new(texture)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/TextureRegion|TextureRegion]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new TextureRegion object.<br /><br />
<br /><br />
If TextureRegion object is created with 1 parameter (texture), it specifies the whole texture.<br /><br />
If TextureRegion object is created with 5 parameters (texture, x, y, width, height), if specifies a rectangular region within texture.<br /><br />
<br /><br />
<br /></translate><br />
<source lang="lua"><br />
TextureRegion.new(texture,x,y,width,height)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''texture''': (TextureBase) <translate>texture object</translate> <br/><br />
'''x''': (number) <translate>left coordinate of the region</translate> <br/><br />
'''y''': (number) <translate>top coordinate of the region</translate> <br/><br />
'''width''': (number) <translate>width of the region</translate> <br/><br />
'''height''': (number) <translate>height of the region</translate> <br/></div>John26https://wiki.gideros.rocks/index.php?title=UrlLoader.new&diff=13269UrlLoader.new2019-06-26T14:19:26Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2012.2.2<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/UrlLoader|UrlLoader]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new [[Special:MyLanguage/UrlLoader|UrlLoader]] object.<br /><br />
<br /><br />
''url'' parameter specifies the URL to download. This parameter is optional and if specified loading starts immediately.<br /><br />
<br /><br />
''method'' parameter specifies the HTTP request method. It can be one of the values of [[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]], [[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]], [[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]] or [[Special:MyLanguage/UrlLoader.DELETE|UrlLoader.DELETE]].<br /><br />
The default HTTP method is [[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]].<br /><br />
<br /><br />
''body'' parameter specifies the HTTP body data. This parameter is used only when the HTTP method is [[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]] or or [[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]].<br /><br />
<br /><br />
After loading is finished, loaded data is stored at ''event.data'' field of [[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]] event as string.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
UrlLoader.new(url,method,headers,body)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''url''': (string, optional) <translate>URL to download. This parameter is optional and if specified loading starts immediately.</translate> <br/><br />
'''method''': (string, default = "get") <translate>HTTP request method.</translate> <br/><br />
'''headers''': (table, optional) <translate>HTTP headers.</translate> <br/><br />
'''body''': (string, optional) <translate>HTTP body data. This data is sent as the message body of a request.</translate> <br/><br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">local url = "http://www.[yourDomain].com/application.php?userid=gideros&login=guest"<br />
<br />
local loader1 = UrlLoader.new(url)<br />
local loader2 = UrlLoader.new(url, UrlLoader.GET) -- same as the previous line<br />
local loader3 = UrlLoader.new(url, UrlLoader.POST, "my post data")<br />
local loader4 = UrlLoader.new(url, UrlLoader.PUT, "my put data")<br />
local loader5 = UrlLoader.new(url, UrlLoader.DELETE)<br />
<br />
local headers = {<br />
["Content-Type"] = "application/x-www-form-urlencoded",<br />
["User-Agent"] = "Gideros Browser",<br />
}<br />
local loader6 = UrlLoader.new(url, UrlLoader.PUT, headers, "key=value")</source></div>John26https://wiki.gideros.rocks/index.php?title=UrlLoader.new&diff=13268UrlLoader.new2019-06-26T14:17:13Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
'''<translate>Available since</translate>:''' Gideros 2012.2.2<br/><br />
'''<translate>Class</translate>:''' [[Special:MyLanguage/UrlLoader|UrlLoader]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
Creates a new [[Special:MyLanguage/UrlLoader|UrlLoader]] object.<br /><br />
<br /><br />
''url'' parameter specifies the URL to download. This parameter is optional and if specified loading starts immediately.<br /><br />
<br /><br />
''method'' parameter specifies the HTTP request method. It can be one of the values of [[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]], [[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]], [[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]] or [[Special:MyLanguage/UrlLoader.DELETE|UrlLoader.DELETE]].<br /><br />
The default HTTP method is [[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]].<br /><br />
<br /><br />
''body'' parameter specifies the HTTP body data. This parameter is used only when the HTTP method is [[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]] or or [[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]].<br /><br />
<br /><br />
After loading is finished, loaded data is stored at ''event.data'' field of [[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]] event as string.<br /><br />
<br /></translate><br />
<source lang="lua"><br />
UrlLoader.new(url,method,headers,body)<br />
</source><br />
=== <translate>Parameters</translate> ===<br />
'''url''': (string, optional) <translate>URL to download. This parameter is optional and if specified loading starts immediately.</translate> <br/><br />
'''method''': (string, default = "get") <translate>HTTP request method.</translate> <br/><br />
'''headers''': (table, optional) <translate>HTTP headers.</translate> <br/><br />
'''body''': (string, optional) <translate>HTTP body data. This data is sent as the message body of a request.</translate> <br/><br />
=== <translate>Examples</translate> ===<br />
'''Example'''<br/><br />
<source lang="lua">local url = "http://www.[yourDomain].com/application.php?userid=gideros&login=guest"<br />
<br />
local loader1 = UrlLoader.new(url)<br />
local loader2 = UrlLoader.new(url, UrlLoader.GET) -- same as the previous line<br />
local loader3 = UrlLoader.new(url, UrlLoader.POST, &quot;my post data&quot;)<br />
local loader4 = UrlLoader.new(url, UrlLoader.PUT, &quot;my put data&quot;)<br />
local loader5 = UrlLoader.new(url, UrlLoader.DELETE)<br />
<br />
local headers = {<br />
[&quot;Content-Type&quot;] = &quot;application/x-www-form-urlencoded&quot;,<br />
[&quot;User-Agent&quot;] = &quot;Gideros Browser&quot;,<br />
}<br />
local loader6 = UrlLoader.new(url, UrlLoader.PUT, headers, &quot;key=value&quot;)</source></div>John26https://wiki.gideros.rocks/index.php?title=UrlLoader&diff=13267UrlLoader2019-06-26T14:15:23Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:UrlLoader --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2012.2.2<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
The [[Special:MyLanguage/UrlLoader|UrlLoader]] class is used to download data from an URL. It can be used to download (and optionally save) text files, XML files, JSON files, image files or binary files, etc.<br /><br />
Downloaded data is delivered at ''event.data'' field of [[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]] event as string. Lua is eight-bit clean and so strings may contain characters with any numeric value, including embedded zeros. That means that you can store any binary data into a string.<br /><br />
<br />
<h3>HTTP Request Methods</h3><br /><br />
<br /><br />
UrlLoader supports GET, POST, PUT and DELETE methods. These are defined by these string constants:<br /><br />
<br /><br />
<ul><br /><br />
<li>''UrlLoader.GET = "get"''</li><br /><br />
<li>''UrlLoader.POST = "post"''</li><br /><br />
<li>''UrlLoader.PUT = "put"''</li><br /><br />
<li>''UrlLoader.DELETE = "delete"''</li><br /><br />
</ul><br /><br />
<br /></translate><br />
=== <translate>Examples</translate> ===<br />
'''The example below shows downloading an image file from an URL, saving it to the documents folder and displaying it<br /><br />
on the stage. This example also shows downloading progress and handling errors.<br /><br />
<br />'''<br/><br />
<source lang="lua">local loader = UrlLoader.new("http://example.com/image.png")<br />
<br />
local function onComplete(event)<br />
local out = io.open("|D|image.png", "wb")<br />
out:write(event.data)<br />
out:close()<br />
<br />
local b = Bitmap.new(Texture.new("|D|image.png"))<br />
stage:addChild(b)<br />
end<br />
<br />
local function onError()<br />
print("error")<br />
end<br />
<br />
local function onProgress(event)<br />
print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)<br />
end<br />
<br />
loader:addEventListener(Event.COMPLETE, onComplete)<br />
loader:addEventListener(Event.ERROR, onError)<br />
loader:addEventListener(Event.PROGRESS, onProgress)</source><br />
'''Uploading a file'''<br/><br />
<source lang="lua">local filename = "crate.png"<br />
local file = io.open(filename, "rb")<br />
local contents = file:read( "*a" )<br />
local boundary = "somerndstring"<br />
<br />
local send = "--"..boundary..<br />
"\r\nContent-Disposition: form-data; "..<br />
"name="..filename.."; filename="..filename..<br />
"\r\nContent-type: image/png"..<br />
"\r\n\r\n"..contents..<br />
"\r\n--"..boundary.."--\r\n";<br />
<br />
local headers = {<br />
["Content-Type"] = "multipart/form-data; boundary="..boundary,<br />
["Content-Length"] = #send,<br />
}<br />
<br />
local loader = UrlLoader.new("http://localhost/gideros.php", UrlLoader.POST, headers, send)<br />
<br />
loader:addEventListener(Event.COMPLETE, function(e)<br />
print(e.data)<br />
end)</source><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/UrlLoader.new|UrlLoader.new]] ''<translate>creates a new UrlLoader object</translate>''<br/><!-- GIDEROSMTD:UrlLoader.new(url,method,headers,body) creates a new UrlLoader object --><br />
[[Special:MyLanguage/UrlLoader:close|UrlLoader:close]] ''<translate>terminates the current loading operation</translate>''<br/><!-- GIDEROSMTD:UrlLoader:close() terminates the current loading operation --><br />
[[Special:MyLanguage/UrlLoader:ignoreSslErrors|UrlLoader:ignoreSslErrors]] ''<translate>Ignores SSL certificate related errors</translate>''<br/><!-- GIDEROSMTD:UrlLoader:ignoreSslErrors() Ignores SSL certificate related errors --><br />
[[Special:MyLanguage/UrlLoader:load|UrlLoader:load]] ''<translate>loads data from the specified URL</translate>''<br/><!-- GIDEROSMTD:UrlLoader:load(url,method,headers,body) loads data from the specified URL --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
[[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]]<br/><!-- GIDEROSEVT:Event.COMPLETE complete--><br />
[[Special:MyLanguage/Event.ERROR|Event.ERROR]]<br/><!-- GIDEROSEVT:Event.ERROR error--><br />
[[Special:MyLanguage/Event.PROGRESS|Event.PROGRESS]]<br/><!-- GIDEROSEVT:Event.PROGRESS progress--><br />
=== <translate>Constants</translate> ===<br />
[[Special:MyLanguage/UrlLoader.DELETE|UrlLoader.DELETE]]<br/><!-- GIDEROSCST:UrlLoader.DELETE delete--><br />
[[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]]<br/><!-- GIDEROSCST:UrlLoader.GET get--><br />
[[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]]<br/><!-- GIDEROSCST:UrlLoader.POST post--><br />
[[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]]<br/><!-- GIDEROSCST:UrlLoader.PUT put--><br />
|}</div>John26https://wiki.gideros.rocks/index.php?title=UrlLoader&diff=13266UrlLoader2019-06-26T14:13:12Z<p>John26: </p>
<hr />
<div>__NOTOC__<br />
<languages /><br />
<!-- GIDEROSOBJ:UrlLoader --><br />
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/><br />
'''<translate>Available since</translate>:''' Gideros 2012.2.2<br/><br />
'''<translate>Inherits from</translate>:''' [[Special:MyLanguage/Object|Object]]<br/><br />
=== <translate>Description</translate> ===<br />
<translate><br /><br />
The [[Special:MyLanguage/UrlLoader|UrlLoader]] class is used to download data from an URL. It can be used to download (and optionally save) text files, XML files, JSON files, image files or binary files, etc.<br /><br />
Downloaded data is delivered at ''event.data'' field of [[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]] event as string. Lua is eight-bit clean and so strings may contain characters with any numeric value, including embedded zeros. That means that you can store any binary data into a string.<br /><br />
<br />
<h3>HTTP Request Methods</h3><br /><br />
<br /><br />
UrlLoader supports GET, POST, PUT and DELETE methods. These are defined by these string constants:<br /><br />
<br /><br />
<ul><br /><br />
<li>''UrlLoader.GET = "get"''</li><br /><br />
<li>''UrlLoader.POST = "post"''</li><br /><br />
<li>''UrlLoader.PUT = "put"''</li><br /><br />
<li>''UrlLoader.DELETE = "delete"''</li><br /><br />
</ul><br /><br />
<br /></translate><br />
=== <translate>Examples</translate> ===<br />
'''The example below shows downloading an image file from an URL, saving it to the documents folder and displaying it<br /><br />
on the stage. This example also shows downloading progress and handling errors.<br /><br />
<br />'''<br/><br />
<source lang="lua">local loader = UrlLoader.new("http://example.com/image.png")<br />
<br />
local function onComplete(event)<br />
local out = io.open(&quot;|D|image.png&quot;, &quot;wb&quot;)<br />
out:write(event.data)<br />
out:close()<br />
<br />
local b = Bitmap.new(Texture.new(&quot;|D|image.png&quot;))<br />
stage:addChild(b)<br />
end<br />
<br />
local function onError()<br />
print(&quot;error&quot;)<br />
end<br />
<br />
local function onProgress(event)<br />
print(&quot;progress: &quot; .. event.bytesLoaded .. &quot; of &quot; .. event.bytesTotal)<br />
end<br />
<br />
loader:addEventListener(Event.COMPLETE, onComplete)<br />
loader:addEventListener(Event.ERROR, onError)<br />
loader:addEventListener(Event.PROGRESS, onProgress)</source><br />
'''Uploading a file'''<br/><br />
<source lang="lua">local filename = "crate.png"<br />
local file = io.open(filename, "rb")<br />
local contents = file:read( "*a" )<br />
local boundary = "somerndstring"<br />
<br />
local send = "--"..boundary..<br />
"\r\nContent-Disposition: form-data; "..<br />
"name="..filename.."; filename="..filename..<br />
"\r\nContent-type: image/png"..<br />
"\r\n\r\n"..contents..<br />
"\r\n--"..boundary.."--\r\n";<br />
<br />
local headers = {<br />
["Content-Type"] = "multipart/form-data; boundary="..boundary,<br />
["Content-Length"] = #send,<br />
}<br />
<br />
local loader = UrlLoader.new("http://localhost/gideros.php", UrlLoader.POST, headers, send)<br />
<br />
loader:addEventListener(Event.COMPLETE, function(e)<br />
print(e.data)<br />
end)</source><br />
{|-<br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Methods</translate> ===<br />
[[Special:MyLanguage/UrlLoader.new|UrlLoader.new]] ''<translate>creates a new UrlLoader object</translate>''<br/><!-- GIDEROSMTD:UrlLoader.new(url,method,headers,body) creates a new UrlLoader object --><br />
[[Special:MyLanguage/UrlLoader:close|UrlLoader:close]] ''<translate>terminates the current loading operation</translate>''<br/><!-- GIDEROSMTD:UrlLoader:close() terminates the current loading operation --><br />
[[Special:MyLanguage/UrlLoader:ignoreSslErrors|UrlLoader:ignoreSslErrors]] ''<translate>Ignores SSL certificate related errors</translate>''<br/><!-- GIDEROSMTD:UrlLoader:ignoreSslErrors() Ignores SSL certificate related errors --><br />
[[Special:MyLanguage/UrlLoader:load|UrlLoader:load]] ''<translate>loads data from the specified URL</translate>''<br/><!-- GIDEROSMTD:UrlLoader:load(url,method,headers,body) loads data from the specified URL --><br />
| style="width: 50%; vertical-align:top;"|<br />
=== <translate>Events</translate> ===<br />
[[Special:MyLanguage/Event.COMPLETE|Event.COMPLETE]]<br/><!-- GIDEROSEVT:Event.COMPLETE complete--><br />
[[Special:MyLanguage/Event.ERROR|Event.ERROR]]<br/><!-- GIDEROSEVT:Event.ERROR error--><br />
[[Special:MyLanguage/Event.PROGRESS|Event.PROGRESS]]<br/><!-- GIDEROSEVT:Event.PROGRESS progress--><br />
=== <translate>Constants</translate> ===<br />
[[Special:MyLanguage/UrlLoader.DELETE|UrlLoader.DELETE]]<br/><!-- GIDEROSCST:UrlLoader.DELETE delete--><br />
[[Special:MyLanguage/UrlLoader.GET|UrlLoader.GET]]<br/><!-- GIDEROSCST:UrlLoader.GET get--><br />
[[Special:MyLanguage/UrlLoader.POST|UrlLoader.POST]]<br/><!-- GIDEROSCST:UrlLoader.POST post--><br />
[[Special:MyLanguage/UrlLoader.PUT|UrlLoader.PUT]]<br/><!-- GIDEROSCST:UrlLoader.PUT put--><br />
|}</div>John26