Code editor made in Love2D?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
ddabrahim
Party member
Posts: 192
Joined: Mon May 17, 2021 8:05 pm
Contact:

Code editor made in Love2D?

Post by ddabrahim »

Hello all!

I've been playing around with the idea to create a very minimalistic, very simple code editor for the system I've been making in Love2D. Of course nothing is wrong with using VS Code, this is what I prefer, but I feel like if I would have an integrated code editor, it would offer a nice and easy way to create quick prototypes and jump in without any setup needed.

Would anyone have any recommendations where to start making a code editor what libraries are out there that could help me get started?
This is the primary things I need:

1. UI in general the text editing field, buttons, scroll bar..etc
2. File management, the ability to manage multiple files and read and write files inside selected directory.
3. Window management, I may would like to be able to have multiple windows open, one for the code editor and one for a preview maybe.
4. Performance in general, I did have a look at some code and text editors made in Love2D and was shared many years ago I also managed to make one using ChatGPT but most of them are really slow. Not sure if there is anything that could be done about that to make sure after X lines of code, the app does not slow down. In most cases the app slow down to the point I can enter only 1 letter every 2 seconds.

What I don't really need is autocomplete, syntax highlight and error checking, tips..etc I obviously don't want to compete with VS Code, I am only trying to create a fun and integrated experience for rapid prototyping.

Thank you.
glitchapp
Party member
Posts: 247
Joined: Tue Oct 05, 2021 10:34 am
Contact:

Re: Code editor made in Love2D?

Post by glitchapp »

Hi, I already have several projects that you may be interested on even if not all the features match your needs:
viewtopic.php?t=95818
https://codeberg.org/glitchapp/love2d-code-editor
https://codeberg.org/glitchapp/love-QWERTY-mobile
https://codeberg.org/glitchapp/Lovepad
All the projects are aimed at mobile devices and contains touch keyboards and other features aimed at touch screens, but you can easily disable those features and make a desktop version, indeed the projects were originally for desktop.

Feel free to fork them, I hope you find them useful.
User avatar
ddabrahim
Party member
Posts: 192
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Code editor made in Love2D?

Post by ddabrahim »

Thanks a lot! Really appreciate it. I’m going to have a look at them :)
User avatar
ddabrahim
Party member
Posts: 192
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Code editor made in Love2D?

Post by ddabrahim »

Okay, so I was making really good progress with integrating this code editor in to my system.

The way I have done it, is simply when I press "f5" I load the code file and my library and then run the code

Code: Select all

local file = love.filesystem.load("mycode.lua")
if file then
   love.graphics.clear()
   require "MyLib"
   file()
end
It is allow me to edit the code and run it and then return to the code editor. However, if I want to run the code once again, I get black screen. No errors, nothing just black screen.
In order to solve this, I delete all the loaded libraries from memory when I return to the code editor and reload the entire code editor.

Code: Select all

for k in pairs(package.loaded) do
        package.loaded[k] = nil
end

loadEditor()

It is solved the problem. So now I can switch back and forth between the code editor and the preview. Seemingly works perfectly.

Everything was fine until I wanted to add a UI library so I can add buttons to the code editor and what not. I decided to go with the Slab library and this is what I do.

Code: Select all

for k in pairs(package.loaded) do
        package.loaded[k] = nil
end

local Slab = require "Slab"

loadEditor()

And it does not work, because I remove all the loaded libraries before, for some reason the Slab library fail to load with the error message

Code: Select all

module 'bit' not found
Would anyone have any idea how to solve this? Either a different way to remove libs or different way to run the code from the editor?

Here is a project I prepped that demonstrate the error message with Slab:
Slab test.zip
(281.74 KiB) Downloaded 18 times
Thank you in advance.
User avatar
keharriso
Party member
Posts: 104
Joined: Fri Nov 16, 2012 9:34 pm

Re: Code editor made in Love2D?

Post by keharriso »

Only remove the package if it's not the bit library?

I'm not entirely sure why you need to remove the packages in the first place.
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
User avatar
ddabrahim
Party member
Posts: 192
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Code editor made in Love2D?

Post by ddabrahim »

Thanks. I have tried to remove the package only if its not the bit library but it did not worked.

I also uncertain why I need to remove the packages. I am sort of aimlessly messing around with integrating a code editor in to my system so I can sort of code in-game.

So basically what is happening when I run the code the first time and load my lib, everything works. But then if I return to the code editor and try to run the code again, it is no longer works. Removing the packages when I return to the code editor solve this problem.

But then I have this problem with the UI library fail to load.
User avatar
ddabrahim
Party member
Posts: 192
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Code editor made in Love2D?

Post by ddabrahim »

Oh, I managed to get it sorted it seems. The solution was that indeed to remove packages only if it's not the "bit" library but I have done it wrong. This is how I had to do it:

Code: Select all

for k in pairs(package.loaded) do
        if k ~= "bit" then 
                package.loaded[k] = nil
        end
end
I think that the reason I need to remove the packages is that when I load my library then I initialise it with some default values but then the code I execute change these default values. So the second time I attempt to run the code, my library no longer loaded because already loaded and no longer initialised and stop working because of this. Removing the package and reload it solve this it seems because then my lib initialised with the proper values.

Guess I could improve it by only remove my package instead of all the packages with the exception of "bit".

I didn't touched Lua and my system for months, practically I have no idea what am I doing.
But for now, it seems I have this particular problem solved and I have the UI library loaded in to the code editor.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests