lua-users home
lua-l archive

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


   I am running in an environment without a useful stdout, and have
therefore redefined print() and _ERRORMESSAGE() to output via alternative
means.  They were easy, but now I also want to redefine write, and have
some questions.  I only want to use the redefined version iff _STDOUT is
explicity specified or no file handle is specified and output hasn't been
directed to a file with a call to writeto().

   Is it legitimate to compare "if _OUTPUT = _STDOUT then ..."?  It seems
to work fine, but I've seen no mention of whether or not it's proper to
compare file handles.  Is it further legal to compare an object of
unspecified type to _STDOUT to test if it is the stdout file handle?  (I'm
assuming that if the type isn't userdata then the compare will fail quickly
based solely on type.)  In outline form, here's what I'm after:

function write(...)
  if ((_OUTPUT == _STDOUT) or (arg[1] == _STDOUT)) then
    if (arg[1] == _STDOUT) then
      -- ok to custom write arg[2] and on, ignoring file arg
    else
      -- ok to custom write arg[1] and on
    end
  else
    -- need to call %write() with entire argument list
  end
end


   Note that I'll actually be doing this in the host language eventually,
but it's easier to puzzle it out directly in Lua first, then convert it. 
;-)  I also wonder why the ishandle() routine in the iolib isn't exposed in
the API?  Will I need that function to handle this "properly"?


   Cheers,
   Dave