-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua-libs.lua
More file actions
53 lines (47 loc) · 988 Bytes
/
lua-libs.lua
File metadata and controls
53 lines (47 loc) · 988 Bytes
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
function get_first_key(dictionary)
if not dictionary then
return nil
end
for key,_ in pairs(dictionary) do
return key
end
return nil
end
has_value =function(tab, val)
for _, value in ipairs (tab) do
if value == val then
return true
end
end
return false
end
get_index=function(tab,val)
i=1
while tab[i]~=nil and tab[i]~=val do
i=i+1
end
if tab[i]==nil then
return nil
else
return i
end
end
function remove_value(tab,val)
table.remove(tab,get_index(tab,val))
end
function string.starts(str,startstr)
return string.sub(str,1,str.len(startstr))==startstr
end
function string.ends(str,endstr)
return endstr=='' or string.sub(str,-string.len(endstr))==endstr
end
function string.split (inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end