Example repo showing a LÖVE app whose source code can be edited from within the app. http://akkartik.name/lines.html
Go to file
Kartik K. Agaram 8adfe41cb2 Merge text.love 2023-09-20 14:46:43 -07:00
LICENSE.txt add a license 2022-05-16 18:51:28 -07:00
Manual_tests.md Merge lines.love 2023-06-08 01:24:34 -07:00
MemoryReferenceInfo.lua.0 remove some memory leaks from rendered fragments 2022-06-10 11:16:41 -07:00
MemoryReferenceInfo.lua.unused clean up memory leak experiments 2022-06-10 13:46:59 -07:00
README.md Merge text.love 2023-09-10 22:00:42 -07:00
app.lua yet another bugfix X-( 2023-09-09 09:27:56 -07:00
button.lua bugfix: propagate mouse press if any button would 2022-08-24 13:40:36 -07:00
colorize.lua stop highlighting strings in code 2023-06-17 10:41:50 -07:00
commands.lua source: show file being edited in window title bar 2023-09-15 13:36:27 -07:00
conf.lua document the version of LÖVE I've been using 2023-02-07 13:37:01 -08:00
drawing.lua assume starty can be nil in update 2023-09-15 11:13:04 -07:00
drawing_tests.lua bugfix: naming points 2023-03-26 09:36:41 -07:00
edit.lua Merge lines.love 2023-09-20 14:32:01 -07:00
geom.lua new fork: rip out drawing support 2022-08-14 09:20:14 -07:00
help.lua get rid of to_text 2023-04-01 16:12:55 -07:00
icons.lua switch source side to new screen-line-based render 2023-04-03 08:33:07 -07:00
json.lua forgot to add json.lua 2022-05-15 14:36:25 -07:00
keychord.lua support for num pad 2023-07-07 18:40:12 -07:00
log.lua create a place for graphical log handlers 2023-01-30 10:20:37 -08:00
log_browser.lua delete some dead code 2023-09-15 13:33:26 -07:00
main.lua Merge text.love 2023-09-10 22:00:42 -07:00
nativefs.lua cleaner API for file-system access 2023-08-30 19:04:06 -07:00
pong.lua Merge text.love 2023-03-17 22:40:22 -07:00
reference.md Merge text.love 2023-08-30 22:52:46 -07:00
run.lua Merge lines.love 2023-07-11 10:06:12 -07:00
search.lua bugfix: searching files containing unicode 2023-05-13 17:02:10 -07:00
select.lua Merge lines.love 2023-06-04 15:11:24 -07:00
source.lua Merge text.love 2023-09-16 00:03:58 -07:00
source_edit.lua bugfix: clear selection when clicking above or below lines 2023-09-20 13:39:29 -07:00
source_file.lua yet another set of bugfixes 2023-08-30 23:52:25 -07:00
source_select.lua port inscript's bugfix to source editor 2023-06-04 12:33:23 -07:00
source_tests.lua bugfix: Windows pushing title bar off screen 2023-07-10 17:09:09 -07:00
source_text.lua hide line numbers from log browser 2023-09-15 13:30:42 -07:00
source_text_tests.lua bugfix: clear selection when clicking above or below lines 2023-09-20 13:39:29 -07:00
source_undo.lua minor cleanup and a todo for later 2023-04-01 20:40:47 -07:00
test.lua show another detail on test failure 2023-01-20 21:48:49 -08:00
text.lua Merge lines.love 2023-07-31 10:26:19 -07:00
text_tests bugfix: clear selection when clicking above or below lines 2023-09-20 13:39:29 -07:00
text_tests.lua Merge lines.love 2023-09-20 14:32:01 -07:00
undo.lua Merge lines.love 2023-04-02 09:22:32 -07:00



An example repo that shows a simple game of Pong -- with all the tools needed to read and modify its inner workings.

Getting started

Install LÖVE. It's just a 5MB download, open-source and extremely well-behaved. I'll assume below that you can invoke it using the love command, but that might vary depending on your OS.

Download this repo:

git clone https://git.sr.ht/~akkartik/pong.love pong

Run the game:

love pong

When you want to read or modify the game, open up its editor by pressing ctrl+e. (Check out more keyboard shortcuts below to see what you can do.)

When you're done reading or making changes, press ctrl+e again to play Pong with any changes you made.

Keyboard shortcuts: playing Pong

At the start, press any key to start a game. Once a game starts:

  • a/z to move the left-hand paddle

  • up/down to move the right-hand paddle

  • space to start a new game

  • ctrl+e to stop playing and browse the code for the game

Keyboard shortcuts: reading source code for Pong

  • ctrl+e to go back to playing Pong, using any changes you made

  • ctrl+g to switch to a different file

  • ctrl+l to toggle a second editor on the right for recent logs. Useful when debugging.

  • ctrl+= to zoom in, ctrl+- to zoom out, ctrl+0 to reset zoom

On the left (source code) side:

  • ctrl+f to find patterns within the current file
  • ctrl+z to undo, ctrl+y to redo
  • alt+right/alt+left to jump to the next/previous word, respectively
  • mouse drag or shift + movement to select text, ctrl+a to select all
  • ctrl+e to modify the sources

Exclusively tested so far with a US keyboard layout. If you use a different layout, please let me know if things worked, or if you found anything amiss: http://akkartik.name/contact

Debugging Pong

The primary method here to understand what Pong is doing (or indeed any other program you choose to turn this repo into) is the log. To emit objects to the log, use the log function:

log(2, "log message")

log takes exactly 2 arguments: a stack frame index to report the file and line number for, and an object to log.

The stack frame index should be 2 if you call log directly. If you create higher levels of abstraction around log, increment the stack frame appropriately. Helper f calling log should use a stack frame index of 3 to report line numbers from its caller. Helper g calling f calling log should use a stack frame index of 4, and so on.

The log function can only emit a single object at a time. However, the object can be of any type.

Since each entry/line in the log contains a single object (after the filename and line number), it's easy to specify how different objects should be rendered. Just make sure the objects contain a field called name, and create a function log_render.name to render it. In this repo, the function log_render.state is an example of such a function, specifying how to render a Pong state consisting of a ball position, ball velocity and paddle positions.

Rendering functions must all have the same interface as log_render.state:

function log_render.state(state, x,y, w)

The first argument is the object that was logged, the remaining arguments specify the starting position from which to render it, and the width on screen available to it. After the function finishes rendering the object, it should return the y coordinate it drew until, so that the log browser knows where to start rendering the next object.

Sharing your changes

While pong.love lets you make changes to its source and shows how your changes affect its behavior, the changes don't live in the same place as the original sources. They live in the app's save directory (love.filesystem.getSaveDirectory()).

To distribute your version you'll need to copy the modified files over into the app, either its directory or its .love zip archive. This process is [unfortunately not automated yet](See https://love2d.org/wiki/Game_Distribution).

Known issues

  • ...

Mirrors and Forks

This repo is a fork of lines.love, an editor for plain text where you can also seamlessly insert line drawings. Its immediate upstream is text.love, a version without support for line drawings. Updates to it can be downloaded from:

Further forks are encouraged. If you show me your fork, I'll link to it here.


Most appreciated.