Skip to content

Commit

Permalink
State#currentDir is not a string
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Dec 22, 2023
1 parent 517f175 commit 115f51e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class State(val parentState: State? = null) {
/**
* The current working directory of the state.
*/
var currentDir = fileSystem.getPath(System.getProperty("user.dir")).toAbsolutePath()
var currentDir = System.getProperty("user.dir")

internal val openUpvalues = ArrayDeque<Upvalue.Instance>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class NativeLoader(private val libs: List<NativeLibrary>) : ModuleLoader {
*/
object FileLoader : ModuleLoader {
override fun load(state: State, module: String): CallableValue? {
val currentDir = state.fileSystem.getPath(state.currentDir)
val searchPaths = state.globals.lookUpHierarchy("package", "path")!!.listValue().map {
state.currentDir.resolve(state.fileSystem.getPath(it.stringValue()))
currentDir.resolve(state.fileSystem.getPath(it.stringValue()))
}
for (searchPath in searchPaths) {
val path = searchPath.resolve("$module.metis")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object OsLib : NativeLibrary("os") {
System.setProperty(value.stringValue(), other.stringValue())
Value.Null
}
lib["getCwd"] = zeroArgFunction { currentDir.absolutePathString().metisValue() }
lib["getCwd"] = zeroArgFunction { currentDir.metisValue() }
lib["setCwd"] = oneArgFunction { p ->
val path = fileSystem.getPath(p.stringValue())
if (!path.isAbsolute) {
Expand All @@ -98,7 +98,7 @@ object OsLib : NativeLibrary("os") {
"Cannot set cwd to relative path: ${path.absolutePathString()}"
)
}
currentDir = path
currentDir = path.absolutePathString()
Value.Null
}
}
Expand All @@ -113,7 +113,9 @@ object PathLib : NativeLibrary("__path") {
translateIoError { fn(toPath(self)) }
}

private fun State.toPath(value: Value) = currentDir.resolve(fileSystem.getPath(value.stringValue()))
private fun State.toPath(value: Value): Path {
return fileSystem.getPath(currentDir).resolve(fileSystem.getPath(value.stringValue()))
}

@OptIn(ExperimentalPathApi::class)
override fun init(lib: MutableMap<String, Value>) {
Expand Down

0 comments on commit 115f51e

Please sign in to comment.