evo-lua / evo-runtime

All-in one Lua runtime based on LuaJIT and libuv
https://evo-lua.github.io
Mozilla Public License 2.0
10 stars 1 forks source link

Deduplicate the C definitions for static FFI exports to make the bindings easier to maintain #506

Closed Duckwhale closed 5 months ago

Duckwhale commented 5 months ago

Some of the definitions unfortunately can't be checked by the compiler. But overall, reduces the amount of boilerplate code:

More cleanup will be needed to remove the bindings member of each library, but this is far too large already.

Duckwhale commented 5 months ago

Just a quick note for future me as to why embedding the cdefs turned out to be so overly complicated:

In short, all solutions are terrible and I'm not sure which one is the least of a headache. Give me std::embed already, will you?

Duckwhale commented 5 months ago

I really am not a fan of this given the increase in complexity. The drawbacks simply don't seem worth it (without std::embed):

Since one goal is to make sure the FFI and C++ definitions are always in sync, maybe there's a simpler way to get that benefit:

This would still necessitate code duplication, but if the test suite catches any discrepancy then it might not be a huge problem.

Duckwhale commented 5 months ago

Closing for now due to the above concerns. It's too large a PR to merge as-is anyway; will split off some parts when applicable.