Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
What it is
Back2BASIC is a library that allows you to have all the functions you loved in BASIC. This will help BASIC programmers switch to lua, as well as making it more straightforward to port BASIC programs to lua.

Already implemented
- b2b.menu (a prefabricated menu function)
- b2b.printText (like "HELLO" in BASIC, but with LESS-style page breaks)

To be implemented
- a graphing function
- Locate

Make a folder called "lib" in your root directory. Put b2b.lua in this folder.
In the program you wish to use the library, put run([[lib\b2b.lua]]) at the top.

Function syntax
NOTE: all width, height, x, and y values are not pixels, but characters.
b2b.menu(x, y, width, height, title, array, color1, color2)
b2b.printText(string, colorfg, colorbg)

See "Known Bugs"





b2b.menu = function (x, y, width, height, title, array, color1, color2)
   local x=x*18-18
   local y=y*18-18
   local continue=0
   local selected=1
   local max=height
   local j=1
   while continue==0 do
      --handle keys
      if key==28 then
         if selected>1 then
            if selected<max-height+1 then max=selected+height-1 end
      if key==37 then
         if selected<#array then
            if selected>height then max=selected end
      if key==31 then
      --draw menu
      zmg.drawRectFill(x+1, y+18, width*12, height*18, color2)
      zmg.drawText(x+1, y+1, title, color2, color1)
      for i=max-height+1, max, 1 do
         if selected==i then
            zmg.drawText(x+1, y+(j*18), array[i], color2, color1)
            zmg.drawText(x+1, y+(j*18), array[i], color1, color2)
      --refresh screen
      if continue~=1 then key=zmg.keyMenu() end
   return selected

b2b.printText = function (string, colorfg, colorbg)
   local substring={}
   local k=1
   --if string extends past screen end (x)
   if #string>31 then
      --split string into screen width sized portions
      for i=1, math.floor(#string/31)+1, 1 do
         substring[i] = string.sub(string, i*31-30, i*31)
   for j=1, math.floor(#substring/11)+1, 1 do
      --clear screen
      zmg.drawRectFill(0, 0, 384, 216, colorbg)
      for i=j*11-10, j*11, 1 do
         if substring[i] then zmg.drawText(1, k*18-18, substring[i], colorfg, colorbg) end
      zmg.drawText(1, 198, "Press a key (Page " .. j .. "/" .. math.floor(#substring/11)+1 .. ")", colorbg, colorfg)




test = b2b.menu(1, 1, 15, 5, "Demo", {"display text","entry2","entry3","entry4","entry5","entry","entry","entry","entry"}, zmg.makeColor("blue"), zmg.makeColor("black"))

teststring="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porttitor, sapien quis sagittis sodales, metus felis faucibus sem, eget mollis erat dolor non elit. Cras id nibh vel massa auctor euismod. Fusce semper rutrum neque, ut faucibus lacus egestas at. Donec velit augue, pulvinar sit amet vulputate et, consectetur iaculis neque. Quisque eu enim eu est condimentum feugiat. Duis gravida ultrices elit ac malesuada. Sed dui sapien, hendrerit nec mattis in, viverra sit amet nibh. Donec vel sodales risus. Duis facilisis cursus placerat. Donec sed ligula sed odio mollis posuere. Integer ante sapien, cursus eu eleifend in, tristique vehicula arcu. Fusce vel erat nibh, non placerat quam. Vivamus quis nibh ut est rhoncus faucibus et vestibulum elit. Pellentesque vel dui eget leo varius faucibus a ac mi. Nulla a nulla non enim euismod ornare a non mauris. Proin ut sagittis turpis. Maecenas in sem tellus, sit amet placerat ligula. Praesent non augue tellus, a convallis lacus. Curabitur suscipit consectetur aliquet. Nunc vehicula lorem in odio accumsan a placerat neque aliquam. Etiam ultricies orci eu justo dapibus vel elementum libero fermentum. Donec et risus nisi, non pulvinar nunc. Duis quis sem neque. Ut eu dignissim nisl. Maecenas a nisl risus, sed consequat ante. Morbi vitae imperdiet erat. Suspendisse potenti. In urna est, viverra id hendrerit vel, pulvinar eget felis. Donec suscipit, dui ac molestie molestie, mi orci scelerisque mi, quis cursus mi metus eget nibh. Aliquam commodo mi at eros sagittis dictum. Nunc ultrices turpis eu urna luctus dictum. Cras sollicitudin ante quis metus aliquet rutrum. Nam vestibulum velit commodo risus ornare eu varius sem placerat. Maecenas egestas odio eu mi tincidunt in porttitor lorem consequat. Proin libero risus, venenatis ut suscipit et, varius non sapien. Suspendisse eget elementum dolor."

if test==1 then b2b.printText(teststring, zmg.makeColor("blue"), zmg.makeColor("black")) end

Known Bugs
- All the functions use zmg.keyMenu(), so it should be possible to use Screen Record to record the program. However, if you run them while in ScreenRecord mode, your calc will crash with the "SYSTEM ERROR" message.

- running demo.lua twice in a row gives an error starting with "demo.lua:1:syntax error near <eof>"
OK, I made a git repo for this, and added a couple functions (read the readme).
Added b2b.inputString()
hello , do you can write a example of use to b2b.inputString() thanks

I have probles beacuse LuaZM says "not enough memory" with a two lines program
mi program have:


b2b.inputString("only numbers")
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum