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
creating an ide
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: creating an ide
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++.
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++.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: creating an ide
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.
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.
Re: creating an ide
i dont need an ide, i got one already, but im intersted in making one.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: creating an ide
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.
Re: creating an ide
ah, thanks.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.
Re: creating an ide
@kikito Thanks for mentioning textadept. Never heard of it before. Looks great
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: creating an ide
I was considering this idea, my conclusion:
The worst part is the text area control... why? Well textareas have quite a bunch of features:
The parser should return a table like:
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.
The worst part is the text area control... why? Well textareas have quite a bunch of features:
- 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.
- 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.
Code: Select all
function (a)
a = {"Hello",123}
end
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"}
}
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)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: creating an ide
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)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 2 guests