Commit Graph

791 Commits

Author SHA1 Message Date
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 36ef0c236e a simple test "app": towers of hanoi
Currently it works with stock Lua and lcurses. Our job now is to build
in the bindings to make it work here.
2021-10-23 22:28:00 -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