creating an ide

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

creating an ide

Post by Doctory »

hello everyone :)
i was wondering if it was possible to create an ide using lua and love2d.
i would like some of the following things:

-syntax highlighting for lua + love2d
-project tree
-saving and loading
-(edit) getting the current open file

how would i do that? im really interested in syntax highlighting and saving and loading, the project tree isnt neccessary but it would be good if you could explain that as well.

thanks ^^
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: creating an ide

Post by ivan »

Sure, with a lot of work it is possible but in IMO it would not be very useful.
For starters, you would need a stable and robust "textarea"-like UI object.
Apart from the UI programming, there are many little things like handling various file encodings, copy/paste via the clipboard, keyboard input layouts and so on.
For syntax highlighting, you would need a simple Lua language parser.
All of the features you mentioned are available in Notepad++.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: creating an ide

Post by kikito »

Also last time I checked LÖVE was not exactly super fast when rendering text, which could give you trouble (last time I checked this was some time ago, so it might have changed).

If you are interested in using Lua to code an editor, you could give a look at textadept. For full-fledged IDEs, Zerobrane Studio is worth a look. I don't know the exact percentage of Lua code vs native code on these projects, but I've heard it's significant. neovim is also worth noting out; one of its aims is replacing VimL in vim with Lua.
When I write def I mean function.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: creating an ide

Post by Doctory »

i dont need an ide, i got one already, but im intersted in making one.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: creating an ide

Post by kikito »

I was not pointing to those so you could use them. I was pointing to them so you could look at their source code and learn from them - to scratch that itch.
When I write def I mean function.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: creating an ide

Post by Doctory »

kikito wrote:I was not pointing to those so you could use them. I was pointing to them so you could look at their source code and learn from them - to scratch that itch.
ah, thanks.
User avatar
rok
Prole
Posts: 36
Joined: Wed Dec 24, 2014 9:12 am
Location: Slovenia

Re: creating an ide

Post by rok »

@kikito Thanks for mentioning textadept. Never heard of it before. Looks great :awesome:
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: creating an ide

Post by Positive07 »

I was considering this idea, my conclusion:

The worst part is the text area control... why? Well textareas have quite a bunch of features:
  1. Cursor:
    • To move the cursor when the the user click you need to get in which character of the text the cursor is. To do this you need to calculate the line where the user clicked (this can be done with the y coordinate of the mouse and the line height), then calculate the character position (with something like Font:getWrap and the x coordinate of the mouse)
    • The cursor also moves with the arrows keys and whenever a character is added. This is easy, just increment or decrement the pointer
    • Characters are added at the cursor position, you can do this with string.sub and concatenation
    • Pressing the up or down arrow keys and moving up to a similar position in the line above, this is really hard too, maybe with a method similar to the mouse cursor.
  2. Selecting text:
    • This is the hardest, dragging the mouse while the left click is pressed, selects a bunch of text, to do this you can get the first cursor with the same method described above, and then have a second cursor which is dynamic (while the mouse is still pressed) and after the click is released get the selection.
    • Selections are also modified when the shift key is pressed and an arrow is pressed.
    • If you move to the left or right the selection is unselected.
    • When you press a key, the selection gets replaced.
    • forget about complicated things like tabulating the selection when tab is pressed or such.
Followed by this you have syntax highlighting, to do this, you need a parser as said by Ivan, this should parse the whole document and split the different zones, lets said you have this text:

Code: Select all

function    (a)
    a = {"Hello",123}
end
The parser should return a table like:

Code: Select all

line[1]={
    {"function",type="function"};
    {"    "};
    {"(",type="operator"}
    {"a",type="none"}
    {")",type="operator"}
}
line[2]={
    {"    a ",type="none"}
    {"= ",type="operator"};
    {"{",type="table"};
    {"\"Hello\"",type="string"}
    {",",type="operator"}
    {"123",type="number"}
    {"}",type="table"}
}
line[3]={
    {"end",type="function"}
}
There are many of this things, an example is LPeg which I dont like and needs a C library to work, but is commonly used for this tasks.

You dont need to parse the file on every update, since most of it will be unchanged, just parse the lines that where modified when a character is input or a selection is deleted. But again, you dont need to parse the whole file, just the part that changed

Then you need to interpret the parser output and print it to the screen, with the appropriate fonts and colors. Also you need to know how much width each word uses so that they are correctly separated. For that you could turn that table into something a library like Robyn's richtext library understands, and leave the printing work to it.

I may suggest you frustum-cull this text, because as Kikito said, printing to the screen is an expensive function when doing it so many times, so you will need to know which parts of the text should be displayed and which ones are not needed so you dont waste time printing unseen text.

You will also need a scrollbar. That was the first thing I did, because it is lot of math, It is in one of my repositories (Fruit), you can use it if you want

Copying and pasting was made easier with the new love.system functions ([g/s]etClipboard()) so there is nothing to worry over there.
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: creating an ide

Post by Robin »

Positive07 wrote:Robyn
:huh:

:P
Help us help you: attach a .love.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: creating an ide

Post by Positive07 »

Dont know how I could make that mistake... I may have been asleep hahaha... I'm sure I wrote Robin!!
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests