lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Mon, Mar 1, 2010 at 3:07 PM, Gavin Wraith <gavin@wra1th.plus.com> wrote:
I have been thinking about Lua and text. By text, I do not mean
simply a string, but a data-structure with an allied notion of list of
markers-to-a-position (for representing a cursor, for selections
of text, ... ). Primitive operations on a text would be (M)
movement-of-cursor,  (I) insertion of a character and (D) deletion
of a character.
What is the most efficient way of implementing this
1) in Lua,
2) in C, but under the constraint that the operations also include
converting a selection of the text to a Lua string, and insertion of
a Lua string at a marker?

In case 1 taking text to be a string, and marker to be an index,
M is cheap, I and D expensive.
Having separate lists for the characters before the cursor and for
those after the cursor might be better. In that case I and D are
cheap, while M becomes expensive.
In case 2 I am looking for datastructures that would use Lua's
garbage collection. Are there any tricks or modifications to Lua's
memory-allocation strategy for tables that could ensure that the
cursor-movement transformation did not trigger a table-reallocation?

I know that there are text editors out there, like Scite and textadept,
which are closely related to Lua, so I guess that various people have
given this abstract question a fair amount of thought. I would be grateful
if anybody could point me at online documentation or previous Lualist
entries that consider these questions.

Thanks
--
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/

This is a must read: The Text Editor sam, Software - Practice and Experience, Vol. 17, 11, pp. 813--845, 1987. ( http://plan9.bell-labs.com/sys/doc/sam/sam.pdf , linked from http://research.google.com/people/r/ )

Robby