fengari-web icon indicating copy to clipboard operation
fengari-web copied to clipboard

Partial io support, especially io.stdin:read?

Open airstruck opened this issue 6 years ago • 2 comments

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.

airstruck avatar Jul 26 '19 18:07 airstruck

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 avatar Jul 27 '19 00:07 daurnimator

whatever tricks require uses, right?

What trick are you referring to?

  • The in-built js library is already loaded in fengari-web; same as all lua standard libraries. https://github.com/fengari-lua/fengari-web/blob/77d35f5e1516f431cbb96e165b4272f2fc9b0b3a/src/fengari-web.js#L84
  • fengari-loader uses webpack to fill up the lua preload table

daurnimator avatar Mar 07 '22 03:03 daurnimator