summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-02-21 22:55:32 +0800
committerruki <[email protected]>2020-02-21 11:33:16 +0800
commiteef01795e14276dac1f904217585b9c9208441dd (patch)
tree1b2da414855210669d30f7afb36ca99414ded1f7
parent2ce8c14ab4cee3a5673aa24649196cb45dcc0426 (diff)
improve xmake lua and os.syserror
-rw-r--r--core/src/xmake/os/syserror.c9
-rw-r--r--xmake/core/base/os.lua6
-rw-r--r--xmake/core/sandbox/modules/os.lua6
-rw-r--r--xmake/plugins/lua/main.lua11
4 files changed, 28 insertions, 4 deletions
diff --git a/core/src/xmake/os/syserror.c b/core/src/xmake/os/syserror.c
index 9630bd3c8..2d2b5511c 100644
--- a/core/src/xmake/os/syserror.c
+++ b/core/src/xmake/os/syserror.c
@@ -39,7 +39,14 @@ tb_int_t xm_os_syserror(lua_State* lua)
tb_assert_and_check_return_val(lua, 0);
// get syserror state
+ tb_int_t err = 0;
tb_size_t syserror = tb_syserror_state();
- lua_pushinteger(lua, (tb_int_t)syserror);
+ switch (syserror)
+ {
+ case TB_STATE_SYSERROR_NOT_PERM: err = 1; break;
+ case TB_STATE_SYSERROR_NOT_FILEDIR: err = 2; break;
+ case TB_STATE_SYSERROR_UNKNOWN_ERROR: err = -1; break;
+ }
+ lua_pushinteger(lua, err);
return 1;
}
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index de67d636b..68273b919 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -41,6 +41,12 @@ os._setenv = os._setenv or os.setenv
os._getenvs = os._getenvs or os.getenvs
os._readlink = os._readlink or os.readlink
+-- syserror code
+os.SYSERR_UNKNOWN = -1
+os.SYSERR_NONE = 0
+os.SYSERR_NOT_PERM = 1
+os.SYSERR_NOT_FILEDIR = 2
+
-- copy single file or directory
function os._cp(src, dst)
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 5aa33d0b2..48f18bd52 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -70,6 +70,12 @@ sandbox_os.projectdir = os.projectdir
sandbox_os.projectfile = os.projectfile
sandbox_os.getwinsize = os.getwinsize
+-- syserror code
+sandbox_os.SYSERR_UNKNOWN = os.SYSERR_UNKNOWN
+sandbox_os.SYSERR_NONE = os.SYSERR_NONE
+sandbox_os.SYSERR_NOT_PERM = os.SYSERR_NOT_PERM
+sandbox_os.SYSERR_NOT_FILEDIR = os.SYSERR_NOT_FILEDIR
+
-- copy file or directory
function sandbox_os.cp(...)
diff --git a/xmake/plugins/lua/main.lua b/xmake/plugins/lua/main.lua
index 2fae8a0c6..87c14d0b5 100644
--- a/xmake/plugins/lua/main.lua
+++ b/xmake/plugins/lua/main.lua
@@ -108,9 +108,14 @@ function _run_script(script, args)
_print_vlog(script_type or "script", script_name or "", args)
-- dump result
- local result = table.pack(func(table.unpack(args, 1, args.n)))
- if printresult and result and result.n ~= 0 then
- utils.dump(unpack(result, 1, result.n))
+ if type(func) == "function" then
+ local result = table.pack(func(table.unpack(args, 1, args.n)))
+ if printresult and result and result.n ~= 0 then
+ utils.dump(unpack(result, 1, result.n))
+ end
+ else
+ -- dump variables directly
+ utils.dump(func)
end
end