lua-users home
lua-l archive

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


Hello

I have made a test class in C code that exposes it self to Lua, it mostly works, the only problem is that I cannot get the setmetatable code to work from C++, so for testing purposes I have been setting that on the Lua side to verify that everything else works indeed.

Lua test code is as follows:

vec = CustomVector:new(1, 2, 3)  -- CustomVector is defined in C code

setmetatable(vec, { __index = CustomVector })  -- This one should be done in C code but I could not get it to work if I have it there.

io.write("<"..vec.x.." , "..vec.y.." , "..vec.z..">\n")

io.write(vec:Magnitude().."\n")

So my question is, does anyone have a example of how to do the setmetatable for case like this from C code ?

Thanks

Björn