Advertisement
Kleadron

Interface System program sketch

Feb 24th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. -- CONCEPT/SKETCH, NOT FINAL
  2. local handles = {} -- Interface System applications are formatted as tables, like almost everything in lua.
  3.  
  4. handles.intsys = true -- This is indeed an Interface System program. This might not actually be very useful.
  5. handles.sysver = 0    -- Intended system version, fails if it's higher.
  6.  
  7. local window = nil
  8.  
  9. local bananaText = "Banana"
  10. local function onBanana() bananaText = "No more banana" end
  11. local function getBananaText() return bananaText end
  12.  
  13. -- Main function, this is executed as a coroutine. Instead of using os.sleep, you will do coroutine.yield
  14. function handles.main()
  15.    
  16.     window = intsys.makeWindow() -- Creates the window with all of its preset functions.
  17.     window.title = "Hello Mario." -- if nil then the window is drawn with no title.
  18.    
  19.     -- Enables/disables the button on the titlebar.
  20.     window.canClose = true
  21.     window.canResize = true
  22.    
  23.     window.setSize(100, 100)
  24.    
  25.     -- window.add will add a control to the list of controls for the window.
  26.     -- A control is a table of.. functions and stuff.
  27.     -- If formatted correctly, you can make your own!
  28.    
  29.     -- A generic persistant text control, that just draws text on redraw.
  30.     window.add(window.makeText(5, 5, "Hello Luigi."))
  31.     -- Buttons take a function reference to execute, if not nil.
  32.     window.add(window.makeButton(5, 20, "Banana", onBanana))
  33.    
  34.     -- These controls can use functions to get their text from as well.
  35.     -- This marks it as an "active" control. When windows redraw, the function is ran.
  36.     window.add(window.makeText(5, 30, getBananaText))
  37.     -- If you wanted the button to change its text for example
  38.     --window.add(window.makeButton(5, 20, getBananaText, onBanana))
  39.    
  40.     -- These controls most likely lack features that will be present later on.
  41.     -- It is possible there will be handles to the window such as "update" and "redraw".
  42.    
  43.     -- Adds the window to the internal list, so it is updated and redrawn, etc. Marks "exists" as true.
  44.     intsys.registerWindow(window)
  45.    
  46.     -- Infinite looping program, this is usually how you would do your update logic.
  47.     -- window.exists returns false if the window no longer is registered. You can probably re-register it if you wanted to.
  48.     -- After the coroutine is no longer valid, Interface System will automatically de-list the program.
  49.     while window.exists do
  50.         coroutine.yield()
  51.     end
  52.     -- De-init down here if necessary.
  53. end
  54.  
  55. return handles -- Returns the program's handles back to Interface System.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement