23 posts
Posted 06 April 2015 - 12:02 AM
If I do this i get a "java.lang.arrayindexoutofboundsexception" error, so whats the proper way to do this?
function doSomething(parameter)
...
end
function doSomething()
doSomething(default_parameter)
end
EDIT: Yes, it was JAVA syntax, now it is LUA ;)/> (like it was intended to be)
Edited on 05 April 2015 - 10:41 PM
2427 posts
Location
UK
Posted 06 April 2015 - 12:18 AM
why is this forum thread tagged as lua when you are using java?
or if this is lua
function doSomething(parameter)
parameter = parameter or default_parameter
...
end
3057 posts
Location
United States of America
Posted 06 April 2015 - 12:24 AM
Assuming you were using the correct syntax while testing, arrayindexoutofboundsexception is triggered if a function calls itself more than 256 times. Which you are managing to do, since your doSomething( parameter ) is overwritten by your declaration of doSomething()
355 posts
Location
Germany
Posted 06 April 2015 - 12:25 AM
why is this forum thread tagged as lua when you are using java?
or if this is lua
function doSomething(parameter)
parameter = parameter or default_parameter
...
end
Your example fixes the problem, the array itself comes from java, since he's calling his own function recursively, unteil the callstack reaches it's limit of 256(?)
Just to comment about your solution:
In lua, you cannot have multiple overloads to one function. The latter overrides always the previous.
Another aspect of the funcionality is, that it is perfectly fine to pass nothing(nil) to a function, even if it's definition contains one.
The functions itself need to check for their inputs and need to take actions(exceptions, or different/default behaviour) on specific inputs.
2427 posts
Location
UK
Posted 06 April 2015 - 12:32 AM
function doSomething(parameter)
parameter = parameter or default_parameter
...
end
In lua, you cannot have multiple overloads to one function. The latter overrides always the previous.
Another aspect of the funcionality is, that it is perfectly fine to pass nothing(nil) to a function, even if it's definition contains one.
The functions itself need to check for their inputs and need to take actions(exceptions, or different/default behaviour) on specific inputs.
either I have not understood any of this, or my example covered all this
23 posts
Posted 06 April 2015 - 12:39 AM
why is this forum thread tagged as lua when you are using java?
or if this is lua
function doSomething(parameter)
parameter = parameter or default_parameter
...
end
I've used the wrong syntax for this post, sorry :(/> . I normally write in Java or vb.net.
But thanks for your answer.