Anaminus/rbxmk

Rework exprim API

Closed this issue · 0 comments

  • Use a global getter/setter function instead.
  • If a descriptor is available, use descriptor behavior. Otherwise, given type or descriptor as fallback.
  • Removes need for types library.
local value = rbxmk.get(instance, "Property", "Type")
rbxmk.set(instance, "Property",  value, "Type")
local value = rbxmk.get(instance, "Property", descriptor)
rbxmk.set(instance, "Property",  value, descriptor)

rbxmk.get

function rbxmk.get(instance: Instance, property: string, fallback: string | Desc | nil): (value: any)

The get function gets the property of instance. If instance has a descriptor, then it is used to determine the type when getting the property. Otherwise fallback is used. If fallback is a string, then the type named by the string is used. If fallback is a Desc, then that descriptor is used. If fallback is nil, then the type will be derived directly from the value of the property.

Note that fallback is always treated as less specific than the descriptor of instance. The purpose of the get function is to provide an descriptor-agnostic way to get properties that have ambiguous types in the absence of a descriptor. With a descriptor, the function behaves the same as indexing the property directly. Without a descriptor, the fallback argument is used to determine the type instead.

rbxmk.set

function rbxmk.set(instance: Instance, property: string, value: any, fallback: string | Desc | nil)

The set function sets the property of instance to value. If instance has a descriptor, then it is used to determine the type when setting the property. Otherwise, fallback is used. If fallback is a string, then the type named by the string is used. If fallback is a Desc, then that descriptor is used. If fallback is nil, then the type will be derived directly from value.

Note that fallback is always treated as less specific than the descriptor of instance. The purpose of the set function is to provide an descriptor-agnostic way to set properties that have ambiguous types in the absence of a descriptor. With a descriptor, the function behaves the same as assigning to the property directly. Without a descriptor, the fallback argument is used to determine the type instead.