A Lua code editor

Showcase your libraries, tools and other projects that help your fellow love users.
josip
Prole
Posts: 20
Joined: Tue Oct 03, 2017 1:55 pm

A Lua code editor

Post by josip »

This is code editor written in pure Lua that can be rendered within LÖVE framework. The editor can be used to build self-contained development environments, like fantasy consoles or in-game editors.

Image

It is a rather complete implementation of editor component that's easy to integrate into any project. Host should provide function callbacks for drawing text and rectangles, and react to keypresses by calling into text buffer functions.

The main.lua demonstrates how to use the editor, but it is not meant to be complete standalone editor application. File access and dialogs for opening/saving files are out of scope.

Features:
* pure Lua platform-independant text buffer
* restricted to ASCII character set
* basic text typing/deleting
* easy key remapping
* horizontal and vertical scrolling
* single cursor with page up/down, word skip and other movement options
* text highlighting for Lua code, with external color scheme
* text selection, cut, copy and paste
* status line for filename and row/column info
* basic macros (quick one-liners to be executed on key combination)
* simple and extendable
* public domain code unburdened by license

There is currently no undo and search features, or support for general text files (currently always using Lua highlighting).

This LÖVE version is actually a by-product of VR project, I'm sharing here as it might be useful to someone. Future updates to the editor will be available here: https://github.com/jmiskovic/indeck
Attachments
lovedit.love
(114.1 KiB) Downloaded 539 times
Last edited by josip on Thu Jul 23, 2020 3:18 pm, edited 1 time in total.
JasonP75
Prole
Posts: 4
Joined: Sat Nov 24, 2018 12:04 pm

Re: A Lua code editor

Post by JasonP75 »

This is really good. The only minor tweak I'd add is key repeating, but that wouldn't be too hard to tack on for an end user. Awesome!
Giovifav
Prole
Posts: 4
Joined: Tue Jul 14, 2020 10:18 am

Re: A Lua code editor

Post by Giovifav »

Hi I'm looking into your code.
I had implemented key repeating in the love example but I'm struggling with utf8 encoding. The editor keep crashing when I insert utf chars. It is my fault or the editor doesn't support it?
Thanks
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

Re: A Lua code editor

Post by monolifed »

Nice. But I can't use it until you add a license
josip
Prole
Posts: 20
Joined: Tue Oct 03, 2017 1:55 pm

Re: A Lua code editor

Post by josip »

Thanks for interest.

@Giovifav the unicode is not supported unfortunately. It would require about x10 more work, and my needs were already covered with basic ASCII. I'll edit the description to clarify.

@monolifed I'm releasing it into public domain for anyone to do with it as they please.
monolifed
Party member
Posts: 188
Joined: Sat Feb 06, 2016 9:42 pm

Re: A Lua code editor

Post by monolifed »

Thanks
Giovifav
Prole
Posts: 4
Joined: Tue Jul 14, 2020 10:18 am

Re: A Lua code editor

Post by Giovifav »

Hi, thanks for the answer!
No Unicode support isn't a problem if there is a way to convert Unicode into ASCII so the editor doesn't crash.

Edit:
After a rapid googling I found this:
https://stackoverflow.com/questions/418 ... n-pure-lua

Maybe worth checking it
User avatar
zorg
Party member
Posts: 3283
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: A Lua code editor

Post by zorg »

Can i assume that your codebase was written for lua version 5.1? (or LuaJIT without the 5.2 compatibility flag?)

I'm only asking because if someone wants to use this in löve, it has its own utf-8 library (regarding the encoding only) that one can require in (with the added ability to actually print utf-8 characters without any modifications to anything), and it's similar, if not a carbon-copy, of the PuC lua 5.3 module. (that said, strings can store anything anyway, so "only" the display and editing parts are the problem)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3288
Joined: Sun Oct 18, 2015 2:58 pm

Re: A Lua code editor

Post by pgimeno »

Well, getting rid of UTF-8 can be done with just one line.

Code: Select all

text = text:gsub('[\192-\255][\128-\191]*', '?')
Giovifav
Prole
Posts: 4
Joined: Tue Jul 14, 2020 10:18 am

Re: A Lua code editor

Post by Giovifav »

My idea was to replace the utf8 char with a similar one ASCII compatible, for example ü become u, ã = a.
I'm a dummie so I don't know if is feasible.

Off topic:
pgimeno I stumble across your code multiple times, I really like your work!
Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests