pass variable by refernce

Hi,

Silly question.. how do you pass a variable by ref to a function in lua

ie

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local a = 1
 
function test(a)
 
a = a + 1
 
end
 
test(a)
 
print(a)
 
<code>
 
I want 'a' to print 2... 

primitives (ints, strings and booleans) are passed by value only, where as tables are passed by reference.

The reason that other languages used reference or value was in a way to return multiple values, Lua can anyways return multiple values, so if you had code like

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 local a = 2
 local b = 3
 local c = 4
 
 function doubleit(a,b)
  return a*2, b*2
 end
 
 a,b = doubleit(a,b)
 a,c = doubleit(a,c)
 b,c = doubleit(b,c)
 
 print("a = ", a)
 print("b = ", b)
 print("c = ", c)

Thanks mate... I really appreciate the help

views:1398 update:2011/10/17 8:58:49
corona forums © 2003-2011