-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImplementations.lua
More file actions
58 lines (46 loc) · 1.44 KB
/
Implementations.lua
File metadata and controls
58 lines (46 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local _ENV = (getgenv or getfenv)()
local Implementations = {}
local type, tostring, string_find, string_rep = type, tostring, string.find, string.rep
-- from number to boolean
function Implementations.toBoolean(n)
return n ~= 0
end
-- an easy way to escape string, most developers better code like this!!!!
function Implementations.toEscapedString(s)
if type(s) == "string" then
local hasQuotationMarks = string_find(s, '"')
local hasApostrophes = string_find(s, "'")
if hasQuotationMarks and hasApostrophes then
return "[[" .. s .. "]]"
elseif hasQuotationMarks then
return "'" .. s .. "'"
end
return '"' .. s .. '"'
end
return tostring(s)
end
-- picks indexing method based on characters in a string
function Implementations.formatIndexString(s)
if type(s) == "string" then
if string_find(s, "^[%a_][%w_]*$") then
return "." .. s
end
return `["{s}"]`
end
return tostring(s)
end
-- add left side character padding to x
function Implementations.padLeft(x, char, padding)
local str = tostring(x)
return string_rep(char, padding - #str) .. str
end
-- add right side character padding to x
function Implementations.padRight(x, char, padding)
local str = tostring(x)
return str .. string_rep(char, padding - #str)
end
-- returns true if passed string is a key pointing to a Roblox global
function Implementations.isGlobal(s)
return _ENV[s] ~= nil
end
return Implementations