Coding 2024-08-28

By Max Woerner Chase

Okay, I've tried to work out some stuff for this Lua code in my head, and it's not working out. Let's try to hash this out in a blog post.

I want to have Lua modules, which can be used in, technically, three different ways:

I've managed to write a utility function to check whether some code is running as a direct result of a lua command, via if debug.getinfo(4) then. It's weird-looking and unintuitive, but it works.

Now, let's think about command-line parsing. I want the result of parsing to be a table, which is passed to a function...

Thinking about stuff like cleanup and control flow, I think this function should use the coroutine library to do something sort of like Python's context managers.

So, let's see how I think things should go together. There should be a function that takes a table input, and performs some action. There should be a function that converts a list of strings to a table.

This table may contain an array of unparsed strings, and a similar pair of functions.

These need to be handled by a runner that takes a table containing those functions, and optionally a list of strings.

Then, the debug.getinfo wrapper needs to be able to take a callback for the script case.

All of this has, of course, completely ignored the logic behind "parsing out arguments and options into a table".

Here's a weird idea: instead of collecting option values into a table, return them from a function, so it just uses multiple returns if there are multiple values... This idea would have a slight issue of not distinguishing "didn't pass anything to a flag that takes an optional argument" from "didn't pass the flag at all"... At least, it can have that issue, depending on the details of how I implement it...

:)

Wait, so, you're trying to represent RPG character sheets in a machine-trackable format, right?

Yes...

:) (glitchier)

So why the HECK are you trying to clone Click in Lua‽

Haha, that's all for now folks, I'll try to start coding stuff up tomorrow.

Good night.