fengari-lua / fengari-web

Provides everything you need to run Fengari in the browser.
MIT License
250 stars 18 forks source link

Partial io support, especially io.stdin:read? #39

Open airstruck opened 5 years ago

airstruck commented 5 years ago

How much trouble would it be to add support for io.stdout:write, io.stdin:read, io.open in read mode, and file:read?

I assume io.stdout:write is easy; basically a print without tabs or newlines, that'll fail on printing most non-string types. It should also probably flush itself, if possible.

Not sure how difficult io.stdin:read would be, but seems possible at least.

And I guess opening a file in read mode could use whatever tricks require uses, right?

That probably covers most of the commonly-used stuff from io. Is there any interest in this? I'd be willing to take a crack at it myself, although I just discovered this project and I'm sure someone else could get it done faster and better.


If only one of these things can happen, a blocking io.stdin:read is probably the most essential. The rest of it can probably be worked around pretty easily. Meanwhile, if anyone knows of a possible workaround for io.stdin:read, I'd be interested in hearing about it.

daurnimator commented 5 years ago

The problem is that without __gc support, you leak file descriptors. This makes io.open a foot-gun waiting to happen.

Additionally, there is no solid concept of a "file" on the web, so you're better off using fengari-interop to call whatever file-like API you want.

daurnimator commented 2 years ago

whatever tricks require uses, right?

What trick are you referring to?