ansca-corona-102.pdf

23 620 3
ansca-corona-102.pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Corona

TMwww.anscamobile.com TMwww.anscamobile.comWhat’s CoronaA simple, yet powerful framework allowing rapid mobile cross platform application development. TMwww.anscamobile.comCorona 102 Functions & EventListeners TMwww.anscamobile.comCorona framework based on Lua TMwww.anscamobile.comCorona Lua resourceshttp://ww.lua.orghttp://www.lua.org/lua-l.htmlhttp://developer.anscamobile.com/http://en.wikipedia.org/wiki/Lua_ TMwww.anscamobile.comCorona Without functionslocal text = display.newText("hello",100,200,"Helvetica",24);textObj:setTextColor(r,g,b);Disadvantages:When program begins to get too big, difficult to manage codereusing code becomes hard to break apartdebugging becomes a nightmareno sense of where program starts TMwww.anscamobile.comCorona With Functions:local function STextColor(textObj, r,g,b) textObj:setTextColor(r,g,b);endlocal function main()local text = display.newText("hello",100,200,"Helvetica",24);STxtColor(text,255,0,0);endmain()Advantages:easier to manage codeeasier to re-use code on other programs as welleasier to debug since you can narrow down where error occursa sense of where program starts TMwww.anscamobile.comCorona Functions:•First-class values.•Passed by value.•Stored in tables.•Returned from functions.•Global and local.•called from other ‘packages’ TMwww.anscamobile.comCorona Function Definitions:function name(args) body return [values]endGlobal Functionlocal function name(args) body return [values]endfunction local to file scopef = function (args) body return [values]endAnonymous functionfunction ( . ) bodyreturn values] end( .) indicates variable args and { .} places them in a table where they processed in standard way. TMwww.anscamobile.comCorona More function definitions:function obj:name(args) body return [values]endObject function getting extra args and self

Ngày đăng: 01/09/2012, 08:48

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan