Is there any haxy way to make .__index yield from the side that is hosting the metatable?
like:
-- .__index yield code
local t = {}
do
local mt = {}
mt.__index = function(t,k)
wait(3)
return true
end
setmetatable(t,mt)
end
-- indexing (SHOULD NOT BE CHANGED)
print(t.a)
If you intend to use __index as a way to have properties, then it shouldn’t yield anyway. I expect indexing properties to be instantanous. Have it return a function that you can call instead.
Someone else proof check this for me since I’m not home, but I remember the handling of __index in the Lua source depends on its own “sub stack” when the method is called, which would get wayyyyy too messy to fix if you attempted to yield and throw it into some sort of thread scheduler.
It makes no sense for code to yield there. In the case of needing to yield through an iteration of indices, you would just create a special iterator/enumerator thing.
Typically things should be designed to index as quickly as possible, so why do you need to yield?
(Sorry if that came off kinda mean – I’m multitasking watching my roommate play the new monster hunter lol)