lua-users home
lua-l archive

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


On Wednesday 16 August 2006 2:56 pm, lists@grahamwakefield.net wrote:
> I want to create a fulluserdata, but assign a Lua table to it as
> metatable (mt1), and in turn assign a C++ created metatable (mt2) to
> the first (mt1)
> Essentially, I want to be able to interact with a fulluserdata as if
> it were a table by treating mt1 as a proxy, and yet still inherit
> class methods from C functions in mt2.

your C code seems to be roughly equivalent to this in Lua:

function newInstance ()
	local mt1 = {half = 0.5}
	local mt2 = getclasstable()
	local udata=newuserdata()
	setmetatable (udata,mt1)
	setmetatable (udata,mt2)
end

but what you want should be something like this:

function newInstance ()
	local innerstorage = {half =0.5}
	local mt1 = {__index = innerstorage}
	local mt2 = getclasstable()
	local udata=newuserdata()
	setmetatable (udata,mt1)
	setmetatable (udata,mt2)
end

i guess you should also put a setter function in mt1.__newindex, that is left 
as an exercise.

-- 
Javier

Attachment: pgpmI1gggKnsp.pgp
Description: PGP signature