Skip to content

Instantly share code, notes, and snippets.

@GlorifiedPig
GlorifiedPig / hook.lua
Last active April 21, 2023 12:12
Lua Hook Library
--- A library used for calling and attaching hooks.
-- @module Hook
Hook = {}
local cachedHooks = {}
--- Attaches a function to a hook.
-- @string hookID The string ID of the hook to be attached to.
-- @string uniqueID The unique ID of the function you are attaching to the hook.
-- @func func The function to be called when the hook is called.
@GlorifiedPig
GlorifiedPig / CLRConversions.cs
Created July 13, 2020 13:39
MoonSharp Colors
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Color),
dynVal => {
Table table = dynVal.Table;
float r = (float)table.Get("r").CastToNumber();
float g = (float)table.Get("g").CastToNumber();
float b = (float)table.Get("b").CastToNumber();
float a = (float)table.Get("a").CastToNumber();
return new Color(r, g, b, a);
}
);
@GlorifiedPig
GlorifiedPig / CLRConversions.cs
Last active June 5, 2023 05:22
MoonSharp Vectors
Script.GlobalOptions.CustomConverters.SetScriptToClrCustomConversion(DataType.Table, typeof(Vector3),
dynVal => {
Table table = dynVal.Table;
float x = (float)table.Get("x").CastToNumber();
float y = (float)table.Get("y").CastToNumber();
float z = (float)table.Get("z").CastToNumber();
return new Vector3(x, y, z);
}
);
Script.GlobalOptions.CustomConverters.SetClrToScriptCustomConversion<Vector3>(