diff --git a/core/src/xmake/os/args.c b/core/src/xmake/os/args.c index c6de9e6c6b5..362b0c9bbba 100644 --- a/core/src/xmake/os/args.c +++ b/core/src/xmake/os/args.c @@ -117,10 +117,23 @@ tb_int_t xm_os_args(lua_State* lua) // add argument lua_pushnumber(lua, (tb_int_t)i); lua_rawget(lua, 1); - size_t size = 0; - tb_char_t const* cstr = luaL_checklstring(lua, -1, &size); - if (cstr && size) - tb_os_args_append(&result, cstr, size, escape, nowrap); + if (lua_istable(lua, -1)) // is path instance? + { + lua_pushstring(lua, "_PATH"); + lua_gettable(lua, -2); + size_t size = 0; + tb_char_t const* cstr = luaL_checklstring(lua, -1, &size); + if (cstr && size) + tb_os_args_append(&result, cstr, size, escape, nowrap); + lua_pop(lua, 1); + } + else + { + size_t size = 0; + tb_char_t const* cstr = luaL_checklstring(lua, -1, &size); + if (cstr && size) + tb_os_args_append(&result, cstr, size, escape, nowrap); + } lua_pop(lua, 1); } } diff --git a/core/src/xmake/process/openv.c b/core/src/xmake/process/openv.c index 493ba02ec98..a6b3dfa08e6 100644 --- a/core/src/xmake/process/openv.c +++ b/core/src/xmake/process/openv.c @@ -82,6 +82,14 @@ tb_int_t xm_process_openv(lua_State* lua) // pass this argument argv[1 + argi] = lua_tostring(lua, -1); } + // is path instance? + else if (lua_istable(lua, -1)) + { + lua_pushstring(lua, "_PATH"); + lua_gettable(lua, -2); + argv[1 + argi] = lua_tostring(lua, -1); + lua_pop(lua, 1); + } else { // error diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 870a98097b8..392047a39db 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -309,6 +309,9 @@ end -- function os.match(pattern, mode, callback) + -- support path instance + pattern = tostring(pattern) + -- get the excludes local excludes = pattern:match("|.*$") if excludes then excludes = excludes:split("|", {plain = true}) end @@ -423,12 +426,15 @@ function os.cp(srcpath, dstpath, opt) -- reserve the source directory structure if opt.rootdir is given local rootdir = opt and opt.rootdir if rootdir then + rootdir = tostring(rootdir) if not path.is_absolute(rootdir) then rootdir = path.absolute(rootdir) end end -- copy files or directories + srcpath = tostring(srcpath) + dstpath = tostring(dstpath) local srcpathes = os._match_wildcard_pathes(srcpath) if type(srcpathes) == "string" then return os._cp(srcpathes, dstpath, rootdir, opt) @@ -452,6 +458,8 @@ function os.mv(srcpath, dstpath) end -- copy files or directories + srcpath = tostring(srcpath) + dstpath = tostring(dstpath) local srcpathes = os._match_wildcard_pathes(srcpath) if type(srcpathes) == "string" then return os._mv(srcpathes, dstpath) @@ -475,6 +483,7 @@ function os.rm(filepath) end -- remove file or directories + filepath = tostring(filepath) local filepathes = os._match_wildcard_pathes(filepath) if type(filepathes) == "string" then return os._rm(filepathes) @@ -491,6 +500,8 @@ end -- link file or directory to the new symfile function os.ln(srcpath, dstpath) + srcpath = tostring(srcpath) + dstpath = tostring(dstpath) if not os.link(srcpath, dstpath) then return false, string.format("cannot link %s to %s, %s", srcpath, dstpath, os.strerror()) end @@ -499,10 +510,11 @@ end -- change to directory function os.cd(dir) - - -- check assert(dir) + -- support path instance + dir = tostring(dir) + -- the previous directory local oldir = os.curdir() @@ -551,6 +563,9 @@ function os.mkdir(dir) return false, string.format("invalid arguments!") end + -- support path instance + dir = tostring(dir) + -- create directories local dirs = table.wrap(os._match_wildcard_pathes(dir)) for _, _dir in ipairs(dirs) do @@ -569,6 +584,9 @@ function os.rmdir(dir) return false, string.format("invalid arguments!") end + -- support path instance + dir = tostring(dir) + -- remove directories local dirs = table.wrap(os._match_wildcard_pathes(dir)) for _, _dir in ipairs(dirs) do @@ -728,7 +746,7 @@ function os.execv(program, argv, opt) opt = opt or {} -- is not executable program file? - local filename = program + local filename = tostring(program) if not os.isexec(program) then -- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"