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

Add support for node.js, Firefox, Chromium #39

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

pipcet
Copy link
Contributor

@pipcet pipcet commented Apr 23, 2017

Start addressing #36. nodejs ./forth should simply work; Firefox should work after copying forth to forth.js and forth.html to forth.html in the lbForth/ directory; with the right security settings, a file:/// url will work, but with a web server, it should always work. Chromium won't work with file:/// urls (I believe there are command line options to fix this but I keep forgetting them), but should work with a web server just like Firefox does.

I can't really test Microsoft browsers, but I'm optimistic it shouldn't be too hard to get them working.

No VT100 emulation yet, and the first line of output ("lbForth") gets eaten right now.

@larsbrinkhoff
Copy link
Owner

Thank you.

I tried to test this. I loaded the forth.html file locally in Firefox, and also made a gh-pages thing: http://larsbrinkhoff.github.io/lbForth/targets/asmjs/forth.html

In both cases, typing something in the input field displays something above it, but quickly dissapears. If I type e.g. words, I don't see the expected output.

@larsbrinkhoff
Copy link
Owner

Tested with nodejs:

$nodejs --version
v0.10.25
$nodejs asmjs-forth

readline.js:73
    terminal = !!output.isTTY;
                       ^
TypeError: Cannot read property 'isTTY' of undefined
    at new Interface (readline.js:73:24)
    at Object.exports.createInterface (readline.js:39:10)
    at Object.<anonymous> (/home/lars/src/lbForth/asmjs-forth:52:23)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

Maybe that version is ancient. It's what I got in Ubuntu 14.

@larsbrinkhoff
Copy link
Owner

I added testing with nodejs to the Travis build. I expect it to fail for now, but I'll fix that.

@larsbrinkhoff
Copy link
Owner

Newlines in stdin doesn't quite work in nodejs. SpiderMonkey is fine:

(echo 42; echo 42 .s) | js24 asmjs-forth
lbForth
ok
 ok
<2> 42 42  ok

But nodejs:

(echo 42; echo 42 .s) | nodejs asmjs-forth
lbForth
ok
<1> 4242  ok

@larsbrinkhoff
Copy link
Owner

I made a hack to add a newline to the nodejs input. This makes the tests pass. BUT it now seems the newlines are sometimes doubled in the input.

{
var n = document.getElementById("output");

if (n) n.innerHTML += str;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check n? Isn't the output div always present in this html file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forth_output gets called before the HTML file has been parsed, so it's necessary to drop (or delay) the first line of output. In Firefox, this is much simpler, since you can simply defer execution of the script until after the HTML has been loaded.

@pipcet
Copy link
Contributor Author

pipcet commented Apr 24, 2017

The forth.html needs to be in the lbForth/ folder, not targets/asmjs/, or we won't find load.fth.

@larsbrinkhoff
Copy link
Owner

@pipcet
Copy link
Contributor Author

pipcet commented Apr 24, 2017

It seems old versions of readline require an output parameter even if no output is intended. Furthermore, as you've discovered, they don't necessarily wait for one line to complete handling before queueing the second.

I think I've fixed both issues, can you verify the duplicated newlines are gone?

@pipcet
Copy link
Contributor Author

pipcet commented Apr 24, 2017

I think you still have the wrong URL there.
http://larsbrinkhoff.github.io/lbForth/forth.html works for me.

@larsbrinkhoff
Copy link
Owner

Yes, sorry. I mean that URL.

@larsbrinkhoff
Copy link
Owner

larsbrinkhoff commented Apr 24, 2017

Newlines seem good.

Node.js echoes doubly when used from the command line.

@pipcet
Copy link
Contributor Author

pipcet commented Apr 24, 2017

I can reproduce that within Emacs, which readline presumably doesn't recognize as a "terminal", but not in an xterm.

Hopefully fixed. It'd probably be best to avoid the readline library entirely and rely on OS buffering...

@larsbrinkhoff
Copy link
Owner

Right, I run my shell in Emacs 99% of the time. It does produce strange effects occasionally.

@larsbrinkhoff
Copy link
Owner

I think this is fine for merging now.

@pipcet
Copy link
Contributor Author

pipcet commented Apr 24, 2017

Okay, cool. I've squashed the commits.

@larsbrinkhoff larsbrinkhoff merged commit 3eb3fda into larsbrinkhoff:master Apr 24, 2017
@larsbrinkhoff
Copy link
Owner

Thanks!

@larsbrinkhoff
Copy link
Owner

IE11 doesn't work, but meh.

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

Successfully merging this pull request may close these issues.

2 participants