Hello!
A "work-in-progress" often leaves its documentation behind - Corona is certainly no exception from this rule...
Fortunately, however, Lua offers really useful introspection capabilities, which may also be used to inspect the Corona run-time environment.
The author has tried to inspect the "Corona-Terminal", here are the results.
The code used was the following (unfortunately, the forum does no longer display any indentations - is there a special trick?) :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | io.stdout:setvbuf("no"); io.stderr:setvbuf("no"); -------------------------------------------------------------------------------- -- inform[ln] writes the given arguments onto stdout -- -------------------------------------------------------------------------------- function inform (...) for i = 1,select('#',...) do -- even "nil" is handled properly io.stdout:write(tostring(select(i,...))); end; end; function informln (...) for i = 1,select('#',...) do -- even "nil" is handled properly io.stdout:write(tostring(select(i,...))); end; io.stdout:write("\n"); end; -------------------------------------------------------------------------------- -- say[ln] just synonyms for inform[ln] -- -------------------------------------------------------------------------------- say = inform; sayln = informln; local Label = display.newText("(see Terminal)", 60,50, nil, 28); Label:setTextColor(255,255,255); -------------------------------------------------------------------------------- -- Table Tracking (never inspect any table twice) -- -------------------------------------------------------------------------------- local inspectedTables = {}; local pendingTables = {}; -------------------------------------------------------------------------------- -- inspectTable inspects a given table -- -------------------------------------------------------------------------------- function inspectTable (TablePrefix, Table) inspectedTables[Table] = TablePrefix; -- mark this table as inspected ---- construct a sorted list with the keys of this table ---- local KeyTable = {}; local hasNonPrintableKeys = false; for Key,Value in pairs(Table) do if (type(Key) == "string") then KeyTable[#KeyTable+1] = Key; elseif (type(Key) == "number") then KeyTable[#KeyTable+1] = tostring(Key); -- not really fool-proof, I know else hasNonPrintableKeys = true; -- just remember any non-printable keys end; end; table.sort(KeyTable); ---- determine the length of the longest key ---- local maxKeyLength = 0; for i = 1,#KeyTable do if (#KeyTable[i] > maxKeyLength) then maxKeyLength = #KeyTable[i] end; end; ---- finally print the list of global keys ---- sayln(); sayln(string.rep("-",80)); sayln(" Contents of ",TablePrefix); sayln(string.rep("-",80)); sayln(); if (#KeyTable == 0) then if (hasNonPrintableKeys) then sayln(" (this table seems to contain non-printable keys only)"); else sayln(" (this table is empty)"); end; end; for i = 1,#KeyTable do local currentKey = KeyTable[i]; -- just a shortcut say(" ", string.rep(" ",maxKeyLength-#currentKey), currentKey, ": "); local currentType = type(Table[currentKey]); if (currentType == "nil") then sayln("nil"); elseif (currentType == "boolean") then sayln(Table[currentKey]); elseif (currentType == "number") then sayln(Table[currentKey]); elseif (currentType == "string") then sayln("'",Table[currentKey],"'"); elseif (currentType == "table") then if (inspectedTables[Table[currentKey]] == nil) then sayln("(table, will be inspected later)"); pendingTables[#pendingTables+1] = { Prefix = TablePrefix.."['"..currentKey.."']", Value = Table[currentKey] }; else sayln("(table, same as "..inspectedTables[Table[currentKey]]..")"); end; else sayln("(",currentType,")"); end; end; if (hasNonPrintableKeys) then sayln(); sayln("this table also seems to contain non-printable keys!") end; end; -------------------------------------------------------------------------------- -- Inspection of the Corona Runtime Environment -- -------------------------------------------------------------------------------- sayln("Lua Version: ", _VERSION); inspectTable("_G",_G); while (#pendingTables > 0) do local nextTable = table.remove(pendingTables,1); inspectTable(nextTable.Prefix,nextTable.Value); end; |
The next tables sound interesting, but there is not yet any description in the docs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | -------------------------------------------------------------------------------- Contents of _G['BounceBehavior'] -------------------------------------------------------------------------------- _name: 'Bounce' _numTargets: 0 _target: (table, will be inspected later) container: (table, will be inspected later) enterFrame: (function) orientation: (function) register: (function) setAutoRotate: (function) setOrientation: (function) vx: 0 vy: 0 -------------------------------------------------------------------------------- Contents of _G['ButtonBehavior'] -------------------------------------------------------------------------------- _eventName: 'touch' _name: 'Button' register: (function) -------------------------------------------------------------------------------- Contents of _G['Generator'] -------------------------------------------------------------------------------- random: (function) -------------------------------------------------------------------------------- Contents of _G['Rotate3DBehavior'] -------------------------------------------------------------------------------- _name: 'Rotate3D' _numTargets: 0 _target: (table, will be inspected later) _vRotation: 0 enterFrame: (function) register: (function) reset: (function) |
The "Runtime" table contains functions for event listener management:
1 2 3 4 5 6 7 8 9 | -------------------------------------------------------------------------------- Contents of _G['Runtime'] -------------------------------------------------------------------------------- _proxy: (table, will be inspected later) _stage: (table, will be inspected later) _super: (table, will be inspected later) addEventListener: (function) removeEventListener: (function) |
The "coroutine" and "debug" tables seem to be complete (they *look* so, at least):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | -------------------------------------------------------------------------------- Contents of _G['coroutine'] -------------------------------------------------------------------------------- create: (function) resume: (function) running: (function) status: (function) wrap: (function) yield: (function) -------------------------------------------------------------------------------- Contents of _G['debug'] -------------------------------------------------------------------------------- debug: (function) getfenv: (function) gethook: (function) getinfo: (function) getlocal: (function) getmetatable: (function) getregistry: (function) getupvalue: (function) setfenv: (function) sethook: (function) setlocal: (function) setmetatable: (function) setupvalue: (function) traceback: (function) |
Many of the "display" functions have already been described in the docs - but what about the "newLine" function? When looking through the API Reference, the author expected line/polyline/polygon support - but could not find it. By inspecting the "display" table, however, it looks as if there would be some line/polyline functionality, at least.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | -------------------------------------------------------------------------------- Contents of _G['display'] -------------------------------------------------------------------------------- BottomCenterReferencePoint: (userdata) BottomLeftReferencePoint: (userdata) BottomRightReferencePoint: (userdata) CenterLeftReferencePoint: (userdata) CenterReferencePoint: (userdata) CenterRightReferencePoint: (userdata) DarkStatusBar: (userdata) DefaultStatusBar: (userdata) HiddenStatusBar: (userdata) TopCenterReferencePoint: (userdata) TopLeftReferencePoint: (userdata) TopRightReferencePoint: (userdata) TranslucentStatusBar: (userdata) _getCurrentStage: (function) _newCircle: (function) _newContainer: (function) _newGroup: (function) _newImage: (function) _newLine: (function) _newRect: (function) _newRoundedRect: (function) _newText: (function) captureScreen: (function) getCurrentStage: (function) newCircle: (function) newContainer: (function) newGroup: (function) newImage: (function) newLine: (function) newRect: (function) newRoundedRect: (function) newText: (function) save: (function) setStatusBar: (function) |
The "easing" table was only partially mentioned in the docs (but not really "described"):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | -------------------------------------------------------------------------------- Contents of _G['easing'] -------------------------------------------------------------------------------- inBounce: (function) inExpo: (function) inOutBounce: (function) inOutExpo: (function) inOutQuad: (function) inQuad: (function) linear: (function) outBounce: (function) outExpo: (function) outQuad: (function) |
"io" and "math" look complete:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | -------------------------------------------------------------------------------- Contents of _G['io'] -------------------------------------------------------------------------------- close: (function) flush: (function) input: (function) lines: (function) open: (function) output: (function) popen: (function) read: (function) stderr: (userdata) stdin: (userdata) stdout: (userdata) tmpfile: (function) type: (function) write: (function) -------------------------------------------------------------------------------- Contents of _G['math'] -------------------------------------------------------------------------------- abs: (function) acos: (function) asin: (function) atan: (function) atan2: (function) ceil: (function) cos: (function) cosh: (function) deg: (function) exp: (function) floor: (function) fmod: (function) frexp: (function) huge: inf ldexp: (function) log: (function) log10: (function) max: (function) min: (function) mod: (function) modf: (function) pi: 3.1415926535898 pow: (function) rad: (function) random: (function) randomseed: (function) sin: (function) sinh: (function) sqrt: (function) tan: (function) tanh: (function) |
The "media" table has been extensively described in the docs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | -------------------------------------------------------------------------------- Contents of _G['media'] -------------------------------------------------------------------------------- Camera: (userdata) PhotoLibrary: (userdata) SavedPhotosAlbum: (userdata) newEventSound: (function) pauseSound: (function) playEventSound: (function) playSound: (function) playVideo: (function) show: (function) stopSound: (function) |
The "native" table has also been completely described in the docs. Unfortunately, there are no "hidden" functions for text input (which still seems to be missing!):
1 2 3 4 5 6 | -------------------------------------------------------------------------------- Contents of _G['native'] -------------------------------------------------------------------------------- cancelAlert: (function) showAlert: (function) |
The "os" table looks complete, the same applies to the "package" table:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | -------------------------------------------------------------------------------- Contents of _G['os'] -------------------------------------------------------------------------------- clock: (function) date: (function) difftime: (function) execute: (function) exit: (function) getenv: (function) remove: (function) rename: (function) setlocale: (function) time: (function) tmpname: (function) -------------------------------------------------------------------------------- Contents of _G['package'] -------------------------------------------------------------------------------- config: '/ ; ? ! -' cpath: '/Applications/Corona/Corona Simulator.app/Contents/Resources/?.blu' loaded: (table, will be inspected later) loaders: (table, will be inspected later) loadlib: (function) path: '/Users/rozek/Corona/?.lua;/Applications/Corona/Corona Simulator.app/Contents/Resources/?.lua' preload: (table, will be inspected later) seeall: (function) |
"string" support looks complete as well:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | -------------------------------------------------------------------------------- Contents of _G['string'] -------------------------------------------------------------------------------- byte: (function) char: (function) dump: (function) find: (function) format: (function) gfind: (function) gmatch: (function) gsub: (function) len: (function) lower: (function) match: (function) rep: (function) reverse: (function) sub: (function) upper: (function) |
The "system" table contains two public looking functions "beginListener" and "endListener" - they should either be documented or have names starting with an underscore "_" in order to mark them "private" (at least - of course, Lua offers far better approaches to "hide" private table entries):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | -------------------------------------------------------------------------------- Contents of _G['system'] -------------------------------------------------------------------------------- DocumentsDirectory: (userdata) ResourceDirectory: (userdata) SystemResourceDirectory: (userdata) TemporaryDirectory: (userdata) __proxyindex: (function) __proxynewindex: (function) __proxyregister: (function) beginListener: (function) endListener: (function) getInfo: (function) getTimer: (function) openURL: (function) pathForFile: (function) setAccelerometerInterval: (function) setIdleTimer: (function) vibrate: (function) |
The "table" table seems to contain a few additional methods ("foreach", "foreachi" and "getn", "setn"):
1 2 3 4 5 6 7 8 9 10 11 12 13 | -------------------------------------------------------------------------------- Contents of _G['table'] -------------------------------------------------------------------------------- concat: (function) foreach: (function) foreachi: (function) getn: (function) insert: (function) maxn: (function) remove: (function) setn: (function) sort: (function) |
The "timer" table seems to additionally offer a function "cancel" which sounds very promising!
1 2 3 4 5 6 7 8 9 | -------------------------------------------------------------------------------- Contents of _G['timer'] -------------------------------------------------------------------------------- _insert: (function) _runlist: (table, will be inspected later) cancel: (function) enterFrame: (function) performWithDelay: (function) |
The "transition" table also seems to offer more functions than described:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | -------------------------------------------------------------------------------- Contents of _G['transition'] -------------------------------------------------------------------------------- _activeTweens: (table, will be inspected later) _add: (function) _createSlideParameters: (function) _dissolvePrepareDst: (function) _dissolvePrepareSrc: (function) _initTween: (function) _nonPropertyKeys: (table, will be inspected later) _setInvisible: (function) cancel: (function) dissolve: (function) enterFrame: (function) from: (function) slide: (function) to: (function) |
The following tables are only mentioned to be complete:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | -------------------------------------------------------------------------------- Contents of _G['BounceBehavior']['_target'] -------------------------------------------------------------------------------- (this table is empty) -------------------------------------------------------------------------------- Contents of _G['BounceBehavior']['container'] -------------------------------------------------------------------------------- _class: (table, will be inspected later) _proxy: (userdata) -------------------------------------------------------------------------------- Contents of _G['Rotate3DBehavior']['_target'] -------------------------------------------------------------------------------- (this table is empty) -------------------------------------------------------------------------------- Contents of _G['Runtime']['_proxy'] -------------------------------------------------------------------------------- __index: (function) __newindex: (function) -------------------------------------------------------------------------------- Contents of _G['Runtime']['_stage'] -------------------------------------------------------------------------------- _class: (table, will be inspected later) _proxy: (userdata) |
The following table looks like the metatable of "Runtime":
1 2 3 4 5 6 7 8 9 10 11 12 | -------------------------------------------------------------------------------- Contents of _G['Runtime']['_super'] -------------------------------------------------------------------------------- __index: (table, same as _G['Runtime']['_super']) _indexForType: (table, will be inspected later) _super: (table, will be inspected later) addEventListener: (function) dispatchEvent: (function) getOrCreateTable: (function) removeEventListener: (function) respondsToEvent: (function) |
Here comes the list of loaded and "preloaded" packages:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | -------------------------------------------------------------------------------- Contents of _G['package']['loaded'] -------------------------------------------------------------------------------- _G: (table, same as _G) coroutine: (table, same as _G['coroutine']) debug: (table, same as _G['debug']) display: (table, same as _G['display']) io: (table, same as _G['io']) math: (table, same as _G['math']) media: (table, same as _G['media']) native: (table, same as _G['native']) os: (table, same as _G['os']) package: (table, same as _G['package']) string: (table, same as _G['string']) system: (table, same as _G['system']) table: (table, same as _G['table']) -------------------------------------------------------------------------------- Contents of _G['package']['loaders'] -------------------------------------------------------------------------------- 1: nil 2: nil 3: nil 4: nil -------------------------------------------------------------------------------- Contents of _G['package']['preload'] -------------------------------------------------------------------------------- ltn12: (function) mime: (function) mime.core: (function) socket: (function) socket.core: (function) socket.ftp: (function) socket.http: (function) socket.smtp: (function) socket.tp: (function) socket.url: (function) |
The interpretation of the following tables is left to the user:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | -------------------------------------------------------------------------------- Contents of _G['timer']['_runlist'] -------------------------------------------------------------------------------- (this table is empty) -------------------------------------------------------------------------------- Contents of _G['transition']['_activeTweens'] -------------------------------------------------------------------------------- (this table is empty) -------------------------------------------------------------------------------- Contents of _G['transition']['_nonPropertyKeys'] -------------------------------------------------------------------------------- delay: true delta: true onComplete: true onStart: true time: true transition: true -------------------------------------------------------------------------------- Contents of _G['BounceBehavior']['container']['_class'] -------------------------------------------------------------------------------- __index: (table, same as _G['BounceBehavior']['container']['_class']) addBehavior: (function) hasBehavior: (function) initProxy: (function) removeBehavior: (function) -------------------------------------------------------------------------------- Contents of _G['Runtime']['_stage']['_class'] -------------------------------------------------------------------------------- __index: (table, same as _G['Runtime']['_stage']['_class']) addBehavior: (function) hasBehavior: (function) initProxy: (function) removeBehavior: (function) -------------------------------------------------------------------------------- Contents of _G['Runtime']['_super']['_indexForType'] -------------------------------------------------------------------------------- function: '_functionListeners' table: '_tableListeners' -------------------------------------------------------------------------------- Contents of _G['Runtime']['_super']['_super'] -------------------------------------------------------------------------------- __index: (table, same as _G['Runtime']['_super']['_super']) new: (function) newClass: (function) |
Thanks for the research. Interesting.
Hello!
Now, that Corona 1.01 has been released, it's time to inspect the new environment and look out for changes.
At a first glance, the following changes were made:
_G: no more "Behavior"s, no "Generator"
_G['package']['preload']: there is a new "crypto" package
I did not find any other modifications - did I miss s.th.?
Kind regards,
Andreas Rozek
Inspection of the global table "_G" yields:
Again, any indentations were lost - that's bad...
Well, at a first glance: