2

So when doing investigation into LCLosures I see it has the same type appearance as CClosures but then further in the proto has upvalues also stored inside of there.

#define ClosureHeader \
    CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
    struct Table *env
typedef struct LClosure {
  ClosureHeader;
  struct Proto *p;
  UpVal *upvals[1];
} LClosure;

Then inside of the proto you have

typedef struct Proto {
  CommonHeader;
  TValue *k;  /* constants used by the function */
  Instruction *code;
  struct Proto **p;  /* functions defined inside the function */
  int *lineinfo;  /* map from opcodes to source lines */
  struct LocVar *locvars;  /* information about local variables */
  TString **upvalues;  /* upvalue names */
  TString  *source;
  int sizeupvalues;
  int sizek;  /* size of `k' */
  int sizecode;
  int sizelineinfo;
  int sizep;  /* size of `p' */
  int sizelocvars;
  int linedefined;
  int lastlinedefined;
  GCObject *gclist;
  lu_byte nups;  /* number of upvalues */
  lu_byte numparams;
  lu_byte is_vararg;
  lu_byte maxstacksize;
} Proto;

My question is do you use both? Do they mean different things in terms of Lua? I wasn't able to find any good explanation. As the lua_getupvalue function doesn't touch the former one it only uses the upvalues in the proto. Any help would be appreciated.

  • Are you talking about `nupvalues` and `nups`? Yes, they are duplicated. But removing either of them would not decrease the size of `Proto` structure. – Egor Skriptunoff May 29 '20 at 15:13

0 Answers0