lua-users home
lua-l archive

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


 >> Is there anybody out there who is doing things in a more "abstract"
way?
 >> I'm writing a "quake style console" widget 

   Yep, and for a similar purpose.  At first it seemed like it would be a
Big Deal, but it turned out to be easy.  Especially if you don't need to
support "real" Lua code.  (in other words, if you are free to take some
liberty in your redefinitions of functions because of your special use of
Lua)

   Basically, you'll need to override print(), _ALERT() and probably
write() on the output side, and read() on the input side.  print() and
_ALERT() are easy to redefine in the host language.  And you'll get
_ERRORMESSAGE() for free when you redefine _ALERT(), open up the i/o lib
and you also get nicer debug messages for free.

   For read() and write() you have maybe three alternatives:

   1)  Ignore them completely and write your own myread() and mywrite() in
the host language with simpler calling conventions, building up a string
and printing it to whatever output mechanism you have, or reading from
whatever.  Call the real read() and write() only when you need the original
functionality for file access.
   2)  Partially redefine read() and write() but forbid the use of the file
handle.  Redirecting as above.   Downside is you'll lose true file i/o
(which you might want to keep for logging purposes or something).
   3)  Fully redefine read() and write() -- see the recent "redefining
write()" thread for ideas, redirecting only as necessary.  write() is
fairly easy to do this for, a full read() would be harder due to the
pattern spec.  But then "real" Lua code should work throughout.

   Please share if you make any interesting discoveries - I'm definately
interested in this topic.  :)

   Cheers,
   Dave