Game Development Reference
In-Depth Information
task = MOAIHttpTask.new ()
task:setVerb ( MOAIHttpTask.HTTP_GET )
task:setUrl ( " www.cnn.com " )
task:setCallback ( onFinish )
task:setUserAgent ( "Moai" )
task:setHeader ( "Foo", "foo" )
task:setHeader ( "Bar", "bar" )
task:setHeader ( "Baz", "baz" )
task:setVerbose ( true )
task:performAsync ()
performAsync , you use
performSync function.
is a two-way function, which means not only can you use it for downloading using HTTP_GET ,
HttpTask are
HTTP_HEAD
HTTP_GET
HTTP_PUT
HTTP_POST
HTTP_DELETE
Using JSON
There is good support for using JSON in Moai. To decode or encode a JSON string, you can use the
MOAIJsonParser object. This has just two functions, encode and decode . The decode function takes a
JSON string and converts it into a hierarchy of tables, whereas encode converts a hierarchy of tables
into a JSON string.
local test = {name="Jayant", Msg={BaaBaa="BlackSheep", Line1="Have you any wool?"}}
print(MOAIJsonParser.encode(test))
Using Base64
When developing a game, to send messages or upload or download data, you might need to encode
data into Base64 in order to be able to send data in text format. The MOAIDataBuffer class gives you
the base-conversion functionality.
theText = "This is plain text, but..."
encoded = MOAIDataBuffer.base64Encode(theText)
print(encoded)
decoded = MOAIDataBuffer.base64Decode(encoded)
print(decoded)
 
Search WWH ::




Custom Search