PasteBoard Run - Test forum projects on the fly

This is a simple little project that allows you to copy code and upon rentering codea the project is ran. I’ve been using it to test out project without having to create a project to store the code in.

I had wrote then when testing 2.0 in beta so I havent put any time into tracking down bugs.

Codea Community Link


--# Main
-- PasteBoard Run

-- Use this function to perform your initial setup
PasteBoard = {}
PasteBoard.cTime = tonumber(os.date("%S"))
PasteBoard.code = ""

function setup()
    print("Copy any valid project and re-enter Codea")
    PasteBoard.o_setup()
    PasteBoard.runCode()
    
end

-- This function gets called once every frame
function draw()
    local t = tonumber(os.date("%S"))
        if t - PasteBoard.cTime >1 then
        PasteBoard.runCode()
        end
        PasteBoard.cTime = t
    -- This sets a dark background color 
    

    -- Do your drawing here
    
end

PasteBoard.o_setup = function()
    parameter.clear()
    output.clear()
    parameter.action("Open Browser",function() PasteBoard.resetProject() openURL("http://codea.io/talk",true) end)
    parameter.action("Reset Project",PasteBoard.resetProject)
end

PasteBoard.resetProject = function()
        PasteBoard.cTime = tonumber(os.date("%S"))
        draw = function() 
            background(0,0,0,255)
            local t = tonumber(os.date("%S"))
            if t - PasteBoard.cTime >1 then
                PasteBoard.runCode()
            end
            PasteBoard.cTime = t
        end
        touched = function() end
        keyboard = function() end
        PasteBoard.o_setup()
end

PasteBoard.runCode = function()
    PasteBoard.code = pasteboard.text
    local run = loadstring(PasteBoard.code.."setup()")
    if pcall(run) then 
        print("Project Loaded")
    else
        print("Error in pasteboard code.") 
    end
    
end




Briar fox… This is amazing. I can’t tell you how many projects I’ve made to put forum code in…my entire life just changed

@Monkeyman32123 Glad you find it useful. I always open up the project when I’m browsing the forums. I’d like to add a save feature but with the inability to create projects from code, I’m not sure it would be of much use.

@briarfox cool!
the line below has an error ("). Once corrected it works.

    parameter.action("Open Browser",function() PasteBoard.resetProject() openURL("http://codea.io/talk",true) end)

(also: when correcting, autocompletion adds an erroneous end which has to be removed)

Thats odd i do not have that issue on my end. Must be the use of < pre > tags? Yup changing to three (~) fixed it.

You can either leave Codea to copy Code or use the codea browser.