Page 1 of 2

A Lua code editor

Posted: Tue Jun 23, 2020 2:07 pm
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

Re: A Lua code editor

Posted: Wed Jun 24, 2020 1:27 pm
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!

Re: A Lua code editor

Posted: Tue Jul 14, 2020 10:46 am
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

Re: A Lua code editor

Posted: Wed Jul 22, 2020 9:02 am
by monolifed
Nice. But I can't use it until you add a license

Re: A Lua code editor

Posted: Thu Jul 23, 2020 3:15 pm
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.

Re: A Lua code editor

Posted: Thu Jul 23, 2020 3:55 pm
by monolifed
Thanks

Re: A Lua code editor

Posted: Wed Jul 29, 2020 7:40 am
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

Re: A Lua code editor

Posted: Wed Jul 29, 2020 10:20 am
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)

Re: A Lua code editor

Posted: Wed Jul 29, 2020 10:24 am
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]*', '?')

Re: A Lua code editor

Posted: Wed Jul 29, 2020 11:56 am
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!