[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C++ Integration and Assignments
- From: "Thomas Lefort" <thomas.lefort@...>
- Date: Fri, 22 Sep 2006 03:20:29 +0200
-- I want to write code like this
v = new( "Vector" );
v:SetNull();
v.x = 0.2; -- for now, i must write: v.x:Parse( CreateString( "0.2" ) );
v.y = 1.5; -- for now, i must write: v.y:Parse( CreateString( "1.5" ) );
-- i need to hook to the assignment operation in order to correctly set
v.x.
Just use the __newindex metamethod. It could look like this:
function __newindex(u, k, v)
local class = getmetatable(u)
local mutator = class.mutators[k]
if mutator then
mutator(u, v)
else
error(string.format("missing mutator %s in class %s", tostring(k),
tostring(class)), 2)
end
end