View on GitHub

Copy

A Luau-specialized module for copying any value with state.

Adding Type Support to Copy

Just like how Copy is meant to be flexible, it’s also meant to be extensible. If a new copyable datatype comes out (like Random), it might be useful to specify a method for copying it. This page will be covering how to do just that.

There are two ways to copy a value, replacing and reconciling.

Both of these methods expect the same return values:

Replacing

(self: Copy, oldValue: T) -> (success: boolean, doSet: boolean, newValue: T)

Parameters:

There are two required tasks the function has to complete when replacing a value.

  1. Creating the new value
  2. Mapping the old value to the new one in self.Transform

Reconciling

(self: Copy, oldValue: T, newValue: T) -> (success: boolean, doSet: boolean, newValue: T)

Parameters: