lua-users home
lua-l archive

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

Payo Nel <> 于2020年4月25日周六 上午3:17写道:

> ```lua
> function wrapSingleUserdata(data)
>   for k, v in pairs(wrappedUserdata) do
>     if v == data then
>       return k
>     end
>   end
>   local proxy = {type = "userdata"}
>   local methods = pcall(userdata.methods, data)
>   for method in pairs(methods) do
>     proxy[method] = setmetatable({name=method, proxy=proxy}, userdataCallback)
>   end
>   wrappedUserdata[proxy] = data
>   return setmetatable(proxy, userdataWrapper)
> end

`data` could be in tobefnz (to be finalize) list , but not in
`wrappedUserdata` set at that time. So it's possible to create a new
proxy with the same data, and then the __gc of old proxy be called.

`wrapSingleUserdata` want to guarantee the proxy of a userdata is
unique. But iterating the `wrappedUserdata` can't offer this
lua-l mailing list --
To unsubscribe send an email to