Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Async Overhaul #253

Open
volundmush opened this issue Dec 29, 2023 · 0 comments
Open

[Feature Request] Async Overhaul #253

volundmush opened this issue Dec 29, 2023 · 0 comments

Comments

@volundmush
Copy link

The Python environment has grown significantly with the advent of asyncio. The ability for Lua to cleanly interact with Python Coroutines (IE: async def func():) would be a golden addition to Lupa.

I have done some experimenting and realized that it is possible to achieve interaction of a sorts - for it to work, Lua must coroutine.yield() a Python coroutine, and whatever managing environment that called lua_coro.send() must be asynchronous.

async def run(self):
   val = self.lua_coro.send(None)
   
   if asyncio.iscoroutine(val):
       res = await val
       self.lua_coro.send(res)

etc. Throw that asyncio.iscoroutine into a while loop and you could have an environment which continuously 'awaits' values.

But this isn't very convenient or intuitive.

when working in Lua, what would be great is if you could call a function/method, like ... obj:getAttribute("strength") and for Lupa to realize 'oh, it's calling a Python coroutine. I should await.' you could have something like an asynchronous version of lua_coro.send() which does this for you.

I might be willing to work on a PR for this myself if I know if the feature would be welcome. Admittedly I've never touched Cython before so I'm a bit daunted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant