lua-users home
lua-l archive

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


> Would it be best to make m and v user data objects, [...]

That depends on how ofter you will use these data in Lua and in C. If in
Lua, then it is better to represent your data as Lua tables, and to write
your C code so that it accesses those tables when it needs the numbers.

Otherwise, you can have them represented as userdata, plus two Cfunctions
registered in Lua to set and get their values. Then you can use 'settable'
and 'gettable' to manipulate the data using Lua syntax:

settagmethod(MATVEC, 'gettable', getCvalue)
settagmethod(MATVEC, 'settable', setCvalue)


print(v[3])  -- calls 'getCvalue' to get value from array in C

-- Roberto

PS: maybe you should change your matrix to something like

m = matrix{{1.0, 0.0, 0.0, 0.0}, 
           {0.0, 1.0, 0.0, 0.0}, 
           {0.0, 0.0, 1.0, 0.0}, 
           {0.0, 0.0, 0.0, 1.0}} ;

with explicit rows and columns.