lua-users home
lua-l archive

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


Actually I faced the prb a some time ago and started to see how the
status could be returned cleanly. Finally I did not need the popen
anymore so I did not implement the thing, but I found out that there
were very little thing to change to make it good.
First by not adding a new function. The current file:close could be used
as suggested delbu9c1, returning a number is equivalent to return a
boolean=true (this would also enable returning status=0 which actually
mean OK)

The modifications to the VM would be to:
1) luaconf.h line 679 to 680: change de macro #define lua_pclose(L,file)
to actually return the pclose code isntead of a boolean
Something like: #define lua_pclose(L,file)    ((void)L, pclose(file))

2) liolib.c line 108, function io_pclose():
Adapt it a little to something like:

        static int io_pclose (lua_State *L) {
          FILE **p = tofilep(L);
          int status = lua_pclose(L, *p);
          *p = NULL;

          if (status == -1)
            return pushresult(L, 0, NULL);

          lua_pushinteger(L, status);
          return 1;
        }


Watchout: It did not compile nor test the above patch, this is just to
illustrate my thought ;)


Cuero

Patrick Donnelly wrote:
> On Wed, Sep 2, 2009 at 12:46 PM, <delbu9c1@erau.edu> wrote:
>   
>> I'm not sure I see a benefit to it being a second return. Nil is false and all numbers are true so existing functionality should remain in tact.
>>     
>
> Yes, you're right. I'm thinking of another interface where a boolean
> is always the first return.
>
>