lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



The attached patch adds a function io.pclose() and file:pclose() to the liolib which returns the return code of the called program in io.popen().  This is to facilitate scripting of external programs where you need to know if they worked or not based on the exit code passed to the shell.  

This patch also modifies pushresult to allow passing arbitrary return values back to LUA.   The way I modified it, 'should' not break anything (all numbers including 0 are resolved as 'true' and nil/false are false) but someone more knowledgeable may wish to confirm this.

It also fixes what I perceve as a bug in the io_pclose() and io_fclose() functions where the file pointer is only set to NULL if the close operation succeeds.  According to the man pages for fclose(), after fclose() has been called on a FILE *, no operation must ever again be performed on that FILE *, or undefined behaviour will result.  I believe setting the FILE * to NULL is suppsed to prevent any further garbage collection in the __gc() metamethod, so it still needs to be done even if fclose() fails, else fclose() will get called on the same FILE * twice, with an unknown result.

Please look at this patch and tell me if I have made any grave errors, as this is my first attempt at patching one of the core libraries of LUA, and the intent is to add functionality and not change it (if possible).

Thanks
Mike Panetta
lua-5.1-pclose-pushresult.patch