Skip to content

LuaBind Lua-To-C Helpers

Cluedrew Kenfar Ink requested to merge Cluedrew/solarus:lua-bind into dev

This merge request adds LuaBind, a namespace that contains tools for working with Lua. Like LuaTools, but provides some high level helpers that help with the transition to and from Lua (in this case Lua to C and back again). The namespace currently only has 3 or 4 public members, but behind them are complex template functions and dozens of little end-points that make everything work.

The core of the interface is LUA_TO_C_BIND a macro that takes a function name. The function's parameters and return types are used to construct an adapter that can handle reading the arguments from Lua and pushing the result back, allowing you to write code that does not even touch the Lua interface. However escape hatches do exist so that you can use the Lua API directly if you would like. (The only thing you can't skip is some boundary handle work.)

In addition to that I am also using this moment to do some general clean-up. Mostly by removing things from LuaContext as it has grown to an unwieldy size (it is implemented over almost two dozen files). The new functions that I am writing that use LuaBind are not members of LuaContext (I have had to make a few more members of LuaContext public, but others just took out because they didn't need to be there).

I have put a lot of work into this, yet I will insist that it is rejected if it hits an issue, as there are several issues that could make this a downgrade. Possible issues include sudden increase in binary size, execution time or compilation time, but I am not too worried about those, but I don't think simple interface is worse making the final produce worse. More likely issues, are that the code will be to hard to use and/or maintain. I wrote and then cut so much code trying to get everything in LuaBind to work, so maintenance might be an issue. I think everyone around here knows the story of LuaJIT.

If that does happen though I think some of the more modest changes would be worth keeping. Such as any clean-up that does not depend on LuaBind (the LuaContext work) or some simpler helpers.

Merge request reports