« Return to Thread: Success at last....getting my feet wet with Plua, with special thanks to Berkant

Re: Success at last....getting my feet wet with Plua, with special thanks to Berkant

by jimmy joe jack :: Rate this Message:

Reply to Author | View in Thread

--- In plua@..., Dado Sutter <dadosutter@...> wrote:

>
> Welcome to the never ending show of pLua :)
>    Please share your code if you can.
>    I might be able to offer to host a User's Wiki for pLua if you all think
> this can be useful. It would be driven by
> Sputnik<http://sputnik.freewisdom.org/>(100% Lua) and it might help to
> concentrate pLua resources, code examples
> and free aplications.
>    I cannot guarantee to much time to maintain it though but the very nature
> of a wiki should be the answer for this, if enough folks help.
>    What is the best/main source of information, code examples and repo for
> pLua today ?
>
> Best of all
> Dado Sutter
>
>
>
Below is the code, brutish though it is. Still has Berkant's comments in places, I just converted his example to palmdoc and tweaked it to make it do what I wanted. A user wiki would be great. There really isn't much out there for this language beyond the basic documentation...of nothing else a nice repository of examples would be nice.

-- **Retrieves previously written files **

savState={}
f,recs =io.open("db:/savState", "r")

-- note that arrays are indexed starting from 1!!!
-- but file recs index starts with 0 !


for i=0,recs-1 do
f:openrec(i)
data = f:read("*a")
table=bin.unpack("SBBB", data)
savState[1]=table[1]
savState[2]=table[2]
savState[3]=table[3]
savState[4]=table[4]
f:close()
end


screen.clear()
gui.title("College Checklist")
screen.moveto(0,40)
faCheck = gui.checkbox( "Financial Aid" )
screen.moveto(0,80)
claCheck=gui.checkbox("Classes Scheduled")
screen.moveto(0,120)
boCheck=gui.checkbox("Books Purchased")
screen.moveto(0,160)
woCheck=gui.checkbox("Work Schedule Fixed")
screen.moveto(150,280)
doneBut=gui.button("Done?")

gui.setstate(faCheck,savState[1])
gui.setstate(claCheck,savState[2])
gui.setstate(boCheck,savState[3])
gui.setstate(woCheck,savState[4])


function saveEnd()

faState=1
claState=2
boState=3
woState=4


savState = {}
savState[1]=gui.getstate(faCheck)
savState[2]=gui.getstate(claCheck)
savState[3]=gui.getstate(boCheck)
savState[4]=gui.getstate(woCheck)


os.remove("savState")

-- check for packing string format in Plua.doc

-- write to file in RAM

f=io.open("db:/savState", "r+")
data = bin.pack("SBBB", savState)
index = f:createrec(string.len(data))
f:openrec(index)
f:write(data)
f:close()
os.exit()
end

while true do
ev,id=gui.event()
if ev==appStop then break end
if ev==ctlSelect and id==doneBut then saveEnd()
end
end






 « Return to Thread: Success at last....getting my feet wet with Plua, with special thanks to Berkant