Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Programming Lua - Functions, parameters "..."

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Wed Feb 08, 2017 2:20 pm    Post subject: Programming Lua - Functions, parameters "..." Reply with quote

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:
Code:
print(...)

But after all what is this "..." and how is it used.

_________________
...
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Feb 08, 2017 3:25 pm    Post subject: Reply with quote

Basic explanation:
https://www.lua.org/pil/5.2.html

Formal explanation:
http://www.lua.org/manual/5.3/manual.html#3.4.11

Even if you don't understand English that well, you should be able to mess around with the provided examples to get a basic comprehension.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Wed Feb 08, 2017 4:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Feb 08, 2017 4:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Wed Feb 08, 2017 4:31 pm    Post subject: Reply with quote

Thank you, until the end I know how to use it.
_________________
...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Feb 08, 2017 6:45 pm    Post subject: Reply with quote

http://lua-users.org/wiki/VarargTheSecondClassCitizen
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites