Created
July 8, 2024 22:12
-
-
Save Kampfkarren/7a135a7e21f4cc1ca542fcfa138e62d6 to your computer and use it in GitHub Desktop.
My Luau code snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Place your snippets for luau here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
// Example: | |
// "Print to console": { | |
// "prefix": "log", | |
// "body": [ | |
// "console.log('$1');", | |
// "$2" | |
// ], | |
// "description": "Log output to console" | |
// } | |
"LocalPlayer": { | |
"prefix": "LocalPlayer", | |
"body": [ | |
"local LocalPlayer = Players.LocalPlayer$0" | |
] | |
}, | |
"Visible Attachment": { | |
"prefix": "VISUAL", | |
"body": [ | |
"local attachment = Instance.new('Attachment', workspace.Terrain) attachment.Visible = true attachment.Position = ${1:position}" | |
] | |
}, | |
// Quick requires | |
"Quick Require - Any Library": { | |
"prefix": "require", | |
"body": [ | |
"local ${1:libraryName} = require(${2:ReplicatedStorage}.${1:libraryName})$0" | |
] | |
}, | |
"React Component": { | |
"prefix": "REACT_COMPONENT", | |
"body": [ | |
"local ReplicatedStorage = game:GetService(\"ReplicatedStorage\")", | |
"", | |
"local React = require(ReplicatedStorage.Packages.React)", | |
"", | |
"local e = React.createElement", | |
"", | |
"local function ${1:$TM_FILENAME_BASE}(props)", | |
"\t$0", | |
"end", | |
"", | |
"return ${1:$TM_FILENAME_BASE}" | |
] | |
}, | |
"React Hook": { | |
"prefix": "REACT_HOOK", | |
"body": [ | |
"local ReplicatedStorage = game:GetService(\"ReplicatedStorage\")", | |
"", | |
"local React = require(ReplicatedStorage.Packages.React)", | |
"", | |
"local function ${2:$TM_FILENAME_BASE}($1)", | |
"\t$0", | |
"end", | |
"", | |
"return ${2:$TM_FILENAME_BASE}" | |
] | |
}, | |
"React Context": { | |
"prefix": "REACT_CONTEXT", | |
"body": [ | |
"local ReplicatedStorage = game:GetService(\"ReplicatedStorage\")", | |
"", | |
"local React = require(ReplicatedStorage.Packages.React)", | |
"", | |
"local e = React.createElement", | |
"", | |
"export type ContextType = {", | |
"\t$1", | |
"}", | |
"", | |
"local default: ContextType = {", | |
"\t$2", | |
"}", | |
"", | |
"local Context = React.createContext(default)", | |
"", | |
"local function ${3:Provider}(props: {", | |
"\tchildren: React.ReactNode,", | |
"})", | |
"\tlocal value: ContextType = {", | |
"\t\t$4", | |
"\t}", | |
"", | |
"\treturn e(Context.Provider, {", | |
"\t\tvalue = value,", | |
"\t}, props.children)", | |
"end", | |
"""return {", | |
"\tContext = Context,", | |
"\t${3:Provider} = ${3:Provider},", | |
"}" | |
] | |
}, | |
"Story": { | |
"prefix": "STORY", | |
"body": [ | |
"local ReplicatedStorage = game:GetService(\"ReplicatedStorage\")", | |
"", | |
"local ${1:${TM_FILENAME_BASE/\\.(.*)//}} = require(script.Parent.${1:${TM_FILENAME_BASE/\\.(.*)//}})", | |
"local React = require(ReplicatedStorage.Packages.React)", | |
"local ReactRoblox = require(ReplicatedStorage.Packages.ReactRoblox)", | |
"", | |
"local e = React.createElement", | |
"", | |
"return function(target)", | |
"\tlocal root = ReactRoblox.createRoot(target)", | |
"\troot:render(e(${1:Component}, {", | |
"\t\t$0", | |
"\t}))", | |
"", | |
"\treturn function()", | |
"\t\troot:unmount()", | |
"\tend", | |
"end" | |
] | |
}, | |
"GetService('ReplicatedStorage')": { | |
"prefix": "GRS", | |
"body": "local ReplicatedStorage = game:GetService(\"ReplicatedStorage\")", | |
}, | |
"local function ...() return": { | |
"prefix": "lfr", | |
"body": [ | |
"local function ${2:$TM_FILENAME_BASE}($1)", | |
"\t$0", | |
"end", | |
"", | |
"return ${2:$TM_FILENAME_BASE}", | |
] | |
}, | |
"UDim2.fromScale()": { | |
"prefix": "u2fs", | |
"body": "UDim2.fromScale(${1:x}, ${2:y})" | |
}, | |
"UDim2.fromOffset()": { | |
"prefix": "offset", | |
"body": "UDim2.fromOffset(${1:x}, ${2:y})" | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment