Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Xottab-DUTY opened this issue Apr 12, 2018 · 8 comments
Closed

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

Xottab-DUTY opened this issue Apr 12, 2018 · 8 comments

Comments

@Xottab-DUTY
Copy link

Xottab-DUTY commented Apr 12, 2018

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
Copy link
Owner

decimad commented Apr 15, 2018

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
Copy link
Author

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
Copy link
Owner

decimad commented Apr 15, 2018

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
Copy link
Author

Can we explicitly tell to luabind default arguments, then?

@decimad
Copy link
Owner

decimad commented Apr 15, 2018

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

@Xottab-DUTY
Copy link
Author

Can you help with how to specify them?)

@decimad
Copy link
Owner

decimad commented Apr 15, 2018

This requires enhancement of the library itself first

@Xottab-DUTY
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants