Advertisement
Descaii

runstring

Feb 24th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. -- Custom loadstring(In progress,have to make) -.-
  2. function runstring(string)
  3.     local create = function(text)
  4.         local t
  5.         local type
  6.         local vars = {}
  7.         if string.sub(text,1,1) == [=["]=] then
  8.             t = ""
  9.             for i = 1,#text-1 do
  10.                 if i ~= 1 then
  11.                     local n = string.sub(text,i,i)
  12.                     if n ~= [["]] then
  13.                         t = t..n
  14.                     else
  15.                         table.insert(vars,t)
  16.                         t = nil
  17.                         break
  18.                     end
  19.                 end
  20.             end
  21.         end
  22.         return unpack(vars)
  23.     end
  24.     local newtype = function(text)
  25.         local n = {}
  26.         local s = ""
  27.         local rec
  28.         for i = 1,#text+1 do
  29.             local r = string.sub(text,i,i)
  30.             if r:match("%w") then
  31.                 print(r)
  32.                 s = s ..r
  33.             elseif r == [["]] then
  34.                 rec = '"'
  35.                 print(r)
  36.                 s = s..[["]]
  37.             elseif r == [[=]] then
  38.                 local a = n[#n]
  39.                 print("EQ:"..a)
  40.                 local g = {Variable=a,Equal={}}
  41.                 n[#n]=g
  42.             --  print("EQ:"..tostring(n[#n]))
  43.             else
  44.                 if rec then
  45.                     s = s..rec
  46.                     rec = nil
  47.                 end
  48.                 if #s > 0 then
  49.                     print("Fin: " ..s,#s)
  50.                     local p = n[#n]
  51.                     if type(p) ~= "table" then
  52.                         table.insert(n,s)
  53.                     else
  54.                         print("Added to " ..p.Variable..", "..s)
  55.                         table.insert(p.Equal,s)
  56.                     end
  57.                 end
  58.                 s = ""
  59.             end
  60.         end
  61.         print(n[1].Variable,n[1].Equal)
  62.         name,equals = n[1].Variable,n[1].Equal
  63.         local cr = n[1].Equal
  64.         local fn = {}
  65.         for i,v in pairs(cr) do
  66.             table.insert(fn,create(v))
  67.         end
  68.         if name and equals then
  69.             getfenv()[name]=(getfenv()[equals] or unpack(fn))
  70.         end
  71.     end
  72.     newtype(string)
  73. end
  74. runstring([[asd = "test"]])
  75. print(tostring(asd))
  76. print(asd)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement