lua-users home
lua-l archive

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


In trying to create a replacement for the standard write() function call, the first thing I did was copy io_write() and its static helper functions and definitions 
from the distribution, modified the calls that actually do the output.  But I am running into a strange, problem....

static int io_write (lua_State *L) {
  int lastarg = lua_gettop(L) - 1;
  IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1);
  int arg = 1;
  int status = 1;
  FILE *f = gethandle(L, ctrl, arg);
  if (f) arg++;
  else f = getfilebyref(L, ctrl, OUTFILE);  /* get _OUTPUT */

The call to getfilebyref() never returns.... debugging further I see that inside of there we get stuck on the line:

  lua_getref(L, ctrl->ref[inout]);

Now, up to this poing, the variable ctrl is NULL, so it is not surprising this doesnt work correctly.  The question is, why is it NULL?  Or am I doing something 
just basically wrong?

Guess I should stipulate that I am using version 4.0

Terry Bayne