lua-users home
lua-l archive

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


The Tilde debugger [1] adds the following code to ldebug.c:

LUA_API int lua_getvararg (lua_State *L, const lua_Debug *ar, int n) {
  CallInfo *ci = L->base_ci + ar->i_ci;
  if(isLfunction(ci->func))
  {
    Closure *cl = (Closure *) clvalue(ci->func);
    StkId firstVarArg = ci->func + cl->l.p->numparams + 1;
    int numVarArg = (int) (ci->base - firstVarArg);
    if(n <= numVarArg)
    {
      lua_lock(L);
      luaA_pushobject(L, firstVarArg + n - 1);
      lua_unlock(L);
      return n;
    }
  }
  return 0;
}

I have been attempting to port it to LuaJIT without success:

LUA_API int lua_getvararg (lua_State *L, const lua_Debug *ar, int n)
{
  int size;
  cTValue *frame = lj_debug_frame(L, 1, &size);
  if (frame) {
    GCfunc *fn;
    fn = frame_func(frame);
    lua_assert(fn->c.gct == ~LJ_TFUNC);
    if (isffunc(fn))
    {
      GCproto *pt = funcproto(fn);
      cTValue* firstVarArg = frame + pt->numparams + 1;
      int numVarArg = 0;
//    int numVarArg = (int) (ci->base - firstVarArg);
      if (n <= numVarArg)
      {
        copyTV(L, L->top, firstVarArg + n - 1);
        incr_top(L);
        return n;
      }
    }
  }

  return 0;
}

I haven't made an attempt yet to port to Lua 5.2.

Is anyone familiar enough with the LuaJIT and Lua 5.2 internals to help me out?

Thanks!

Josh

[1] https://github.com/jjensen/lua-tilde