summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-08-23 22:50:15 +0800
committerruki <[email protected]>2019-08-23 11:01:35 +0800
commit01e7af7426fc0d1b461efbe57d9ed137fb1894ee (patch)
tree38548a2d2f6cf055cc23b3660eb9fe601eb75254
parent713d22e55d1fc6633f76ab34fe913ac5d793b735 (diff)
add luajit.bcsave
-rw-r--r--xmake/core/_xmake_main.lua2
-rw-r--r--xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua47
2 files changed, 49 insertions, 0 deletions
diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua
index f7aebd3e3..7f812089b 100644
--- a/xmake/core/_xmake_main.lua
+++ b/xmake/core/_xmake_main.lua
@@ -48,11 +48,13 @@ function _loadfile_impl(filepath, mode)
-- load script data from file
local file, ferrors = io.file_open(filepath, binary and "rb" or "r")
if not file then
+ ferrors = string.format("file(%s): %s", filepath, ferrors or "open failed!")
return nil, ferrors
end
local data, rerrors = io.file_read(file, "a")
if not data then
+ rerrors = string.format("file(%s): %s", filepath, rerrors or "read failed!")
return nil, rerrors
end
io.file_close(file)
diff --git a/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua b/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua
new file mode 100644
index 000000000..da4baed6b
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua
@@ -0,0 +1,47 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file bcsave.lua
+--
+
+-- load modules
+local io = require("base/io")
+local string = require("base/string")
+local raise = require("sandbox/modules/raise")
+
+-- save lua file to bitcode file
+--
+-- @param luafile the lua file
+-- @param bcfile the bitcode file
+-- @param opt the arguments option, e.g. {strip = true}
+--
+function main(luafile, bcfile, opt)
+ opt = opt or {}
+ local result, errors = loadfile(luafile)
+ if not result then
+ raise(errors)
+ end
+ result, errors = string._dump(result, opt.strip)
+ if not result then
+ raise(errors)
+ end
+ result, errors = io.writefile(bcfile, result)
+ if not result then
+ raise(errors)
+ end
+end
+return main