Wiki
Clone wikiCore / debug.getinfo
Back to Beyond the Codea in-app reference
debug.getinfo() function
The debug.getinfo()
function is part of one of Lua's standard libraries that is available in Codea.
debug.getinfo(1).source
debug.getinfo(1)
returns a table with information about the function that called getinfo()
.
That table includes a field source
that refers to a string of the code in the tab in which getinfo()
was called.
For example, the first tab of a Codea project could include this code:
local code = "" -- Will hold the code captured from each tab
function captureTab(tabName, tabCode)
if #code > 0 then code = code.."\n\n" end
code = code.."--\n-- "..tabName.."\n--\n" -- Add the name of the tab
code = code...string.match(tabCode.source, ".-%-%-%-%-\n(.*)") -- Remove the 'header'
end
function saveCode(key)
saveGlobalData(key, code) -- Save the code in Codea's global storage
end
The following code can then can be added to the top of each tab that is to be preserved in the global storage. The end of this code 'header' is marked by ----
:
captureTab("Name for the tab", debug.getinfo(1))
----
-- Rest of code in tab...
The code is then preserved in global storage by calling in setup():
function setup()
...
saveCode("ProjectName")
...
end
Updated