ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 07:43 AM |
hi ^^
simple question, however I can't find it with calling a function you can do this: function thing(...) end
however I can't do this: ... = thing();
you can probably do something like this: package = {thing()}; however I don't like it is there a fancy way to return a tupple? |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 07:45 AM |
What..? O.e
function thing(...) return {...} end
thing1 = thing(args) |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 07:49 AM |
okay I will restate my question :D
I have a function that returns 0 - infinite arguments function thing() return a, b c -- etc end
how can I make it, that I get the tupple arguments ... = thing(); -- this does not work |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 08:07 AM |
| you can use unpack and a table to return an unspecified number of arguments. Of course, returning the table would be better IMO. |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 08:08 AM |
Oh. That's what you meant.
You can do that like this:
local TablizedTuple = {FunctionThatReturnsTuple(Arguments)} |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
| |
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:09 AM |
okay, it would have been fun if it was possible the way I explained I'll stick to returning tables and unpacking ^^ |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:10 AM |
@amanda that's not what I want, I want 0 - infinite arguments back since I don't want to type infinite arguments that won't work |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:12 AM |
@jarold okay so {thing()} will work, however I don't like that syntax :D thanks for the help ^^
sorry for the spamming :3 I got ninja'd |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 08:22 AM |
So you want to use the ellipsis operator?
local FunctionToHandleReturns = function(...) -- Do stuff with ... end
FunctionToHandleReturns(FunctionThatReturnsTuple(Arguments)) |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 08:22 AM |
| lol, that's even worse though :P |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:25 AM |
wow I didn't thought about that thank you for adding this :D I think I'm going to do something like this, because it looks fancy |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:27 AM |
if you do something like
function tuppleAction(...) -- stuf end
tuppleAction(functionTuppleReturn());
I think it looks quite nice ^^ |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 08:29 AM |
Couldn't you just do this?
function Var(...) return {...} end
Table = Var() |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:34 AM |
yea that's almost the same ^^ expect that the action with the ... is placed to another function instead of first making a table :D |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 08:36 AM |
You make the table in the function, then assign the returned table to a variable.
It's no different than doing: {unpack(Var())}
Doing: {Var()} creates a nested table if I'm not mistaken. |
|
|
| Report Abuse |
|
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 08:44 AM |
euh wait, I think we meant the same but say it in different words :D
-- this is packing function Var(...) return {...} end Table = Var(functionThatReturnsTupple()); -- action with table
-- first from yarold (this one is the same as Var()): table = {unctionThatReturnsTupple()}; -- action with table
--the last one from yarold was this: function tuppleFunction(...) -- action with ... end Table = tuppleFunction(functionThatReturnsTupple());
for some reason I more like the syntax of the last one, not really sure why though ^^
|
|
|
| Report Abuse |
|
|
anaIyze
|
  |
| Joined: 29 May 2014 |
| Total Posts: 2048 |
|
| |
|
| |
|
ganger800
|
  |
| Joined: 06 Dec 2012 |
| Total Posts: 427 |
|
|
| 09 Jun 2015 09:10 AM |
@analize thank you for this kind insult next time say why you think so instead of insulting please, because then I can do something with it |
|
|
| Report Abuse |
|
|
|
| 09 Jun 2015 09:15 AM |
How do you want your table to look? 1. {A, B, C} 2. {{A,B,C}} |
|
|
| Report Abuse |
|
|