diff --git a/src/host/lua-5.1.4/src/liolib.c b/src/host/lua-5.1.4/src/liolib.c index f0fe50e8..1baedced 100644 --- a/src/host/lua-5.1.4/src/liolib.c +++ b/src/host/lua-5.1.4/src/liolib.c @@ -105,15 +105,26 @@ static int io_noclose (lua_State *L) { /* ** function to close 'popen' files */ +/* + * PREAAKE change: return both output and exit code + */ static int io_pclose (lua_State *L) { FILE **p = tofilep(L); int result = lua_pclose(L, *p); *p = NULL; if (result == -1) { + /* + * pclose call failure + */ return pushresult(L, 0, NULL); } lua_pushboolean(L, 1); - lua_pushinteger(L, result / 255); + /** + * On success, pcluse returns a 2 byte length integer + * where the higher byte contains the command exit code + */ + result /= 255; + lua_pushinteger(L, result); return 2; } diff --git a/src/host/lua-5.1.4/src/luaconf.h b/src/host/lua-5.1.4/src/luaconf.h index 88ff3ffe..c3775903 100644 --- a/src/host/lua-5.1.4/src/luaconf.h +++ b/src/host/lua-5.1.4/src/luaconf.h @@ -668,11 +668,17 @@ union luai_Cast { double l_d; long l_l; }; #if defined(LUA_USE_POPEN) #define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) +/* + * PREMAKE change: get pclose return value + */ #define lua_pclose(L,file) ((void)L, (pclose(file))) #elif defined(LUA_WIN) #define lua_popen(L,c,m) ((void)L, _popen(c,m)) +/* + * PREMAKE change: get pclose return value + */ #define lua_pclose(L,file) ((void)L, (_pclose(file))) #else diff --git a/tests/base/test_os.lua b/tests/base/test_os.lua index ee5371c2..27eae2a4 100644 --- a/tests/base/test_os.lua +++ b/tests/base/test_os.lua @@ -103,3 +103,25 @@ function suite.pathsearch_NilPathsAllowed() test.isequal(os.getcwd(), os.pathsearch("premake5.lua", nil, os.getcwd(), nil)) end + +-- +-- os.pathsearch() tests +-- + function suite.outputof_commandExitCode() + if os.is("macosx") + or os.is("linux") + or os.is("solaris") + or os.is("bsd") + then + -- Assumes 'true' and 'false' commands exits + -- which should be the case on all *nix platforms + for cmd, exitcode in pairs ({ + ["true"] = 0, + ["false"] = 1 + }) + do + local o, e = os.outputof(cmd) + test.isequal(e, exitcode) + end + end + end \ No newline at end of file