[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Passing values by reference?
- From: Sacha Varma <sacha@...>
- Date: Sun, 15 Jun 2003 23:03:59 +0100 (BST)
Can arguments and return values be passed by reference?
I'm trying to work out how I would bind the following C function:
int * inc (int *p)
int x = 6;
assert(x == 8);
(This is a trivial example but is representative of a class of functions
in the C++ API I am trying to bind.)
In my bindings, C ints are represented in Lua as numbers. So, the above C
example would be as follows in lua:
x = 6
-- x now equals 8
Any thoughts? If there is no way to pass or return values by reference, do
I just outlaw pointers (and C++ references) in the C++ API?
BTW the binding is automated by way of a SWIG Lua 5.0 language module; if
anyone else is working on one, I would be happy to stop developing it and
be a guinea pig for someone else's.
A real function I'm trying to bind (if the above does not please you) is
const Vector3 & Vector3::Normalize()
float mag = Magnitude();
if(mag == 0.0f)
float oo_mag = 1.0f/mag;
mx *= oo_mag;
my *= oo_mag;
mz *= oo_mag;