08-14-2017, 06:44 AM
I think I have a great new revolutionary way of writing API bindings. I'll polish things up and try to rewrite a few manual bindings to verify it works, but then it should be a breeze to add new bindings. Possibly even the ToLua++-generated bindings could be rewritten to use the new way.
Basically, you can now do this:
Basically, you can now do this:
int someBindingFunction(lua_State * a_LuaState) { cLuaState L(a_LuaState); int overloadUsed; cPlayer * self; int paramI1, paramI2, paramI3; AString paramS1, paramS2; L.ReadParams(overloadUsed, std::tie(self, paramI1, paramS1), std::tie(self, paramI1, paramI2, paramS1), std::tie(self, paramI1, paramS1, paramI2), std::tie(self, paramI1, paramI2, paramS1, paramS2, paramI3) ); // Reads all params, chooses the right overload, reports any errors if none matches switch (overloadUsed) { case 0: { // paramI1, paramS1 are valid break; } case 1: { // paramI1, paramI2, paramS1 are valid break; } case 2: { // paramI1, paramS1, paramI2 are valid break; } case 3: { // paramI1, paramI2, paramS1, paramS2, paramI3 are valid break; } } }