diff options
| -rw-r--r-- | src/luarocks/core/manif.lua | 11 | ||||
| -rw-r--r-- | src/luarocks/core/manif.tl | 9 | ||||
| -rw-r--r-- | src/luarocks/core/persist.lua | 30 | ||||
| -rw-r--r-- | src/luarocks/core/persist.tl | 30 | ||||
| -rw-r--r-- | src/luarocks/manif.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/manif.tl | 4 | ||||
| -rw-r--r-- | src/luarocks/vendor/dkjson.d.tl | 2 |
7 files changed, 87 insertions, 5 deletions
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index 4c5e0441..c5ee158e 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table; local type = type | 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table; local type = type |
| 2 | 2 | ||
| 3 | local manif = {} | 3 | local manif = {} |
| 4 | 4 | ||
| @@ -52,7 +52,14 @@ end | |||
| 52 | 52 | ||
| 53 | 53 | ||
| 54 | function manif.manifest_loader(file, repo_url, lua_version) | 54 | function manif.manifest_loader(file, repo_url, lua_version) |
| 55 | local manifest, err, errcode = persist.load_into_table(file) | 55 | local manifest, err, errcode |
| 56 | |||
| 57 | if file:match(".*%.json$") then | ||
| 58 | manifest, err, errcode = persist.load_json_into_table(file) | ||
| 59 | else | ||
| 60 | manifest, err, errcode = persist.load_into_table(file) | ||
| 61 | end | ||
| 62 | |||
| 56 | if not manifest and type(err) == "string" then | 63 | if not manifest and type(err) == "string" then |
| 57 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode | 64 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode |
| 58 | end | 65 | end |
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index 1f3b3659..0a96d47e 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl | |||
| @@ -52,7 +52,14 @@ end | |||
| 52 | -- @return table or (nil, string, string): the manifest or nil, | 52 | -- @return table or (nil, string, string): the manifest or nil, |
| 53 | -- error message and error code ("open", "load", "run"). | 53 | -- error message and error code ("open", "load", "run"). |
| 54 | function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string | 54 | function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string |
| 55 | local manifest, err, errcode = persist.load_into_table(file) | 55 | local manifest, err, errcode: {string: any}, {string: boolean} | string, string |
| 56 | |||
| 57 | if file:match(".*%.json$") then | ||
| 58 | manifest, err, errcode = persist.load_json_into_table(file) | ||
| 59 | else | ||
| 60 | manifest, err, errcode = persist.load_into_table(file) | ||
| 61 | end | ||
| 62 | |||
| 56 | if not manifest and err is string then | 63 | if not manifest and err is string then |
| 57 | return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode | 64 | return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode |
| 58 | end | 65 | end |
diff --git a/src/luarocks/core/persist.lua b/src/luarocks/core/persist.lua index 258a42c0..c9ccb4a0 100644 --- a/src/luarocks/core/persist.lua +++ b/src/luarocks/core/persist.lua | |||
| @@ -2,6 +2,8 @@ local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 th | |||
| 2 | local persist = {} | 2 | local persist = {} |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | local json = require("luarocks.vendor.dkjson") | ||
| 6 | |||
| 5 | 7 | ||
| 6 | 8 | ||
| 7 | 9 | ||
| @@ -67,4 +69,32 @@ function persist.load_into_table(filename, tbl) | |||
| 67 | return result, globals | 69 | return result, globals |
| 68 | end | 70 | end |
| 69 | 71 | ||
| 72 | |||
| 73 | |||
| 74 | |||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | |||
| 79 | |||
| 80 | |||
| 81 | |||
| 82 | function persist.load_json_into_table(filename) | ||
| 83 | local fd, open_err = io.open(filename) | ||
| 84 | if not fd then | ||
| 85 | return nil, open_err, "open" | ||
| 86 | end | ||
| 87 | local str, read_err = fd:read("*a") | ||
| 88 | fd:close() | ||
| 89 | if not str then | ||
| 90 | return nil, read_err, "open" | ||
| 91 | end | ||
| 92 | local manifest, _, err = json.decode(str) | ||
| 93 | if not manifest then | ||
| 94 | return nil, "Failed decode manifest: " .. err, "load" | ||
| 95 | end | ||
| 96 | |||
| 97 | return manifest, {} | ||
| 98 | end | ||
| 99 | |||
| 70 | return persist | 100 | return persist |
diff --git a/src/luarocks/core/persist.tl b/src/luarocks/core/persist.tl index 4694afcb..268d2bb6 100644 --- a/src/luarocks/core/persist.tl +++ b/src/luarocks/core/persist.tl | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | local record persist | 2 | local record persist |
| 3 | end | 3 | end |
| 4 | 4 | ||
| 5 | local json = require("luarocks.vendor.dkjson") | ||
| 6 | |||
| 5 | -------------------------------------------------------------------------------- | 7 | -------------------------------------------------------------------------------- |
| 6 | 8 | ||
| 7 | --- Load and run a Lua file in an environment. | 9 | --- Load and run a Lua file in an environment. |
| @@ -67,5 +69,33 @@ function persist.load_into_table(filename: string, tbl?: {string:any}) : {string | |||
| 67 | return result, globals | 69 | return result, globals |
| 68 | end | 70 | end |
| 69 | 71 | ||
| 72 | --- Load a JSON file containing assignments, storing them in a table. | ||
| 73 | -- The global environment is not propagated to the loaded file. | ||
| 74 | -- @param filename string: the name of the file. | ||
| 75 | -- @param tbl table or nil: if given, this table is used to store | ||
| 76 | -- loaded values. | ||
| 77 | -- @return (table, table) or (nil, string, string): a table with the file's assignments | ||
| 78 | -- as fields and set of undefined globals accessed in file, | ||
| 79 | -- or nil, an error message and an error code ("open"; couldn't open the file, | ||
| 80 | -- "load"; compile-time error, or "run"; run-time error) | ||
| 81 | -- in case of errors. | ||
| 82 | function persist.load_json_into_table(filename: string) : {string: any}, {string: boolean} | string, string | ||
| 83 | local fd, open_err = io.open(filename) | ||
| 84 | if not fd then | ||
| 85 | return nil, open_err, "open" | ||
| 86 | end | ||
| 87 | local str, read_err = fd:read("*a") | ||
| 88 | fd:close() | ||
| 89 | if not str then | ||
| 90 | return nil, read_err, "open" | ||
| 91 | end | ||
| 92 | local manifest, _, err = json.decode(str) | ||
| 93 | if not manifest then | ||
| 94 | return nil, "Failed decode manifest: " .. err, "load" | ||
| 95 | end | ||
| 96 | |||
| 97 | return manifest, {} | ||
| 98 | end | ||
| 99 | |||
| 70 | return persist | 100 | return persist |
| 71 | 101 | ||
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 809b823d..b608d363 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local type = type | 1 | local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table; local type = type |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| @@ -103,6 +103,10 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
| 103 | not versioned_only and "manifest" or nil, | 103 | not versioned_only and "manifest" or nil, |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | if util.get_luajit_version() then | ||
| 107 | table.insert(filenames, 1, "manifest-" .. lua_version .. ".json") | ||
| 108 | end | ||
| 109 | |||
| 106 | local protocol, repodir = dir.split_url(repo_url) | 110 | local protocol, repodir = dir.split_url(repo_url) |
| 107 | local pathname, from_cache | 111 | local pathname, from_cache |
| 108 | if protocol == "file" then | 112 | if protocol == "file" then |
diff --git a/src/luarocks/manif.tl b/src/luarocks/manif.tl index 6a62a73f..da9b7d4c 100644 --- a/src/luarocks/manif.tl +++ b/src/luarocks/manif.tl | |||
| @@ -103,6 +103,10 @@ function manif.load_manifest(repo_url: string, lua_version?: string, versioned_o | |||
| 103 | not versioned_only and "manifest" or nil, | 103 | not versioned_only and "manifest" or nil, |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | if util.get_luajit_version() then | ||
| 107 | table.insert(filenames, 1, "manifest-" .. lua_version .. ".json") | ||
| 108 | end | ||
| 109 | |||
| 106 | local protocol, repodir = dir.split_url(repo_url) | 110 | local protocol, repodir = dir.split_url(repo_url) |
| 107 | local pathname, from_cache: string, boolean | 111 | local pathname, from_cache: string, boolean |
| 108 | if protocol == "file" then | 112 | if protocol == "file" then |
diff --git a/src/luarocks/vendor/dkjson.d.tl b/src/luarocks/vendor/dkjson.d.tl index a7c76389..4245e8aa 100644 --- a/src/luarocks/vendor/dkjson.d.tl +++ b/src/luarocks/vendor/dkjson.d.tl | |||
| @@ -15,7 +15,7 @@ local record dkjson | |||
| 15 | end | 15 | end |
| 16 | encode: function({string:any}, ?JsonState): string | 16 | encode: function({string:any}, ?JsonState): string |
| 17 | 17 | ||
| 18 | decode: function(string, ?number, ?any, ?table): {string:any} | 18 | decode: function(string, ?number, ?any, ?table): {string:any}, integer, string |
| 19 | 19 | ||
| 20 | null: table | 20 | null: table |
| 21 | 21 | ||
