Commit Graph

527 Commits

Author SHA1 Message Date
Kartik K. Agaram fd4ca45ae5 clean up luasocket build file
Teliva is never intended to be "installed" somewhere. Just work inside
its directory and separately share the .tlv files you create. (Though I
don't yet have a good flow for starting a new .tlv file.)
2021-11-27 06:57:38 -08:00
Kartik K. Agaram c558d2c565 . 2021-11-27 00:42:15 -08:00
Kartik K. Agaram ff43b5bae1 fix build on Mac 2021-11-27 00:41:17 -08:00
Kartik K. Agaram 83050ec38e starting to test compilation on Mac and BSD.
For starters, put Linux-specific stuff in a Linux-specific target.

By not resetting MYCFLAGS and MYLDFLAGS, I'm unnecessarily passing in
-DLUA_USE_LINUX. But that'll make it easier to get things running on Mac
and BSD.
2021-11-27 00:34:49 -08:00
Kartik K. Agaram 1e911f95ef bugfix: emit legal Lua representation 2021-11-26 22:03:47 -08:00
Kartik K. Agaram 662d1cf202 support space/backspace in recent changes view 2021-11-26 21:54:45 -08:00
Kartik K. Agaram 2426fe7a79 standardize indent 2021-11-26 21:50:53 -08:00
Kartik K. Agaram 7e86f6d123 colorize comments in recent changes 2021-11-26 21:48:31 -08:00
Kartik K. Agaram e2a53858a0 support notes on edits
Unlike both conventional version control and wiki history, I'm planning
to always allow modifying commit messages.
2021-11-26 21:43:31 -08:00
Kartik K. Agaram 6b6fe7ce72 periodic cleanup of warnings 2021-11-26 21:22:20 -08:00
Kartik K. Agaram db7202ccfd . 2021-11-26 21:20:23 -08:00
Kartik K. Agaram 35fe28a36f . 2021-11-26 21:19:41 -08:00
Kartik K. Agaram 0c211dec77 don't mislead immediately after undo 2021-11-26 20:00:32 -08:00
Kartik K. Agaram b954ab869e . 2021-11-26 19:52:31 -08:00
Kartik K. Agaram 0726692546 more obvious serialization of undo events 2021-11-26 19:45:19 -08:00
Kartik K. Agaram 3cb37a0f39 render undo events 2021-11-26 19:38:51 -08:00
Kartik K. Agaram a0171352a1 start processing undo events 2021-11-26 19:33:35 -08:00
Kartik K. Agaram 576ab1df8d start recording undo events in timeline
We're not using or rendering them yet.
2021-11-26 18:59:31 -08:00
Kartik K. Agaram 07bf55b460 save timestamp on change; show in recent changes 2021-11-26 18:47:50 -08:00
Kartik K. Agaram f3dd541561 . 2021-11-26 18:21:04 -08:00
Kartik K. Agaram 555159fb9a clean up traces of an old experiment 2021-11-26 18:18:58 -08:00
Kartik K. Agaram 720ff19351 add support for metadata in Teliva programs
They don't have any semantics yet. We just ignore them for now.
2021-11-26 18:17:35 -08:00
Kartik K. Agaram 7295ce050d undo to a specific point
Still highly experimental. I'm not persisting state yet.
2021-11-26 18:05:41 -08:00
Kartik K. Agaram 080ea49d23 standardize screen headings 2021-11-26 18:04:58 -08:00
Kartik K. Agaram 0800f65eff start of 'recent changes' screen
I'm still unclear on precisely what the experience should be here. We
probably don't need all of a version control system. The goal is just to
be able to answer the question, "what did I change recently that caused
things to break?"

For now let's just start with letting people see past versions.
2021-11-26 18:03:20 -08:00
Kartik K. Agaram 283cc7ea52 eliminate tail call using goto 2021-11-26 16:54:45 -08:00
Kartik K. Agaram 0b365d3e4d clean up terminal in a specific situation
The problem: if ever I hit ctrl-e to go to the big picture view and then
hit Esc to go back to running the app, my terminal was messed up after
exiting the app.

Why did I even have this gunk? Perhaps it dates from the time when kilo
was emitting raw escape sequences rather than using ncurses.
2021-11-26 16:39:20 -08:00
Kartik K. Agaram e699b5a052 dedup an enum 2021-11-26 16:26:13 -08:00
Kartik K. Agaram 5bc52a5cba . 2021-11-26 16:10:02 -08:00
Kartik K. Agaram 2c80411224 . 2021-11-26 16:09:15 -08:00
Kartik K. Agaram f930b9e7c7 extract a function 2021-11-25 21:04:08 -08:00
Kartik K. Agaram 61ea63adca more stack hygiene 2021-11-25 21:02:27 -08:00
Kartik K. Agaram f5221ba651 one more curses binding 2021-11-25 20:51:38 -08:00
Kartik K. Agaram 73a22a397e libraries don't need Lua's `#define`s and whatnot 2021-11-25 20:21:05 -08:00
Kartik K. Agaram 16a98ea1b3 . 2021-11-25 20:16:41 -08:00
Kartik K. Agaram 4d7e99c343 . 2021-11-25 20:13:49 -08:00
Kartik K. Agaram d6810aba30 dedup definitions in big-picture view
We only want to show most recent version of each binding.
2021-11-25 20:02:10 -08:00
Kartik K. Agaram 4a8691c3dc new shortcut: return to big-picture view 2021-11-25 20:01:40 -08:00
Kartik K. Agaram f58d5b8354 teliva is now ASan-clean again
At least in short runs.

Encouraging that the problem was in a recent commit (5a63a5ca40 from
yesterday when I introduced version control).

Disabling Address Sanitizer again.
2021-11-25 19:27:30 -08:00
Kartik K. Agaram 05f4482139 make upstream kilo ASan-clean
Many thanks to dirkf for https://github.com/antirez/kilo/pull/73!

However, teliva is still not ASan-clean.
2021-11-25 11:28:05 -08:00
Kartik K. Agaram 6727045165 temporarily start using the address sanitizer 2021-11-25 11:25:28 -08:00
Kartik K. Agaram 103b8e17bb jettison luac
I'm starting to see some heap buffer overruns, which means we have too
much C code.

I noticed this because editing life.tlv no longer works after commit
5a63a5ca4. However, the offending heap overrun has been around long
before that. It's just been a silent bug until now.
2021-11-25 11:22:26 -08:00
Kartik K. Agaram d606e93839 rename 2021-11-24 12:50:05 -08:00
Kartik K. Agaram 5a63a5ca40 monotonically accumulate versions of definitions
One old drawback now has a new look. Before, we loaded definitions in
order, so global definitions had to exist before other global
definitions that used them. See window and grid in life.tlv. Now we load
definitions in reverse order, so initialization needs to change. Worse,
if we update window, we need to edit grid just to fix the order.

This implies that we can't yet optimize away bindings where there are no
new changes.
2021-11-24 10:10:38 -08:00
Kartik K. Agaram b40ad26544 more Makefile streamlining
Since everything is in my control there's no need to parameterize
include paths.

It's a struggle to get make to run when it should. Lying that something
is phony stops working when it's a dependency. Commands get
unnecessarily run. Just fucking run recursive makes directly in the
target that depends on them.
2021-11-24 09:28:01 -08:00
Kartik K. Agaram a788f80a92 . 2021-11-24 07:55:39 -08:00
Kartik K. Agaram b670747d9e consistent file ops
Now we're down to 1 real warning and 1 false positive.
2021-11-24 07:54:48 -08:00
Kartik K. Agaram aff8afa12d style 2021-11-24 07:48:49 -08:00
Kartik K. Agaram 64b609f743 rename 2021-11-24 07:04:04 -08:00
Kartik K. Agaram bd9020c5b3 indent 2021-11-24 06:43:32 -08:00
Kartik K. Agaram 1bf2504a8b clean up a warning and a bit of duplication
Now we have 2 probably-valid warnings caused by my edits, and 1
false-positive.
2021-11-22 19:25:05 -08:00
Kartik K. Agaram 76329c0206 standardize warning flags everywhere
I'd like to enable -Wextra as well, but that creates some false
positives.

I've at least made my changes clean w.r.t. -Wextra.

Now we have 4 remaining warnings with gcc 9.3 that seem genuine. Need to
fix those.
2021-11-22 19:01:07 -08:00
Kartik K. Agaram e77f3eb9f9 . 2021-11-22 18:47:56 -08:00
Kartik K. Agaram 11d370493a drop a warning implied by -Wall 2021-11-22 18:37:11 -08:00
Kartik K. Agaram ef68041137 standardize CFLAGS in luasocket 2021-11-22 18:36:04 -08:00
Kartik K. Agaram 3b4d7131cb standardize CFLAGS
Adding -Wpedantic creates a new warning. Leaving it alone for now:
  https://stackoverflow.com/questions/31526876/casting-when-using-dlsym
2021-11-22 18:11:38 -08:00
Kartik K. Agaram 97a0254042 standardize CFLAGS in luasec
What in the world is up with the $MYCFLAGS convention in these Lua
makefiles? I don't know, but I'm going to leave it undisturbed as far as
possible.
2021-11-22 18:06:20 -08:00
Kartik K. Agaram c4ecb9a53d standardize on gcc
cc and gcc are identical on my system. But why rely on that.
2021-11-22 17:56:45 -08:00
Kartik K. Agaram c79527b784 delete final vestiges of embedded luasocket 2021-11-22 17:41:08 -08:00
Kartik K. Agaram 70a2e1db1d delete most of the embedded luasocket in luasec
Hilariously, I wasn't linking against it in the first place.
2021-11-22 17:37:41 -08:00
Kartik K. Agaram d40471e9dc luasec: fix 'make clean' 2021-11-22 00:12:37 -08:00
Kartik K. Agaram 5a484efe8c https now working!
Still extremely ugly:
- I've inlined all the namespaces under ssl, so you need to know that
  context and config are related to ssl.
- luasec comes with its own copy of luasocket. I haven't deduped that
  yet.
2021-11-21 15:55:52 -08:00
Kartik K. Agaram 3b44b9827d basic http requests starting to work
In the process we're starting to load almost all of luasocket by
default. And everything is working as expected, no unpleasant surprises.
2021-11-21 15:07:42 -08:00
Kartik K. Agaram fdd87c5eda now. we. have. JSON.
Completely unmodified from upstream.
2021-11-21 14:22:20 -08:00
Kartik K. Agaram 15b43d3092 drop some redundant `require`s 2021-11-20 23:35:22 -08:00
Kartik K. Agaram 548d59f918 luasocket now loading properly
I still haven't tried actually running it.
2021-11-20 23:34:29 -08:00
Kartik K. Agaram 02acfa7c9c rename 2021-11-20 21:03:38 -08:00
Kartik K. Agaram fa6faaa700 extract a helper 2021-11-20 20:35:37 -08:00
Kartik K. Agaram 6bdc3d17a7 inline luasocket
Just builds for now, isn't available yet to Lua code.
2021-11-20 20:26:17 -08:00
Kartik K. Agaram 38b21ef79b bugfix: support running from top-level
Unfortunately we can't currently run teliva from anywhere else :/
2021-11-20 19:59:32 -08:00
Kartik K. Agaram d6ff198e78 get rid of a distracting name
No distinction now between the C and Lua versions of the curses library.
We build them all together in one place.
2021-11-20 16:33:41 -08:00
Kartik K. Agaram b618bfc7cf port changes from minimal to maximal version
From lcurseslib.c to lcurses/ directory.
2021-11-20 16:33:41 -08:00
Kartik K. Agaram 8a3e81b4b0 report errors when calling non-existent functions 2021-11-20 10:13:58 -08:00
Kartik K. Agaram e693448b65 inline in C is not worth the trouble
https://merveilles.town/@akkartik/107310347838372198
2021-11-20 10:10:26 -08:00
Kartik K. Agaram b43747ecef inline lcurses maximally rather than minimally
Until now we had just the bare minimum bindings needed for the demos
built so far. Now we have all of lcurses building in place with minimal
changes.

The changes in this commit can run hanoi.lua when inlined into Lua 5.1,
but don't work with Teliva.
2021-11-19 19:11:03 -08:00
Kartik K. Agaram 720d728a8d tested on Mac OS 2021-11-14 12:33:25 -08:00
Kartik K. Agaram f40bc31cc3 import life.teliva into image format 2021-11-14 11:10:18 -08:00
Kartik K. Agaram 58d2d596ea cleaner error handling 2021-11-14 09:55:13 -08:00
Kartik K. Agaram a3ca7877da . 2021-11-14 09:48:41 -08:00
Kartik K. Agaram 7b91691b14 remain in editor on error 2021-11-14 09:48:41 -08:00
Kartik K. Agaram b3b844c5f7 . 2021-11-14 09:48:41 -08:00
Kartik K. Agaram 2cc6912e85 find _some_ way to show error on initial load 2021-11-14 09:48:41 -08:00
Kartik K. Agaram 4ab3ccebb5 more menu cleanup 2021-11-14 09:48:40 -08:00
Kartik K. Agaram af4fbe97bf . 2021-11-14 09:48:40 -08:00
Kartik K. Agaram 33331a7c50 drop support for non-image Lua scripts
We still have no story for error messages. We'll work on that next.
2021-11-14 07:59:15 -08:00
Kartik K. Agaram b50e393770 draw the browse dialog the same way 2021-11-14 07:53:20 -08:00
Kartik K. Agaram 12d738d5ce dialogs are not status messages 2021-11-14 07:34:23 -08:00
Kartik K. Agaram b4e3936170 smarter image browsing
- distinguish between unused functions and data
- don't hardcode a specific convention for the curses window object
2021-11-14 07:11:30 -08:00
Kartik K. Agaram 5be743324c slightly more robust on-disk format
Looks like Lua supports a little bit of programmability in its
multi-line string literals. Even though I can't find this documented
anywhere.
2021-11-14 00:52:25 -08:00
Kartik K. Agaram b64a21771e janky way to cancel browsing 2021-11-14 00:38:00 -08:00
Kartik K. Agaram d9aac11889 slightly more obvious browse dialog 2021-11-14 00:27:59 -08:00
Kartik K. Agaram 9db1cd174f cleaner dialogs 2021-11-14 00:23:20 -08:00
Kartik K. Agaram e451206e06 no, use Esc to cancel
It inserts an ugly pause for ghastly historical reasons having to do
with the origins of terminals. But hopefully this isn't a common case.
2021-11-14 00:07:28 -08:00
Kartik K. Agaram c5261224df use word at cursor when it's not at start of line 2021-11-14 00:02:04 -08:00
Kartik K. Agaram 8e9534ed4f editor: use ctrl-g to cancel dialogs 2021-11-13 23:59:05 -08:00
Kartik K. Agaram 711d764b37 jump to word at cursor by default 2021-11-13 23:55:08 -08:00
Kartik K. Agaram 812b930815 ctrl-u to clear response in go menu 2021-11-13 23:27:51 -08:00
Kartik K. Agaram d79e394a30 reset cursor position when switching definitions 2021-11-13 23:27:06 -08:00
Kartik K. Agaram 3c2a5e26ae . 2021-11-13 23:22:00 -08:00
Kartik K. Agaram 902ce6009d cleaner layout for a function's code and data 2021-11-13 23:14:52 -08:00
Kartik K. Agaram 0e74056cbb . 2021-11-13 22:48:59 -08:00
Kartik K. Agaram e990682fb2 . 2021-11-13 22:48:14 -08:00
Kartik K. Agaram 55302fd877 . 2021-11-13 22:45:44 -08:00
Kartik K. Agaram a0dbc38c34 generalize kilo's hard-coded multiline C syntax 2021-11-13 22:39:28 -08:00
Kartik K. Agaram 308cb7acbe . 2021-11-13 22:02:30 -08:00
Kartik K. Agaram 485cd25739 fix for editor highlighting
Bug introduced during the transition to ncurses.
2021-11-13 22:00:50 -08:00
Kartik K. Agaram a7139a6b14 clean up after the editor
Even though we don't need to leave ncurses mode, there's still a process
boundary to clean up before.
2021-11-13 21:33:12 -08:00
Kartik K. Agaram da76ec44f1 . 2021-11-13 21:25:52 -08:00
Kartik K. Agaram 88f4b1bb2b . 2021-11-13 21:23:14 -08:00
Kartik K. Agaram 90f86daf1c kill highlighting flags
Looks like they were never used in original Kilo.
2021-11-13 21:20:30 -08:00
Kartik K. Agaram a655059c8d replace Kilo's raw terminal handling with ncurses
This was on my todo list. What made it urgent was finding that calling
getch() even once while in ncurses caused Kilo to stop detecting arrow
keys. No need to debug that sort of nonsense.
2021-11-13 21:20:30 -08:00
Kartik K. Agaram 625a66e196 avoid side-effects on the Lua stack 2021-11-13 17:48:04 -08:00
Kartik K. Agaram 12b2a44cf6 stop leaking memory 2021-11-13 17:46:08 -08:00
Kartik K. Agaram 398112f756 memory corruption bug
I was saving an address on the stack to a global, and it was getting
clobbered later. This is the sort of thing I completely eliminated in
https://github.com/akkartik/mu :/

Now I'm taking a leaf out of the Mu playbook and leaking a little bit of
memory every time I switch definitions.
2021-11-13 17:42:39 -08:00
Kartik K. Agaram 51378afb2a . 2021-11-13 16:53:39 -08:00
Kartik K. Agaram c34db20756 very rudimentary definition browser
Never shows definitions that were never called. Including non-functions.
2021-11-13 16:36:12 -08:00
Kartik K. Agaram 7a24bed432 . 2021-11-13 16:28:13 -08:00
Kartik K. Agaram 998e666958 . 2021-11-13 16:13:05 -08:00
Kartik K. Agaram 5bf5e47077 . 2021-11-13 16:13:05 -08:00
Kartik K. Agaram 647a2520d6 shield kilo.c from teliva_editbuffer detail 2021-11-13 16:13:05 -08:00
Kartik K. Agaram ee0e7c36f5 . 2021-11-13 15:11:03 -08:00
Kartik K. Agaram 4e62aa95b0 . 2021-11-13 15:07:28 -08:00
Kartik K. Agaram cbd5e7d552 . 2021-11-13 15:07:14 -08:00
Kartik K. Agaram e06a7b1a7b . 2021-11-13 15:00:49 -08:00
Kartik K. Agaram 33b705282d . 2021-11-13 14:59:22 -08:00
Kartik K. Agaram 7623e7069a clean up experiment from previous commit 2021-11-13 10:10:16 -08:00
Kartik K. Agaram 5a44605143 instrumenting function calls with their depth 2021-11-13 08:16:41 -08:00
Kartik K. Agaram 0f4faf0e53 start using static linkage like the rest of Lua 2021-11-13 05:14:41 -08:00
Kartik K. Agaram d72eae5978 create empty file when navigating to empty definition 2021-11-11 17:41:37 -08:00
Kartik K. Agaram e7f33de81e fix incorrect hotkey in menu 2021-11-11 17:32:50 -08:00
Kartik K. Agaram f6c7bf6fd0 ctrl-g to edit a different definition 2021-11-11 17:29:40 -08:00
Kartik K. Agaram 4d20e71c80 gracefully handle missing definition 2021-11-11 17:04:29 -08:00
Kartik K. Agaram 8398f8e2d1 . 2021-11-11 17:00:18 -08:00
Kartik K. Agaram a76cd9067a global for current definition being edited 2021-11-11 16:47:09 -08:00
Kartik K. Agaram d303c6efb0 pass lua_State into editor 2021-11-11 16:42:02 -08:00
Kartik K. Agaram 0d6378aa51 delete a helper that hides stack side effects 2021-11-11 16:32:08 -08:00
Kartik K. Agaram 7b389ce41e extract a few helper functions 2021-11-11 16:16:55 -08:00
Kartik K. Agaram 2d05f5090f . 2021-11-11 16:15:06 -08:00
Kartik K. Agaram 15e0ac70f9 . 2021-11-11 16:09:46 -08:00
Kartik K. Agaram 3e7ff252af reorg 2021-11-11 15:50:52 -08:00
Kartik K. Agaram f43a1c7da0 edit a single hard-coded definition in the image
src/teliva counter.tlv
C-e  # switch to editor
C-e  # save and quit
C-x  # exit

counter.tlv now has the same logical contents, though the whitespace has
changed, and the order of keys is different.

The implementation is utterly ghastly. For one, I'm unnecessarily
interfacing with kilo through the file system.
2021-11-10 23:20:59 -08:00
Kartik K. Agaram 9a49b92703 . 2021-11-10 22:15:13 -08:00
Kartik K. Agaram efbb57d339 new .tlv image format
Plan is for this to be the default representation for Teliva programs.
Text-friendly but not meant to be edited directly as text. Will
eventually include both code and data definitions, both current snapshot
and past revision history.

Right now .tlv files seem to run. Error checking is non-existent,
because I don't understand Lua's idioms around 'status' yet. Opening the
editor expectedly segfaults.

This commit is the most mind-bending bit of code I've written in a long
time.
2021-11-10 22:09:12 -08:00
Kartik K. Agaram dc05a10e23 life: move starting pattern around on the screen
This assumes we're doing it early soon after opening a new pattern, when
it hasn't yet reached the margins. Quick and dirty, but seems good
enough.
2021-11-10 14:26:38 -08:00
Kartik K. Agaram b397edcfbd . 2021-11-09 20:52:53 -08:00
Kartik K. Agaram ef9c42084d switch menu bars to reverse video 2021-11-07 10:29:29 -08:00
Kartik K. Agaram 2b7ffea316 fix menu colors
I had it switching to a dark background on me.
2021-11-07 08:06:42 -08:00
Kartik K. Agaram 22f1624728 better support light backgrounds
Thanks nicolas decoster for reporting this issue.
2021-11-07 08:04:33 -08:00
Kartik K. Agaram 40fdaf2a2a more obvious phrasing
Early returns are only worthwhile if they're utterly obvious.
2021-11-07 06:30:15 -08:00
Kartik K. Agaram 51d6ae77d2 fix a regression in commit ee85ad384f 2021-11-07 06:28:24 -08:00
Kartik K. Agaram d79c83f209 . 2021-11-07 06:05:55 -08:00
Kartik K. Agaram a8668eaf9f game of life
This required me to figure out some unicode-related nuances, but no new
primitives.
2021-11-06 21:49:23 -07:00
Kartik K. Agaram 8d1e5f6475 . 2021-11-06 19:21:10 -07:00
Kartik K. Agaram 5619f0117a window:nodelay() for non-blocking input 2021-11-06 19:21:01 -07:00
Kartik K. Agaram 62ecf17870 escape hatch to quit with a pending error 2021-11-06 14:41:11 -07:00
Kartik K. Agaram cba53ec9f6 reorg editor transitions 2021-11-06 13:22:05 -07:00
Kartik K. Agaram 3305ac0b90 start showing error messages in editor
Before we'd end up in cryptic situations where error messages would get
hidden when the program got out of ncurses mode.

Now it's a little nicer with error messages showing up at the bottom of
the editor.

But there's still a problem: there's no way to abort without fixing an
error.
2021-11-06 13:10:22 -07:00
Kartik K. Agaram ee85ad384f simple interface for adding to app menu
We're not going to enforce that the menu items actually do what they
advertise. It's just a way to draw on the bottom line of screen,
something apps aren't otherwise allowed to do.
2021-11-06 12:44:47 -07:00
Kartik K. Agaram 2964a5e74a refactor menu drawing 2021-11-06 12:41:14 -07:00
Kartik K. Agaram 9b99cd2a56 . 2021-11-06 12:15:41 -07:00
Kartik K. Agaram 3e94073a88 auto-save
We'll add version control soon.
2021-11-06 10:37:49 -07:00
Kartik K. Agaram 38d202d68d replace initial help message with a menu 2021-11-06 10:35:50 -07:00
Kartik K. Agaram 0de8ee3911 no, more consistent to toggle run/edit with ctrl-e 2021-11-06 10:18:22 -07:00
Kartik K. Agaram 29bb6403eb exit editor with ctrl-x for consistency 2021-11-06 10:13:43 -07:00
Kartik K. Agaram e0c0dea5b7 . 2021-11-06 10:12:50 -07:00
Kartik K. Agaram 567ee60c5a . 2021-11-06 10:12:50 -07:00
Kartik K. Agaram 491f9a378f clean up when leaving editor
kilo.c is still calling exit() in several places that we'll need to
gradually clean up.
2021-11-06 08:06:31 -07:00
Kartik K. Agaram 9275c954c8 readme and docs 2021-11-05 23:52:58 -07:00
Kartik K. Agaram 52d73ff930 clean up first paint of editor 2021-11-05 22:40:12 -07:00
Kartik K. Agaram 6fc0e72cb3 utterly ghastly way to rerun script after edit 2021-11-05 22:39:36 -07:00
Kartik K. Agaram 6b8da095b1 stitch editor in 2021-11-05 22:12:24 -07:00
Kartik K. Agaram dd434b2e1c drop test array data structure 2021-11-05 22:09:15 -07:00
Kartik K. Agaram 4ad3390ce3 . 2021-11-05 22:07:46 -07:00
Kartik K. Agaram 95841b8a43 select an editor to bundle: kilo
From https://github.com/antirez/kilo
Source code description: https://viewsourcecode.org/snaptoken/kilo
BSD 2-clause license seems identical to the MIT in the current codebase.
2021-11-05 21:41:39 -07:00
Kartik K. Agaram a2aa431c1e slightly improve hanoi rendering 2021-11-05 19:53:16 -07:00
Kartik K. Agaram 5da9f27079 menu entry: cleanly exit 2021-11-05 19:50:12 -07:00
Kartik K. Agaram ee3f6e8a22 colors: init_pair/color_pair 2021-11-05 19:43:40 -07:00
Kartik K. Agaram 6c9e26e07c . 2021-11-05 19:26:05 -07:00
Kartik K. Agaram 643deca2e2 slightly clearer rendering in the example app 2021-11-05 18:44:16 -07:00
Kartik K. Agaram cab996b194 make some space for the global menu
We'll eventually need some interface to add entries to it.
2021-11-05 18:43:37 -07:00
Kartik K. Agaram 78898d2716 move getch out of window scope
The window only matters for output, which seems like a stupid interface.
2021-11-05 17:54:45 -07:00
Kartik K. Agaram 18f06a5169 rename 'screen' to 'window'
We're going to set aside a portion of the screen soon that apps can't
touch.
2021-11-05 17:48:09 -07:00
Kartik K. Agaram c0307fae88 resist the temptation to add to the Lua API
Instead we'll include code in the Lua app itself, to minimize the
differences between what runs on regular Lua and what runs on Teliva.
2021-11-05 16:41:31 -07:00
Kartik K. Agaram 216e56effc hanoi.lua now working
There's something strange in the combination of Lua 5.1 and lcurses:
window.getch() returns a char but curses.getch() returns an int.
2021-11-05 16:25:45 -07:00
Kartik K. Agaram d04ecfeaf3 hanoi.lua _almost_ working 2021-11-05 13:34:38 -07:00
Kartik K. Agaram 936f8f916b vimrc 2021-11-05 13:23:58 -07:00
Kartik K. Agaram 44258f7657 window:getch()
But how do we get curses.getch() to work?
I don't see it implemented in lcurses.
2021-11-05 13:23:14 -07:00
Kartik K. Agaram 14b16003b1 hanoi.lua now rendering 2021-11-05 13:16:39 -07:00
Kartik K. Agaram b882d405ca curses print constants
Very satisfying to debug the difference between lcurses putting the
module table in an upvalue. Since I implicitly call initstr() rather
than define it as a primitive, I don't need to bother with that. I am
awesome. Lua is awesome for giving me that sense.
2021-11-05 13:13:25 -07:00
Kartik K. Agaram a7351c723e grouping 2021-11-05 13:08:12 -07:00
Kartik K. Agaram 13784eb757 mvaddch/mvaddstr
I think we now have all the output functions/methods we need. Just some
constants remaining.
2021-11-05 12:57:13 -07:00
Kartik K. Agaram 6f96d30641 attron/attroff 2021-11-05 12:48:27 -07:00
Kartik K. Agaram a4ce7ffbd0 window:getmaxyx() 2021-11-05 12:25:31 -07:00
Kartik K. Agaram 595a963671 . 2021-11-05 12:21:16 -07:00
Kartik K. Agaram debe292277 window:clear() 2021-11-05 12:16:31 -07:00
Kartik K. Agaram 048abcfbc2 ok, what do we need next for hanoi.lua? 2021-11-05 12:12:16 -07:00
Kartik K. Agaram d1c9bff737 reindent
I'm trying to follow the style of lua sources even when they're not my
preference. lcurses code is a bit different.
2021-11-05 12:06:14 -07:00
Kartik K. Agaram ffaf456654 ohh, that word 'index' was key 2021-11-05 12:03:27 -07:00
Kartik K. Agaram ac6c9319f9 oh, that's just a cosmetic thing
So why isn't this working?
  a = curses:stdscr()
  a:addstr(abc)

The error is "attempt to index global 'a' (a userdata value)"
2021-11-05 12:00:37 -07:00
Kartik K. Agaram f2d61064fb copy metatable name from lcurses
Makes no difference to the results of:
  print(curses:stdscr())
2021-11-05 11:54:55 -07:00
Kartik K. Agaram bf7baffa30 metatables seem to be a separate namespace from globals 2021-11-05 11:52:59 -07:00
Kartik K. Agaram c4c3b93bf5 snapshot
Not quite working. curses.stdscr() is returning userdata, not a window.

This is true even of the raw array example from the book. So we need to
learn something new here. How does lcurses's Pinitscr return a special
window object? From what I can tell it's just putting the results of
lc_newwin() on the stack. Which is the same as my curses_newwin() here.
2021-11-05 11:46:47 -07:00
Kartik K. Agaram f761d0ae36 stdscr binding
print(curses.stdscr())
print(curses:stdscr())
2021-11-05 10:51:47 -07:00
Kartik K. Agaram 8552ad4ced starting on curses library
First piece of working new vocabulary:
  print(curses:cols())

Just pulling in code from lcurses for the most part. But I'm trying to
understand its internals as I gradually add them in, after my more blunt
first approach of packaging up lcurses/ext failed.

Overall plan for Teliva's API:
- start out with a 'curses' library that does what people who are used
  to ncurses/lcurses expect.
- over time create a more opinionated library called 'screen' or
  'window' or something.
2021-11-05 10:30:07 -07:00
Kartik K. Agaram 37b05c2957 https://www.lua.org/pil/28.3.html
a = array.new(1000)
for i=1,1000 do
  a:set(i, 1/i)
  end
print(a:get(10))  -- 0.1
2021-11-05 09:17:54 -07:00
Kartik K. Agaram b4d86665b8 https://www.lua.org/pil/28.2.html 2021-11-05 08:54:19 -07:00
Kartik K. Agaram f53ca6f804 confirmed that this is the same
And it seems simpler to me.
2021-11-05 08:31:43 -07:00
Kartik K. Agaram 712dc16b23 going through chapter 28 of https://www.lua.org/pil
User-defined C data.

I think I have some understanding of the Lua stack now. It's a different
kind of verbose, error-prone syntax than Mu that requires me to play
computer in my head. But I don't fully grok metatables yet. At least not
well enough to grok everything that's going on in lcurses/ext.
2021-11-05 08:31:43 -07:00
Kartik K. Agaram e35454c9a8 I don't yet understand the stack 2021-10-24 14:20:37 -07:00
Kartik K. Agaram d8fcd648d7 ok, starting to make sense now
Putting together two resources:
  https://lucasklassmann.com/blog/2019-02-02-how-to-embeddeding-lua-in-c/#exposing-a-simple-variable
  https://www.lua.org/manual/5.3/manual.html, section 2.1, "Values and Types", particularly the description of light user data.

And lo, I see lua_pushlightuserdata in lapi.c
2021-10-24 10:32:22 -07:00
Kartik K. Agaram 4a0822929b done reading lua_newstate 2021-10-24 10:08:15 -07:00
Kartik K. Agaram e3b1ac2c83 mildly less confusing 2021-10-24 09:58:47 -07:00
Kartik K. Agaram 7b285449c3 back to making sense of lua_newstate 2021-10-24 09:57:19 -07:00
Kartik K. Agaram 4a28aace9a get rid of userstate hooks 2021-10-24 09:52:07 -07:00
Kartik K. Agaram 67e4fb8c8e get rid of fromstate/tostate 2021-10-24 09:46:56 -07:00
Kartik K. Agaram a1d3225305 get rid of state_size 2021-10-24 09:39:30 -07:00
Kartik K. Agaram a3c090ce09 get rid of LUAI_EXTRASPACE
Lua's power may come from extensibility, but the indirections are
currently in the way
2021-10-24 09:35:12 -07:00
Kartik K. Agaram c80bafed74 trying to make sense of how bindings are created
lua_State contains these StkId fields (stack, stack_last, base, top)
that expand to a pointer of a struct containing a Lua value and an int.
Unclear how it's used, or how you build a stack out of it.
2021-10-24 09:23:54 -07:00
Kartik K. Agaram 8d8580089f print's newline now returns to column 0
At this point I'm done making this repo ncurses-ready. Remaining files
that allude to stdin/stdout/stderr:

  lauxlib.c - unclear how these primitives should work; may kill them
  ldblib.c - unclear what debug experience should be
  liolib.c - might kill or simulate these
  luac.c - let the compiler continue to be a terminal program
2021-10-22 21:22:27 -07:00
Kartik K. Agaram 05fa5124c2 drop lua_stdin_is_tty
luaconf.h now no longer refers to stdin/stdout/stderr.
2021-10-22 21:02:47 -07:00
Kartik K. Agaram 9792ac1e09 drop support for '-' filename
lua.c now no longer refers to stdin/stdout/stderr.
2021-10-22 21:00:26 -07:00
Kartik K. Agaram 1445cbc5b1 ncurses I/O in lua.c
Currently working:
  > print(1)
  1
   > print(2)
  2

Print's newline doesn't return to column 0 yet.

Ctrl-d no longer works. Ctrl-c exits cleanly.
2021-10-22 20:54:34 -07:00
Kartik K. Agaram d92a484b91 kill lua_readline abstraction 2021-10-22 20:37:56 -07:00
Kartik K. Agaram 9eb951608b purge notion of commandline history 2021-10-22 20:30:13 -07:00
Kartik K. Agaram 0ab2c77e6c delete readline support
We're going to be using full-on ncurses.
2021-10-22 20:29:31 -07:00
Kartik K. Agaram c03ee20559 clean up a few warnings with gcc 9.3.0 2021-10-22 19:25:59 -07:00
Kartik K. Agaram 74f8cd15bb new fork of Lua 5.1
https://www.lua.org
2021-10-22 19:24:44 -07:00