|
On 23/06/15 03:19 PM, Rena wrote:
__call and co() makes it look like a function call, which may be kinda confusing. On the other hand OOP syntax co:resume() is more Lua-like, as strings have it too. You also cannot index functions.On Tue, Jun 23, 2015 at 2:11 PM, Soni L. <fakedme@gmail.com> wrote:On 23/06/15 03:09 PM, Sean Conner wrote:It was thus said that the Great Luiz Henrique de Figueiredo once stated:co = coroutine.create(function() print"test" end) ... Can we get a thread metatable?debug.setmetatable(co,{__len=function(thread) return "abc" end}) print(#co) --> abcI think the OP wants debug.setmetatable(co,{__index=coroutine}) so that he can say co:resume().Or debug.setmetatable( co, { __call = function(co,...) return coroutine.resume(co,...) end } ) so that we can say co() -spcAnd how do you get the status with that? Not co:status(), that wouldn't work... -- Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.By using both __call and __index.
If you need a function, you can uselocal f = coroutine.wrap(function(myfunc) return myfunc(coroutine.yield(coroutine.running())) end)
local co = f(myfunc)-- pass f around to use it as a function, pass co around to use it as a coroutine.
Idk, but for me, making coroutine.wrap semi-redundant (some things would still error when they meet a coroutine) is just meh.
Just for consistency. -- Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.