Skip to content

Instantly share code, notes, and snippets.

@Accoast
Created September 15, 2024 01:25
Show Gist options
  • Select an option

  • Save Accoast/e819afb293df941210b82b441809fcf4 to your computer and use it in GitHub Desktop.

Select an option

Save Accoast/e819afb293df941210b82b441809fcf4 to your computer and use it in GitHub Desktop.
runtime safe object/instance properties set specified to use with --!strict
--!optimize 2
export type props = {[string]: any}
-- return runtime safe pcall wrapper
local function generate_safewrap(func: (any...) -> (any...))
return function(...: any...)
local success: boolean, result: string? = pcall(func, ...)
if success then
return result
else
warn("[safepropseterr]:", result)
end
end
end
-- wrappers generated
return {
access_set = generate_safewrap(function(object: Instance, key: string, value: any)
object[key] = value
end),
pure_access = generate_safewrap(function(object: Instance, key: string)
return object[key]
end),
prop_set = generate_safewrap(function(object: Instance, props: props)
for k,v in props do
object[k] = v
end
end),
} :: {
access_set: (object: Instance, key: string, value: any) -> (),
pure_access: (object: Instance, key: string) -> (any),
prop_set: (object: Instance, props: props) -> (),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment