Extra functions for Lua |
Gan_356_x « Citoyen » 1595819220000
| 5 | ||
Extra Lua Functions What is this? This is a library of simple functions that I've seen in other languages that I believe should be easily accessible in Lua. It will be added onto more in the future as there are not many functions I have added to this. How to use it? To use this, the only thing you will need to do is copy and paste this code at the top of your Lua script, or if you're too lazy to go to the link, copy and paste this: Code Lua 1 local a={reverseList=function(b)local c={}for d=1,#b do c[d]=b[#b-d+1]end;return c end,sum=function(b)local e=0;for d=1,#b do e=e+b[d]end;return e end,stringToCharList=function(f)local g={}for d=1,string.len(f)do g[d]=f:sub(d,d)end;return g end,listToString=function(b)local h=""for d=1,#b do h=h..b[d]end;return h end,indexOf=function(b,string)local i=-1;for d=1,#b do if b[d]==string then i=d;break end end;return i end,count=function(b,j)local k=0;for d=1,#b do if b[d]==j then k=k+1 end end;return k end}function a.split(f,l)local m={}local n=1;local d=1;while d<string.len(f)+1 do if f:sub(d,d+string.len(l)-1)==l then n=n+1;d=d+string.len(l)-1 else m[n]=(m[n]or"")..f:sub(d,d)end;d=d+1 end;return m end;function a.reverseString(f)return a.listToString(a.reverseList(a.stringToCharList(f)))end _=a You can access its methods with the _ variable. Examples (remember to have the code from above at the top of your script before using the functions below) Code Lua 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 local splittedString = _.split("hello i am a human", " ") Code Lua 1 2 3 4 5 6 7 8 9 10 local reversed = _.reverseString("hello i am a human") Code Lua 1 2 3 4 5 6 7 8 9 10 11 local nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} There are other functions I did not show examples of, though eventually I will try to make documentation for each of the functions. Dernière modification le 1595819880000 |
Kimsterjay « Consul » 1597140060000
| 0 | ||
Looks neat |