Talk:Optional Arguments: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 3: Line 3:
What if you replace one of the previous arguments with 'nil'? Atleast that works with addBan().
What if you replace one of the previous arguments with 'nil'? Atleast that works with addBan().
: It depends on the function, some support that, some don't. [[User:EAi|eAi]] 21:43, 4 January 2011 (UTC)
: It depends on the function, some support that, some don't. [[User:EAi|eAi]] 21:43, 4 January 2011 (UTC)
: Lua always passes nil for elements that are not specified so it should work with all functions(cf. Programming in Lua 2nd edition p.36), unless one argument requires another optional argument to work(for example colors, you can not set red to nil and green and blue to 255 and expect it to work) [[User:Kamshak|Kamshak]] 19:18, 4 May 2011 (CEST)
:: I'm not sure that can apply with C functions, as Lua doesn't know how many arguments these take, so it can't provide nils for them. It's down to our code to handle this case. I may be wrong here though. [[User:EAi|eAi]] 19:58, 6 May 2011 (CEST)

Latest revision as of 17:58, 6 May 2011

"Optional Arguments have one limitation. You cannot use any optional arguments unless all previous arguments are also supplied."

What if you replace one of the previous arguments with 'nil'? Atleast that works with addBan().

It depends on the function, some support that, some don't. eAi 21:43, 4 January 2011 (UTC)
Lua always passes nil for elements that are not specified so it should work with all functions(cf. Programming in Lua 2nd edition p.36), unless one argument requires another optional argument to work(for example colors, you can not set red to nil and green and blue to 255 and expect it to work) Kamshak 19:18, 4 May 2011 (CEST)
I'm not sure that can apply with C functions, as Lua doesn't know how many arguments these take, so it can't provide nils for them. It's down to our code to handle this case. I may be wrong here though. eAi 19:58, 6 May 2011 (CEST)