Advertisement
Bolodefchoco_LUAXML

[Script] os.lua (ALPHA)

May 14th, 2016
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 14/05/2016
  3. --Last update: 26/05/2016
  4. --[[ Notes:
  5.     Does:
  6.         Uma função que facilita a programação.
  7.     Current Commands:
  8.         every time_timer do function()
  9.         create var with value
  10.     Timers:
  11.         s --> Segundo
  12.         m --> Minuto
  13.         h --> Hora
  14.     Values:
  15.         nil --> Nulo
  16.         int --> Número
  17.         str --> String
  18.         bol --> Boolean
  19.     Example:
  20.         (Final das linhas)
  21. ]]
  22.  
  23. string.split=function(str,id,split)
  24.     local list={}
  25.     for val in string.gmatch(str,(id==0 and '[^'..(split or '%s')..']+' or id==1 and split)) do
  26.         table.insert(list,val)
  27.     end
  28.     return list
  29. end
  30. table.find=function(table,value)
  31.     for k,v in next,table do
  32.         if v == value then
  33.             return true,k
  34.         end
  35.     end
  36.     return false,0
  37. end
  38.  
  39. os.lua = function(command)
  40.     local p = string.split(command,0)
  41.     local loopE,loopI = table.find(p,"every")
  42.     local createE,createI = table.find(p,"create")
  43.     if loopE then
  44.         if p[loopI] == "every" then
  45.              if p[loopI + 2] == "do" then
  46.                 local int,time = p[loopI + 1]:match("(%d*)(%a)")
  47.                 int = tonumber(int) or 1
  48.                 if time then
  49.                     if time == "s" then
  50.                         int = int * 1
  51.                     end
  52.                     if time == "m" then
  53.                         int = int * 60
  54.                     end
  55.                     if time == "h" then
  56.                         int = int * 60 * 60
  57.                     end
  58.                     local numb = 0
  59.                     eventLoop = function(timer)
  60.                         numb = numb + .5
  61.                         if numb == int then
  62.                             numb = 0
  63.                             local func,val = p[loopI + 3]:match("(%w+)%((.*)%)")
  64.                             local x = string.split(val,0,",")
  65.                             _G[func](table.unpack(x))
  66.                         end
  67.                     end
  68.                 end
  69.             else
  70.                 error("<I>do</I> is missed!")
  71.             end
  72.         end
  73.     end
  74.     if createE then
  75.         if p[createI] == "create" then
  76.             if p[createI + 2] == "with" then
  77.                 if p[createI + 3] == "nil" then
  78.                     _G[p[createI + 1]] = nil
  79.                 elseif p[createI + 3] == "int" then
  80.                     _G[p[createI + 1]] = tonumber(p[createI + 4])
  81.                 elseif p[createI + 3] == "str" then
  82.                     _G[p[createI + 1]] = table.concat(p,' ',createI + 4)
  83.                 elseif p[createI + 3] == "bol" then
  84.                     _G[p[createI + 1]] = p[createI + 4] == "true"
  85.                 else
  86.                     error("The value is missed!")
  87.                 end
  88.             else
  89.                 error("<I>with</I> is missed!")
  90.             end
  91.         end
  92.     end
  93. end
  94.  
  95. --Exemplo
  96. os.lua([[
  97.     every 10s do print(Test!)
  98.     create NUMB with int 10
  99. ]])
  100. print(NUMB+20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement