Easy class function self. Code generation+customized project icon

I wrote this to help me write class code.

Hope you like it.

It also includes a function to create your own icon for the CODEA project home page.

-- ClassHelper

--BACKUP original

--[[
Use function INITSELFS(tabName,className,classFuncName,parameters) to generate
in tab tabName
function className:classFuncName(x)
    self.x=x or 0 --  comments
end

from the long string
parm name : what goes after
x: or 0 --  comments
in 
end
  ]]
displayMode(FULLSCREEN)
function setup()
    saveProjectInfo("Description","Class CODEA Generation for CODEA Enlightenment")
    saveProjectInfo("Author","CODING ON NAPKINS")
    setProjectIcon("GENERATE self.x=x"
                        .."\
class code  helper\
"
                        ..os.date()
                        .."\
for Codea Enlightenment\
by Coding On Napkins"
                        .."\
Understanding\
Codea using Codea")
    PatternLUAName="[_%w][_%w%d]*"
    
    
-- CHANGE THESE FOR YOUR OWN NEEDS     
    INITSELFS("newCode","BOX","init", -- string in [[  ]] gives parm names
[[
BOXTitle:or "Empty Title" -- comments
x: or 0
y: or HEIGHT/2
table:{a,b,c,d=e}
]]
    
) -- end INITSELFS call
    

end

function draw()
    background(223, 172, 172, 255)
    textMode(CORNER)
    text("check new tab for code to copy  paste where you need it",50,HEIGHT/2)
end


-- sets up a class function className:classFuncName(
-- and sets up self.p=p for parm in parameters
function INITSELFS(tabName,className,classFuncName,parameters)
    local f = "--[====[ created by INITSELFS written by Coding On Napkins"
    .."\
function "..className..":"..classFuncName.."("
    local selfs=""
    for k,v in string.gmatch(parameters,"("..PatternLUAName..")%:(.-)\
") do
        f=f..k..","
        selfs = selfs.."self."..k.." = "..k.." "..v.."\
"
    end
    saveProjectTab(tabName,f..")\
"..
            selfs.."end -- function "..className..":"..classFuncName.."\
]====]")
end

-- set icon for project
function setProjectIcon(icontext)
    pushStyle()
    local iconsize=350 
    local img = image(iconsize,iconsize) -- or 350 on retina, 175 non-retina
    setContext(img)
    fill(3, 253, 90, 255)
    stroke(0, 50, 255, 255)
    noStroke()
    rectMode(CORNER)
    rect(0,0,iconsize,iconsize)
    fill(0, 0, 0, 255)
    textAlign(CENTER)
    font("HelveticaNeue-CondensedBold")
    fontSize(25)
    textMode(CENTER)
    text(icontext,iconsize/2,iconsize/2)
    saveImage("Project:Icon", img)
    setContext()
    popStyle()
end

it looks nice, i havent tried it, your code may be too formal for me.

@firewolf @Simeon

here is a version with more comments

it also copies the generated code to the pasteboard so you can paste it directly into your project.

With care you can put these functions into your code so you don’t have to switch projects to use

I update the icon text for WORKING and BACKUP 150321am0940
so I can easily backup a project using duplicate by adding date to end of
project name, copy the backup name, paste it into the second line of Main
and adjust the icon from WORKING to BACKUP 150321am0940.

Instant documentation at a glance from CODEA home screen!

I hope this makes coding easier.

Coding On Napkins working on CODEA Enlightenment

-- ClassHelper

--[[
This project generates code to be put into a CODEA class definition

Use function INITSELFS(tabName,className,classFuncName,parameters) to generate
in tab tabName
function className:classFuncName(x)
    self.x=x or 0 --  comments
end

from the long string
parm name : what goes after
x: or 0 --  comments
in 
end
  ]]
displayMode(FULLSCREEN)
function setup()
    saveProjectInfo("Description","Class CODEA Generation for CODEA Enlightenment")
    saveProjectInfo("Author","CODING ON NAPKINS")
-- setProjectIcon replaces the default codea icon your own custom icon
-- see code for how to change colors, font(),fontSize(), etc.
    setProjectIcon("sent to forum 150320\
GENERATE self.x=x"
                        .."\
class code\
"
                        ..os.date()
                        .."\
for Codea Enlightenment\
by Coding On Napkins"
                        .."\
Understanding\
Codea using Codea")
    PatternLUAName="[_%w][_%w%d]*"
    
-- CHANGE THESE FOR YOUR OWN NEEDS     
    INITSELFS("WhereCodePut","BOX","init", -- string in [[  ]] gives parm names
[[
Title:or "Empty Title" -- comments
Text:or {"No Text Given"}
x: or 0
y: or 0
w: or WIDTH
h: or HEIGHT
]]
) -- end INITSELFS call
-- THIS IS THE CODE GENERATED, copied to pasteboard and tab you named in call
--[====[ created by INITSELFS written by Coding On Napkins
function BOX:init(Title,Text,x,y,w,h)
	self.Title = Title or "Empty Title" -- comments
	self.Text = Text or {"No Text Given"}
	self.x = x  or 0
	self.y = y  or 0
	self.w = w  or WIDTH
	self.h = h  or HEIGHT
end
]====]   

end

function draw()
    background(255, 255, 255, 255)
    textMode(CENTER)
    text("Code generated:\
\
"
            ..codeGenerated
            .."\
\
is on pasteboard to paste into your code"
            .."\
and in tab "..wheregeneratedcodegoes
            .."\
\
touch screen to return to editor",WIDTH/2,HEIGHT/2)
end

function touched(touch)
    close()
end

-- sets up a class function className:classFuncName(parms)
-- and sets up self.p=p for parm in parameters
function INITSELFS(tabName,className,classFuncName,parameters)
    wheregeneratedcodegoes=tabName
    local func = "function "..className..":"..classFuncName.."("
    local selfs=""
    for k,v in string.gmatch(parameters,"("..PatternLUAName..")%:(.-)\
") do
        func = func..k..","
        selfs = selfs.."\\tself."..k.." = "..k.." "..v.."\
"
    end
    func=string.sub(func,1,-2) -- remove last comma in parameter list
    codeGenerated=func..")\
"..selfs.."end"
    pasteboard.copy(codeGenerated) -- make code copying easy by putting code on clipboard
    saveProjectTab(tabName,
            "--[====[ created by INITSELFS written by Coding On Napkins\
\
"
            ..codeGenerated
            .."\
\
]====]")
end

-- set icon for project
function setProjectIcon(icontext)
    pushStyle()
    local iconsize=350 
    local img = image(iconsize,iconsize) -- or 350 on retina, 175 non-retina
    setContext(img)
    fill(3, 253, 90, 255)
    --stroke(0, 50, 255, 255)
    noStroke()
    rectMode(CORNER)
    rect(0,0,iconsize,iconsize)
    fill(0, 0, 0, 255)
    textAlign(CENTER)
    font("HelveticaNeue-CondensedBold")
    fontSize(25)
    textMode(CENTER)
    text(icontext,iconsize/2,iconsize/2)
    saveImage("Project:Icon", img)
    setContext()
    popStyle()
end

Sweet?its a good idea. Your code help me with studying, actually i like the idea of making CODEA programs easier to read and create.