MiniIDE: live code inside a LOVE app

Showcase your libraries, tools and other projects that help your fellow love users.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

MiniIDE: live code inside a LOVE app

Post by SugarRayLua »

Hello, LÖVE Community, we’d like to introduce “MiniIDE”!

MiniIDE was created so that developers can live-code LÖVE scripts inside of LÖVE itself. Its initial target was mobile iOS developers who lack options to live-code Love2D on their devices, but it has been tested on Windows, MacOS, Linux, iOS (iPad) and Android (tablet). We are grateful to the developers of Lua, LÖVE and the libraries love-console, Slab and native-fs. MiniIDE is built upon all their work.

MiniIDE comes with a console (bottom of the screen), a terminal (left hand side of the screen), and a resizable/movable mini-text editor.

MiniIDE has the ability to load and save lua scripts, and call its own LÖVE callback loops and return back to the editor from them.

MiniIDE is also able to render graphics commands directly from the MiniIDE screen to allow easy experimentation with the love.graphics API. One can even use the included Slab GUI library to create GUIs from one's script inside MiniIDE.

Note:
If you wish to break out of scripts that you run in MiniIDE that use LÖVE callbacks (e.g. love.update or love.draw), we’ve programmed into MiniIDE (using `xpcall`) to intercept any error in your script (e.g. if you call `error()`) and return you back to the MiniIDE editor when miniIDE encounters that code. For your convenience, we included a simple `escape()` function you can call in your script that calls `error()` and that can be inserted into the end of your script by pressing the “Stop Code” button in the Editor.

Limitations:
Cannot use the `love.run` or `love.load` callbacks in your scripts (used by MiniIDE)

No warnings yet if you forget to save editor contents.

Directory for storing scripts is currently set to the Source Base Directory (which contains the MiniIDE.love file--user could easily change in the program's code).

Acknowledgements:
MiniIDE includes the following libraries with grateful thanks:

love-console: https://github.com/rameshvarun/love-console

Slab: https://github.com/flamendless/Slab

nativefs: https://github.com/EngineerSmith/nativefs

We welcome any feedback you may have on MiniIDE and hope you enjoy using it and find it helpful :-)
------------------------------------------------------------------
YouTube MiniIDE Video:

IMG_1501.png
IMG_1501.png (266 KiB) Viewed 20064 times
MiniIDE-ae.love
(293.04 KiB) Downloaded 462 times
Last edited by SugarRayLua on Mon Sep 04, 2023 1:06 am, edited 1 time in total.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: MiniIDE: live code inside a LOVE app

Post by SugarRayLua »

Update:
MiniIDE-af release below adds the ability of MiniIDE to recognize additional white spaces and nested () inside love.graphics commands

We'd especially appreciate feedback from Android users as to how we could better optimizing MiniIDE for Android use. Thanks!
------------
MiniIDE-af.love
(294.47 KiB) Downloaded 408 times
User avatar
Kartik Agaram
Prole
Posts: 34
Joined: Fri Apr 01, 2022 4:46 am

Re: MiniIDE: live code inside a LOVE app

Post by Kartik Agaram »

One new thing inside the latest version is a list of manual tests that we're using before publishing new versions of MiniIDE. It might be useful also to others, to get a sense of the kinds of LÖVE apps you can build from within MiniIDE. Here it is:
How we the creators expect MiniIDE to behave in a few different scenarios
  1. Typing in an expression involving constants into either the console (bottom line on screen) or editor evaluates it and prints the result in the console (above the bottom line on screen).

    Code: Select all

     > 1+1
     2
    
    In editor:

    Code: Select all

    1+1
    ..and hit 'Run'
  2. Typing in graphics involving constants into either the console or editor shows them on screen.

    Code: Select all

    > love.graphics.line(100,100, 200,300)
    You should see a line on the screen, potentially drawing over text in the console.
  3. Typing in an expression involving variables into either the console or editor works as usual.

    Code: Select all

    > x = 1
    > x+1
    2
    
    In editor, type:

    Code: Select all

    x = 1
    
    and hit 'Run'

    Then clear editor and type:

    Code: Select all

    x+1
    and hit 'Run' again.

    You can't put both statements into the editor at once. That would be like typing `x = 1; x+1` into the console or any Lua prompt. (Which also wouldn't work.)
  4. Drawing graphics involving variables will work in either the console or editor.

    Code: Select all

    x = 100
    love.graphics.line(x,x, 200,300)
    
    The console requires blocks to all be on a single line, though:

    Code: Select all

    > function foo()
    
    If you hit enter now you'll see an error. You can define functions if they're all on one line.

    Code: Select all

    > function foo() return 42 end
    
    You're probably better off putting function definitions in the editor.
  5. However, graphics only work when they fit a specific pattern. This doesn't work (known bug):

    Code: Select all

    lg = love.graphics
    lg.line(100,100, 200,300)
    
  6. For more complex graphics, override `love.draw`:

    Code: Select all

    lg = love.graphics
    
    function love.draw()
        lg.line(100,100, 200,300)
    end
    
    However, once you hit 'Run' you're running a whole new app, and you'll have no way to go back to MiniIDE. (intended behavior)
  7. To return to MiniIDE, override some event to `escape()`:

    Code: Select all

    function love.draw()
        love.graphics.line(100,100, 200,300)
    end
    function love.keypressed(key)
        escape()
    end
    
    Now press the 'Stop Code' button. It will insert some code into the editor so it looks like this:

    Code: Select all

    function love.draw()
        love.graphics.line(100,100, 200,300)
    end
    function love.keypressed(key)
        escape()
    end
    function escape()
        error('StopScript')
    end
    
    Now press 'Run' to see a new app draw a line across the whole screen. Press any key to return to MiniIDE.
  8. You can also create an app that includes MiniIDE, like this:

    Code: Select all

    lg = love.graphics
    
    if old_love_draw == nil then
        old_love_draw = love.draw
    end
    
    function love.draw()
        old_love_draw()
        lg.line(100,100, 200,300)
    end
    
    This will look just like scenario 2 above, but it has more room to grow. You can take over other event handlers from MiniIDE like `love.keypressed` or `love.mousepressed`, and you can add rules before or after them. Any errors will put you back in MiniIDE without your app additions. For example, if you edit it to look like this:

    Code: Select all

    lg = love.graphics
    
    if old_love_draw == nil then
        old_love_draw = love.draw
    end
    
    function love.draw()
        old_love_draw()
        lg.line(100,100, 200,300)
    end
    
    function love.keypressed()
        print(y+1)  -- error: y is nil, and you can't add 1 to nil
    end
    
    Hit 'Run', then press a key. The key will have no effect, and you'll see an error like this in the log:

    Code: Select all

    Error: [string "lg = love.graphics..."]:13: attempt to perform arithmetic on global 'y' (a nil value)
    
    However, future keypresses (without hitting 'Run' again) will work. Your app has been 'deregistered', and things have gone back to pristine MiniIDE. Now you can fix the error and try hitting 'Run' again.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: MiniIDE: live code inside a LOVE app

Post by SugarRayLua »

The following release uses a menu-driven GUI for those who might prefer a more minimalistic look and would like more screen space.

The release also contains a "Rotate device" feature for Android users. You can still use control-c and control-v to transfer text to and from the clipboard.
-----------------
IMG_1525.png
IMG_1525.png (191.92 KiB) Viewed 19347 times
------------------
MiniIDE-am.love
(290.52 KiB) Downloaded 423 times
User avatar
ddabrahim
Party member
Posts: 201
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: MiniIDE: live code inside a LOVE app

Post by ddabrahim »

Interesting project. One small problem I have immediately faced. If I implement my own love.draw callback and run it, it is clear the entire screen, get rid of all the menus including the option to stop the code. I would setup a key, maybe the Escape key traditionally to stop the code from running when pressed.

But even if I just run the code love.graphics.print()
It is print over the menu.

I think there should be a boundary to draw maybe using a separate canvas to keep the menu always visible.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: MiniIDE: live code inside a LOVE app

Post by SugarRayLua »

Thanks, @ddabrahim, for checking out the project and offering your suggestions!

A separate canvas is a great idea.

We thought about a separate "escape" key to exit out of your running code but initially decided to let folks programmatically decide what they want to use to escape (e.g. a certain key or mouse click). We've tried to make it easy on programmers by including the following brief escape function that you can add to your project with callbacks by pressing (or selecting) the "stop code" button or menu selection which will insert:

```
function escape()
error("StopScript")
end
```

(i.e. the "stop code" button doesn't actually stop the script from running but rather provides you with default code to stop the script).

Then from whatever trigger you like in your script you can just call "escape()" and the project will exit back to the main editor. If you then wanted to use the same script outside of MiniIDE you could then perhaps just substitute "love.event.quit()" for the "escape" call.

*For more concise code, alternatively you can just call "error()" from a trigger anywhere in your code to get your running code to stop and return to the editor.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: MiniIDE: live code inside a LOVE app

Post by SugarRayLua »

Hello, LOVE2D Community.

We've updated MiniIDE to make it easier to use on mobile devices (iOS and Android tablets) with on-screen keyboards. Desktop users and those with mobile devices and an external keyboard have more screen space.

Release notes:
1. Type commands at top of window so that it isn't covered by the keyboard on touchscreens.
2. New menu entries for copy and paste, increase/decrease console font size
3. Clear graphics as well when clearing console
4. Some bugfixes to drawing graphics without overriding love.draw

Note: Editor window is resizable by selecting and dragging window borders (although a bit more difficult to do so by touch).

We welcome your further feedback and suggestions for the project.

Screenshots on iOS (iPAD) below:
----------------------
IMG_1551.png
IMG_1551.png (265.6 KiB) Viewed 18554 times
IMG_1552.png
IMG_1552.png (256 KiB) Viewed 18554 times
IMG_1553.png
IMG_1553.png (263.05 KiB) Viewed 18554 times
IMG_1554.png
IMG_1554.png (282.61 KiB) Viewed 18554 times
-----------------------
MiniIDE-au.love
(296.56 KiB) Downloaded 401 times
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Re: MiniIDE: live code inside a LOVE app

Post by SugarRayLua »

New release, primarily with improvements for mobile tablet use:

Major changes:
* Windows are easier to resize, especially on a tablet.
* Scrollbars are easier to drag around, especially on a tablet.

-------------------
MiniIDE-bb.love
(296.79 KiB) Downloaded 407 times
zhengying
Prole
Posts: 6
Joined: Tue Nov 02, 2021 1:35 pm

Re: MiniIDE: live code inside a LOVE app

Post by zhengying »

It's interesting if the editor has an autocomplete feature; it would be more useful. It could even have a document embedded for users to look up the API.
pauljessup
Party member
Posts: 356
Joined: Wed Jul 03, 2013 4:06 am

Re: MiniIDE: live code inside a LOVE app

Post by pauljessup »

This is really handy...
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests