Advertisement
Bolodefchoco_LUAXML

[Function] run

Jun 6th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. local run = function(s)
  2.     local variables = {}
  3.  
  4.     for vName, vValue in string.gmatch(s, "([%a_][%a%d_]*) ?= ?([\"'%a%d_]*);") do
  5.         variables[vName] = vValue
  6.     end
  7.  
  8.     local functions = {}
  9.  
  10.     for  fName, fOut in string.gmatch(s, "([%a_][%a%d_]*) ?=> ?([%a%d_]*);") do
  11.         functions[fName] = function() return variables[fOut] or fOut end
  12.     end
  13.  
  14.     local out = {}
  15.  
  16.     for fCall in string.gmatch(s, "([%a_][%a%d_]*) ?%(%);") do
  17.         local result = type(functions[fCall]) == "function" and functions[fCall]() or type(_G[fCall]) == "function" and _G[fCall]()
  18.         out[#out + 1] = result
  19.     end
  20.    
  21.     for value1, comparsion, value2 in string.gmatch(s, "([%a%d_]+) ?([<>]=?) ?([%a%d_]+);?") do
  22.         value1 = (tonumber(value1) or variables[value1] or 0)
  23.         value2 = (tonumber(value2) or variables[value2] or 0)
  24.  
  25.         local result
  26.        
  27.         if comparsion:sub(1, 1) == "<" then
  28.             result = value1 < value2
  29.         else
  30.             result = value1 > value2
  31.         end
  32.        
  33.         if comparsion:sub(2, 2) == "=" then
  34.             result = result or value1 == value2
  35.         end
  36.        
  37.         out[#out + 1] = result
  38.     end
  39.    
  40.     for value, values in string.gmatch(s, "([%a%d_]+) ?== ?%((.-)%);") do
  41.         value = tonumber(variables[value] or value)
  42.        
  43.         if value then        
  44.             local args = {}
  45.             for v in string.gmatch(values, "[^, ]+") do
  46.                args[#args + 1] = tonumber(v) or tonumber(variables[v])
  47.             end
  48.  
  49.             local bool = false
  50.             for i = 1, #args do
  51.                 if args[i] == value then
  52.                     bool = true
  53.                     break
  54.                 end
  55.             end
  56.  
  57.             out[#out + 1] = bool
  58.         end
  59.     end
  60.    
  61.     for bool, tru, fals in string.gmatch(s, "([%a_][%a%d_]*) ?%? ?([%a%d_]+) ?: ([%a%d_]+);") do
  62.         bool = not not (variables[bool] or _G[bool])
  63.        
  64.         if bool then
  65.             out[#out + 1] = variables[tru] or _G[tru] or "nil"
  66.         else
  67.             out[#out + 1] = variables[fals] or _G[fals] or "nil"
  68.         end
  69.     end
  70.    
  71.     for tru, fals in string.gmatch(s, "([%a_][%a%d_]*) ?%?%? ?([%a%d_]+);") do
  72.         tru = variables[tru] or _G[tru] or tonumber(tru)
  73.        
  74.         if not not tru then
  75.             out[#out + 1] = tru or "nil"
  76.         else
  77.             out[#out + 1] = variables[fals] or _G[fals] or tonumber(fals) or "nil"
  78.         end        
  79.     end
  80.    
  81.     return out
  82. end
  83.  
  84. local r = run([[
  85.  
  86. x = 10;
  87.    
  88. f => x;
  89.    
  90. 10 < 20 < 30;
  91.    
  92. 10 == (x, 20, 30);
  93.    
  94. x ? y : 49;    
  95.  
  96. y ?? x;
  97.    
  98. ]])
  99.  
  100. print(table.unpack(r))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement