Hi all,
I'm now trying to port vim into javascript with emscripten.
The main barrier I found is that the async model of JavaScript. JavaScript
is event-driven, and there is no mechanism to sleep and wait for events to be
processed, so the following won't work:
```
void wait_for_input()
{
// wait until there's some input
while(!input_available())
mch_delay(50); // there's no sleep() in JavaScript, and we cannot do a
busy-wait here
}
// in gui_start()
// do something
wait_for_input()
// do something else
```
Instead we have to split the function to make the function call async:
```
static callback_t wait_for_input_cb;
void wait_for_input()
{
if(!input_available())
mch_delay_async(50, wait_for_input);
else
wait_for_input_cb();
}
// in gui_start()
// do something
wait_for_input_cb = gui_start_cb;
wait_for_input();
} // end gui_start() here
void gui_start_cb()
{
// do something else
```
Generally it's hard to maintain both versions, I'm trying to define some
macros to ease the process, but the code is still not readable due to function
splitting. The easiest way of doing this is to simulate the async model in the
sync model, which would however introduce (un-necessary) overhead for sync
situations.
The worst case is that the async (JavaScript) version has to be maintained
separately, but I wonder if there are better solutions?
Please let me know what you guys think about it.
Thanks!
regards,
- Lu Wang
2013.11.30
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.