|
Post by noobler on May 22, 2023 17:47:10 GMT
why we cant use coroutine with ankulua?
ive tried and cant get it work
function printMsg(msg)
while true do
print(msg)
coroutine.yield(1)
end
end
local co = coroutine.create(printMsg)
coroutine.resume(co, "Hello, world!")
while true do
coroutine.resume(co)
end
|
|
|
Post by AnkuLua on May 23, 2023 13:27:25 GMT
Sorry. There is problem on calling Java function from coroutine. print() is mapped to Java function in AnkuLua. And all AnkuLua methods are java functions.
|
|
|
Post by noobler on May 24, 2023 6:49:21 GMT
Sorry. There is problem on calling Java function from coroutine. print() is mapped to Java function in AnkuLua. And all AnkuLua methods are java functions. what can we use for parallel coding or multitasing? cant we use activity.runOnUiThread() and proxies to run the java methods on main thread while using coroutine? sadly i'm not good with luajava but cant we do something like this? local function myCoroutine()
activity.runOnUiThread(
luajava.createProxy("java.lang.Runnable", {
run = function()
MyJavaClass.myJavaFunction()
end
})
)
end
local myCoroutineThread = coroutine.create(myCoroutine)
coroutine.resume(myCoroutineThread)
|
|
|
Post by AnkuLua on May 24, 2023 7:58:56 GMT
First, lua coroutine is not real parallel multitasks. There is only one thread running at the same time. The script uses yield and resume to control which coroutine to run. There is no clear benefit for AnkuLua to run coroutine.
|
|
|
Post by noobler on May 24, 2023 9:02:00 GMT
First, lua coroutine is not real parallel multitasks. There is only one thread running at the same time. The script uses yield and resume to control which coroutine to run. There is no clear benefit for AnkuLua to run coroutine. is still usefull for asynchronous operations tho, like "real time" network requests while without blocking main function, also can build user interactions without pausing the code. Can be usefull prioritize certain tasks too even if isn't real multithread. if exists other ways to archive some sort of multitasking even for small tasks without coroutine will be awesome to learn them and implement them. Thanks again for answering
|
|