lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Yes that looks good. But I have a vector/matrix library written in C++ that
I want to use. I'd like to make it as easy as possible for my (LUA
implemented as script) users to access elements. Therefore I have an
overloaded operator ().

C++ :

declaration:
double& operator() (int, int);

implementation:
double& matrix::operator() (int m, int n)
{
   if (m <= 0 || m > m_nRows || n <= 0 || n > m_nCols)
      Throw(IndexException(m, n, *this));
   return data[(m - 1) * ncols + n - 1];
}

Is it possible to implement this operator as a LUA extension, so my Users
can write a vaild LUA statement like: 

mat = matrix:new(NumCols, NumRows)
mat(1, 1) = 12
mat(1, 2) = 56
mat(2, 1) = 98
mat(2, 2) = 32
mat:delete()

cheers,
Chris