wren-lang / wren-cli

A command line tool for the Wren programming language
MIT License
129 stars 31 forks source link

ER: import from a specified location #130

Open pkoppstein opened 2 years ago

pkoppstein commented 2 years ago

Over at https://github.com/wren-lang/wren/issues/346 I see:

munificent commented on Jun 1, 2016 | it's designed to allow the user to load the modules from wherever it needs to, right? Exactly right.

That does not seem to be true of wren-cli. I think it should be possible to specify an absolute path. Or am I missing something?

Example

$ cd /tmp

$ wren --version
wren 0.4.0

$ cat float.wren
import "/Users/user/github/wren-essentials/src/modules/json" for JSON
var x = JSON.parse("1.24")

$ file /Users/user/github/wren-essentials/src/modules/json.wren
/Users/peter/github/wren-essentials/src/modules/json.wren: C++ source text, ASCII text

$ wren float.wren
Could not load module './Users/peter/github/wren-essentials/src/modules/json'.
[./float line 1] in (script)

Changing the first / in the import to // did not help.

ruby0x1 commented 2 years ago

you might be looking for https://github.com/joshgoebel/wren-console/ ?

pkoppstein commented 2 years ago

@ruby0x1 - No, this question has nothing to do with wren-console or JSON. It is about specifying the location of a module in an arbitrary location, as per the "subject". Thanks anyway.

ruby0x1 commented 2 years ago

Module resolution is handled by the host, so for example how dome handles modules is different to wren cli, and the log you linked mentioned stuff from wren console (specifically wrenc) which implied the resolution question might be host specific. @joshgoebel can check, I haven't read into the issue just yet.

joshgoebel commented 2 years ago

@ruby0x1 I don't know what this is (from the log)... wren-console shows both the host and wren version when asked. (the prior --version output from 0.2.91 was even longer)

% wrenc --version
wrenc v0.3 (with wren v0.4)

My guess was they were using wren-cli renamed to Wren but compiled from source (hence the 0.4, but I didn't look to confirm)?

@pkoppstein wren-essentials contains binary modules (including JSON)... so that's not going to work well with just an import anyways (even if you get the path sorted)... you'll need to build it into your binary CLI (or use wren-console which does that for you).

There is of course the experimental binary module loading support, but as mentioned in the, very experimental.

joshgoebel commented 2 years ago

@pkoppstein I think you'll find wren-cli simply doesn't know how to resolve absolute paths. Only "relative" and simple paths (ie, built-ins)...

Reference: https://github.com/wren-lang/wren-cli/blob/main/src/cli/vm.c#L135

This is something wren-console supports IIRC (there are several PRs along those lines) - as it's module loading system has been mostly/entirely re-written (in Wren). I'd suggest this issue be renamed to be a feature request asking that wren-cli add absolute path support.

pkoppstein commented 2 years ago

@joshgoebel - I've added ER to the "subject" as you suggested. I was originally going to do so, but then I came across the munificent quotation at the very top of this thread, so it began to look more like a bug. Thanks.

@ruby0x1 - Sorry for the confusion about wren-console vs wren-cli. I guess you saw my original post via Discord, rather than the revision that I posted almost immediately afterwards.