lua-users home
lua-l archive

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


2015-08-19 10:33 GMT+02:00 云风 Cloud Wu <cloudwu@gmail.com>:
> local t = obj.x.y.z  -- obj is an userdata
>
> We can't create separated userdata stores the separated part of obj ,
> because only one object in C. So create a proxy userdata for obj.x , obj.x.y
> and obj.x.y.z is a solution, each proxy referenced a part of obj.
>
> It's not enough, we also need create a weak table in obj to cache "x" "x.y"
> and "x.y.z" proxy userdata, because we can't returns different proxy
> userdata for obj.x when we call obj.x more than once.  (obj.x should be
> unique, when we need use it as a table key later)
>
> If this tree based document is large and deep, we need create too many small
> full userdata to access each part of it. It's very expensive now , and not
> necessary to clone the whole tree from C to lua with lua table.

This particular use case can be handled in a straightforward way
by a method.

local t = obj:retrieve(x,y,z)