Skip to content

Commit

Permalink
add package.config
Browse files Browse the repository at this point in the history
package.config was added in Lua v5.0-430-gab3dfa55.
lua/lua@ab3dfa5

but was documented since version 5.2
https://www.lua.org/manual/5.2/manual.html#pdf-package.config

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(package.config)
/
;
?
!
-
>

In gopher-lua package.config is nil.
This causes some packages, such as Luarocks, to crash with an error.

CLoses #360
  • Loading branch information
0x501D committed Mar 30, 2022
1 parent f4c35e4 commit f4be710
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ var LuaPath = "LUA_PATH"
var LuaLDir string
var LuaPathDefault string
var LuaOS string
var LuaDirSep string
var LuaPathSep = ";"
var LuaPathMark = "?"
var LuaExecDir = "!"
var LuaIgMark = "-"

func init() {
if os.PathSeparator == '/' { // unix-like
LuaOS = "unix"
LuaLDir = "/usr/local/share/lua/5.1"
LuaDirSep = "/"
LuaPathDefault = "./?.lua;" + LuaLDir + "/?.lua;" + LuaLDir + "/?/init.lua"
} else { // windows
LuaOS = "windows"
LuaLDir = "!\\lua"
LuaDirSep = "\\"
LuaPathDefault = ".\\?.lua;" + LuaLDir + "\\?.lua;" + LuaLDir + "\\?\\init.lua"
}
}
3 changes: 3 additions & 0 deletions loadlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func OpenPackage(L *LState) int {
L.SetField(packagemod, "path", LString(loGetPath(LuaPath, LuaPathDefault)))
L.SetField(packagemod, "cpath", emptyLString)

L.SetField(packagemod, "config", LString(LuaDirSep+"\n"+LuaPathSep+
"\n"+LuaPathMark+"\n"+LuaExecDir+"\n"+LuaIgMark+"\n"))

L.Push(packagemod)
return 1
}
Expand Down

0 comments on commit f4be710

Please sign in to comment.