I understand that Lua doesn’t allow type-based overloading like not being able to distinguish between:
function f ( string, int ) and function f ( int, string )
but I’m wondering if it allows any overloading at all. I ask because I’ve encountered the following situation. I have a few overloaded functions I define and a call to one of them.
-- functions (defined in C++ using dostring) "function TypeA:f ( szName ) " "Msg( 'inside first before' ) " "a:f( NULL, szName, NULL, NULL, NULL ) " "Msg( 'inside first after' ) " "end " "function TypeA:f ( arg1, szName, arg3, arg4, arg5 ) " "Msg( 'inside second' ) " "end " "function TypeA:f ( arg1, szName, arg3, arg4, arg5, arg6 ) " "Msg( 'inside last' ) " "end "
and it has the simple call:
"a:f ( 'test_01' ) "
When I run this call (well, I renamed things in this code to make it easier to understand), it always just goes straight to the last defined overload of the function i.e. it prints out “inside last” and nothing else. I would’ve expected it to go into the function with one parameter. Am I doing something wrong or is it that Lua simply doesn’t have overloading? All help appreciated.