add more comments on changes to the lua library

add basic test for the new os.outputof behavior
This commit is contained in:
Renaud Guillard 2014-01-25 20:23:13 +01:00
parent 187a756ce7
commit c8a18c4b4e
3 changed files with 40 additions and 1 deletions

View File

@ -105,15 +105,26 @@ static int io_noclose (lua_State *L) {
/* /*
** function to close 'popen' files ** function to close 'popen' files
*/ */
/*
* PREAAKE change: return both output and exit code
*/
static int io_pclose (lua_State *L) { static int io_pclose (lua_State *L) {
FILE **p = tofilep(L); FILE **p = tofilep(L);
int result = lua_pclose(L, *p); int result = lua_pclose(L, *p);
*p = NULL; *p = NULL;
if (result == -1) { if (result == -1) {
/*
* pclose call failure
*/
return pushresult(L, 0, NULL); return pushresult(L, 0, NULL);
} }
lua_pushboolean(L, 1); 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; return 2;
} }

View File

@ -668,11 +668,17 @@ union luai_Cast { double l_d; long l_l; };
#if defined(LUA_USE_POPEN) #if defined(LUA_USE_POPEN)
#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m)) #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))) #define lua_pclose(L,file) ((void)L, (pclose(file)))
#elif defined(LUA_WIN) #elif defined(LUA_WIN)
#define lua_popen(L,c,m) ((void)L, _popen(c,m)) #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))) #define lua_pclose(L,file) ((void)L, (_pclose(file)))
#else #else

View File

@ -103,3 +103,25 @@
function suite.pathsearch_NilPathsAllowed() function suite.pathsearch_NilPathsAllowed()
test.isequal(os.getcwd(), os.pathsearch("premake5.lua", nil, os.getcwd(), nil)) test.isequal(os.getcwd(), os.pathsearch("premake5.lua", nil, os.getcwd(), nil))
end 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