decimad / luabind-deboostified

Create Lua bindings for your C++ code easily - my improvements
http://www.vrac.iastate.edu/vancegroup/docs/luabind/
Other
71 stars 26 forks source link

Calling C++ functions with default arguments from Lua #40

Closed Xottab-DUTY closed 1 year ago

Xottab-DUTY commented 6 years ago

When I try to call exported function with default args luabind says, that matching overload is not found and requires to send all arguments. Is there a solution to use default args?

The following code working normally in the old luabind (~beta7-devel.rc4) but wont work with current version

void g_send(NET_Packet& P, bool bReliable = false, bool bSequential = true, bool bHighPriority = false, bool bSendImmediately = false)
{
     Level().Send(P, net_flags(bReliable, bSequential, bHighPriority, bSendImmediately));
}

inline static void CLevel_Export(lua_State* luaState)
{
    module(luaState, "level")
    [
        def("send", &g_send) //allow the ability to send netpacket to level
    ];
};
function exampleFunction()
    local packet = net_packet()
    ...  -- doing something with packet here
    level.send(packet); -- new luabind wants all 5 arguments
end

P.S. because of this we are forced to manually create overloads on C++ part (you can look here)

decimad commented 6 years ago

Are you aware how this works with the "original" luabind? My understanding is that at the moment you take the address of the method, the syntactic sugar of default arguments of a method declaration/definition is gone.

Xottab-DUTY commented 6 years ago

Are you aware how this works with the "original" luabind?

Can't say how it works in the original version..

My understanding is that at the moment you take the address of the method, the syntactic sugar of default arguments of a method declaration/definition is gone.

Is there a way to use the syntactic sugar?

decimad commented 6 years ago

Well, until I see proof of the other case, I assume it is not possible to automatically deduce default arguments given a function pointer, since the default arguments are not part of the function type

Xottab-DUTY commented 6 years ago

Can we explicitly tell to luabind default arguments, then?

decimad commented 6 years ago

Well it would be possible to specify default arguments and let luabind genrate the wrapper functions, I guess

Xottab-DUTY commented 6 years ago

Can you help with how to specify them?)

decimad commented 6 years ago

This requires enhancement of the library itself first

Xottab-DUTY commented 6 years ago

Ah.. Okay. I just don't know how to do this. Will leave it as is for now...