Skip to content

runtime: introduce LuteLibrary shared interface for runtime modules.#959

Open
aatxe wants to merge 5 commits intoprimaryfrom
awe/library-refactor
Open

runtime: introduce LuteLibrary shared interface for runtime modules.#959
aatxe wants to merge 5 commits intoprimaryfrom
awe/library-refactor

Conversation

@aatxe
Copy link
Copy Markdown
Member

@aatxe aatxe commented Apr 8, 2026

There's a lot of inconsistency between the different runtime library definitions, and it's bothered me for a while. To try to make things more structured, this PR introduces a shared interface LuteLibrary and refactors each library namespace to instead be a struct that implements that LuteLibrary interface. The goal here is to make it more difficult to author a library that isn't structured how we would expect, and to bring all of the existing libraries into that uniform structure.


I'm not necessarily 100% convinced that this is worth it, but I think it came together well enough that I want to solicit other opinions on it. Does this look and feel better to work on going forward? It definitely looks to make headers, especially, a lot more uniform. The static_asserts in particular are a bit janky, but it seems arguably nicer than the alternative of doing an abstract class with all of these fields virtual.

@aatxe aatxe self-assigned this Apr 8, 2026
@aatxe aatxe added the runtime Work in the C++ runtime portion of the code label Apr 8, 2026
@aatxe aatxe requested review from Vighnesh-V and hgoldstein April 8, 2026 23:19
Comment on lines +45 to +51
static int openAsGlobal(lua_State* L)
{
verifyInterface();
Derived::pushLibrary(L);
lua_setglobal(L, Derived::kName);
return 1;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a small q - this function uses ::pushLibrary and ::kName so it makes sense to assert for them. Does it still make sense to assert for lib and properties, since these can just be implementation details wherever they are needed, and the derived classes don't have to use properties if they aren't exported?

static int openAsGlobal(lua_State* L)
{
verifyInterface();
Derived::pushLibrary(L);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it's possible for this to exist as an implementation on the LuteLibrary? I'm looking at the existing pushLibraries we have and it looks like they're all doing pretty much the same thing? I guess metatable initialization is the main difference here right?

Copy link
Copy Markdown
Collaborator

@Vighnesh-V Vighnesh-V left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is really good - I'm just curious if we can move even more stuff into generic lute initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

runtime Work in the C++ runtime portion of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants