wu-lang / wu

🐉 A practical game and data language
https://wu-lang.gitbook.io/guide/
MIT License
467 stars 17 forks source link

[bug] import still doesn't behave predictably #38

Open evolbug opened 3 years ago

evolbug commented 3 years ago

When compiling imports should behave by this system:

compile file:       all imports are relative to initial file
compile directory:  all imports are relative to initial directory
build project:      all imports are relative to src/

The resulting require statements should also use . to separate path elements instead of / and should not contain a ./ prefix

project/
    src/
        lib/
            init.wu
            mylib.wu
        main.wu
    wu.toml

Contents:

# main.wu
import lib { mylib }

# init.wu
import mylib { MyType }

# mylib.wu
MyType: struct {}

Building project: ~/project$ wu build Expected contents:

-- main.wu
local lib = require "lib"
local mylib = lib["mylib"]

-- init.wu
local mylib = require "lib.mylib"

-- mylib.wu
<empty>

Building directory: ~/project$ wu src/lib Expected contents:

-- init.wu
local mylib = require "mylib"

-- mylib.wu
<empty>

Building file: ~/project$ wu src/lib/init.wu Expected contents:

-- init.wu
local mylib = require "mylib"

-- mylib.wu
<empty>