src/vm/oba_compiler.c
static int resolveUpvalue(Compiler* compiler, Token name) {
  // There are no upvalues if this is the root function scope.
  if (compiler->parent == NULL) return -1;

  int local = resolveLocal(compiler->parent, name);
  if (local >= 0) {
    compiler->parent->locals[local].isCaptured = true;
    return addUpvalue(compiler, local, true);
  }

  int upvalue = resolveUpvalue(compiler->parent, name);
  if (upvalue >= 0) {
    return addUpvalue(compiler, upvalue, false);
  }

  return -1;
}
// Resolves an upvalue from the enclosing function scope.
//
// If this is the first time the upvalue is being resolved, and it is found in
// an outer scope of the enclosing scope, it is recursively registered as an
// upvalue in each enclosing scope to optimize future resolution.
Resolves an upvalue from the enclosing function scope.
If this is the first time the upvalue is being resolved, and it is found in
an outer scope of the enclosing scope, it is recursively registered as an
upvalue in each enclosing scope to optimize future resolution.
Resolves an upvalue from the enclosing function scope . If this is the first time the upvalue is being resolved and it is found in an outer scope of the enclosing scope it is recursively registered as an upvalue in each enclosing scope to optimize future resolution .
static int resolveUpvalue(Compiler* compiler, Token name) {
  if (compiler->parent == NULL) return -1;
  int local = resolveLocal(compiler->parent, name);
  if (local >= 0) {
    compiler->parent->locals[local].isCaptured = true;
    return addUpvalue(compiler, local, true);
  }
  int upvalue = resolveUpvalue(compiler->parent, name);
  if (upvalue >= 0) {
    return addUpvalue(compiler, upvalue, false);
  }
  return -1;
}
static int resolveUpvalue ( Compiler * compiler , Token name ) { if ( compiler -> parent == NULL ) return -1 ; int local = resolveLocal ( compiler -> parent , name ) ; if ( local >= 0 ) { compiler -> parent -> locals [ local ] . isCaptured = true ; return addUpvalue ( compiler , local , true ) ; } int upvalue = resolveUpvalue ( compiler -> parent , name ) ; if ( upvalue >= 0 ) { return addUpvalue ( compiler , upvalue , false ) ; } return -1 ; }
Resolves an upvalue from the enclosing function scope.
Resolves an upvalue from the enclosing function scope .
// There are no upvalues if this is the root function scope.