moonjit / moonjit

Just-In-Time Compiler for the Lua Programming language. Fork of LuaJIT to continue development. This project does not have an active maintainer, see https://twitter.com/siddhesh_p/status/1308594269502885889?s=20 for more detail.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coroutine.clone

sharpobject opened this issue · comments

Hello,

Please consider including coroutine.clone in a future 2.1.x or 2.2.x release.

The patch was originally distributed on the lua mailing list here, but Mike amended the patch in a reply to the same thread: http://lua-users.org/lists/lua-l/2006-01/msg00652.html

A toy motivating example is here: https://github.com/torus/lua-call-cc

Another motivating example, which I surely cannot do justice to in this brief post:

Imagine you are making an online multiplayer video game, and your online multiplayer video game is made under the assumption that time is divided up into 16.667ms time slices, and each time slice contains a single input state from each player (maybe a 12-bit input state? 4 bits for a joystick and 8 bits for 8 buttons?), and the game state at a time t is a deterministic function of the game's initial conditions and all the inputs from all players from the beginning until time t. Further, suppose that you would like each player to experience a constant amount of netplay-induced input latency (that is, you would not like to increase or decrease the local input latency based on changes in network latency during the game). Then, you'll sometimes need to speculatively execute some game updates, and be prepared to go back to a previous state and advance back to the present whenever inputs you receive from another player inform you that your speculative execution has diverged from reality. This is called "Rollback netcode" and you can read about it here or here or watch a video here or here.

Imagine further that some people on your team are not galaxy brain software engineers, and just want to write some imperative scripts to dictate the behavior or a certain move or a certain projectile in the game across many frames. Then, the galaxy brain software engineers might attach coroutines to the game objects to provide this sort of simple scripting environment for less technical people, and the coroutines will become part of the game state, and when the galaxy brain software engineers add rollback netcode the coroutines will need to be copied along with the rest of the game state.

Thanks!

AFAICT, this is not really part of the Lua API yet. Did you try reviving the thread in lua-users to see if they're interested in adding it? I see two scenarios:

  1. They're interested and would like to work a bit more on the specification, etc. and eventually get it in. That gives us a good reference to implement and we don't end up with conflicts if a lua implementation were to come up in future
  2. They're absolutely not interested, which makes having an extension a little bit safer for us in moonjit since (hopefully!) they'll never implement something like this, at least not in the same namespace.

To elaborate on my concern, there are already way too many flavours of lua/luajit implementations out there and I want to avoid making moonjit a distinct n+1th flavour. If anything, my primary goal (or hope!) is to try and unify these flavours to the extent I can.

Alright, I'll try to get PUC-Rio Lua solidly into one of those two categories.

Thanks! I'll keep this open so that we can continue the conversation later.