visitAssignExpr method

  1. @override
Object? visitAssignExpr(
  1. AssignExpr assignExpr
)
override

Implementation

@override
Object? visitAssignExpr(AssignExpr assignExpr) {
  Object? lhs = assignExpr.lhs.accept(this);
  final rhs = assignExpr.rhs.accept(this);

  if (lhs == null && assignExpr.lhs is RawExpr) {
    // If this variable is not defined, it is now
    // and is also in the global scope.
    final id = (assignExpr.lhs as RawExpr).token.lexeme;
    return defGlobal(LuaObject.variable(id, rhs));
  } else if (lhs is LuaObject) {
    if (rhs is LuaObject) {
      if (lhs.deref() != rhs.deref()) {
        lhs.value = rhs;
      }
    } else {
      lhs.value = rhs;
    }
  }

  return lhs;
}