YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Returning value from function in parameter
pointer
#1 Posted : Friday, December 16, 2016 8:26:23 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 12/16/2016(UTC)
Posts: 3

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Hi Folks,

Is there way to return value from function in parameter? Is there some kind of reference or pointer to parameter available in code?

For example:

Code:


function hello(param1) {
        param1="HELLO WORLD\n";

}

local test = "HELLO\n";


hello(test);


print(test);



Returns me "HELLO" instead of "HELLO WORLD".

Thanks for help!

absence
#2 Posted : Saturday, December 17, 2016 3:44:00 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 102
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 8 time(s) in 8 post(s)
Tables and arrays (and classes/instances) are always references.
(Though strings are internally references too, they _resolve_ any changes so referencing is ineffective at the surface)
Hence, use tables or arrays for indirection:

Code:


function foo(param1,param2)
{
   param[0]="Hello world" ;
   param2.test<-"Hello world" ;
}

local text=["Hello"] ;
local text2={ test="Hello" ; }

print (text) ;  //prints "Hello"
print (text2) ;  //prints "Hello"
foo(text,text2) ;
print(text[0]) ; //prints "Hello world"
prin (text2.test) ; //prints "Hello world"



Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.062 seconds.