| View previous topic :: View next topic |
| Author |
Message |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Wed Feb 08, 2017 2:20 pm Post subject: Programming Lua - Functions, parameters "..." |
|
|
It is as follows, you can create a function like this:
| Code: | | function test_function(...) |
| Code: | | function test_function(param1, ...) |
And you can pass this as a parameter:
But after all what is this "..." and how is it used.
_________________
... |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4709
|
|
| Back to top |
|
 |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Wed Feb 08, 2017 4:17 pm Post subject: |
|
|
I did not get anything, I do not understand what is wrong. Could you show a simple example of a function and a function call using this?
Because I try to catch the examples most of the mistake.
I tried to write that too, but also the error.
| Code: | function g(...)
print(arg[1])
end
g(10, 20, 24) |
_________________
... |
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4709
|
Posted: Wed Feb 08, 2017 4:26 pm Post subject: |
|
|
Oops. That version of PIL was written for Lua 5.0. Seems like the implementation has changed since 5.1 (CE uses 5.3).
For a quick workaround, use this:
| Code: | function g(...)
local arg = {...} -- arg is now a table of all extra values passed to g
print(arg[1])
end
g(10, 20, 24) |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
| Back to top |
|
 |
Filipe_Br Master Cheater
Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Wed Feb 08, 2017 4:31 pm Post subject: |
|
|
Thank you, until the end I know how to use it.
_________________
... |
|
| Back to top |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
|
| Back to top |
|
 |
|