Same name, different class/function, that is what, polymorphism is.
It doesn't really make sense talking about it in Lua, since only with a couple of ugly hacks(which normally result in poorer performance), you can achieve object oriented programming, and as far as I have ear or tried, you can't have two functions with the same name(well, you can, but it won't do you anything). If someone can prove me wrong, please do

Anyhow, for a pseudocode(in Lua) version of polymorphism:
function OpenDoor(location, key) do
door = getDoor(location)
insert(key, door)
turn(key, door)
push(door)
end
function OpenDoor(location) do
door = getDoor(location)
push(door)
end
Two functions with the same name, but do different things. In this case, the second since doesn't have arg key, only tries to push the door(This can be extended much further, since in C++ you have to declare variable types, so it's not only about nÂș of variables, but also they're variables.
Yes, I know, this is a very poor example, the best I could come up with.
Also, if you REALLY want to, yes, you can simulate polymorphism in Lua. You just need to check the arguments types(if it's nil, it wasn't provided, so...)