Hi all,
I’ve come across an issue when attempting to call into the Codea API from within a coroutine.
The example below shows the issue clearly and simply calls exactly the same function both in and out of a coroutine:
-- CoroutineTest
--
-- Call the same function from a coroutine & the main thread.
function setup()
-- Coroutine
local co = coroutine.create(function(fn)
return fn()
end)
-- Main Thread
local fn = layout.___getters.safeArea
print("fn=" .. tostring(fn))
local fn_res = fn()
local _,cofn_res = coroutine.resume(co, fn)
-- Analyse results
print("mn ret=" .. tostring(fn_res))
print("co ret=" .. tostring(cofn_res))
-- As we're calling exactly the same function we would expect the
-- return types to be identical (not the same object but same type).
--
-- It looks like when called from a coroutine, the function returns itself!?
if type(fn_res) ~= type(cofn_res) then
objc.warning("Return types do not match!")
end
end
This then produces the following in the output pane:
fn=function: 0x2994ae3d0
mn ret=table: 0x288009ac0
co ret=function: 0x2994ae3d0
Return types do not match!
I’ve attempted to figure out what’s going wrong myself and I’ve used the ___getters
value as it appears to be as far as debugging from Lua can take me.
Could anyone shed some light on what’s going on here please?
Cheers,
Steppers