Advertisement
Rochet2

lua upvalues

Jul 27th, 2015
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.58 KB | None | 0 0
  1. c = 10
  2. function test()
  3.  local a, b, c, d = 1, 2, 1, 4
  4.  
  5.  return function()
  6.      print(a, b, c, d, e)
  7.      return a+b+c+d
  8.  end
  9. end
  10.  
  11. local function ddump(f)
  12.     local i, t = 2, {}
  13.     local a, b = debug.getupvalue (test(), i)
  14.     while (a) do
  15.         t[i] = b
  16.         i = i+1
  17.         a, b = debug.getupvalue (test(), i)
  18.     end
  19.     return t, string.dump(f)
  20. end
  21. local function lload(t, d)
  22.     local f = assert(load(d))
  23.     for k,v in pairs(t) do
  24.         debug.setupvalue(f, k, v)
  25.     end
  26.     return f
  27. end
  28.  
  29. local t, d = ddump(test())
  30. local f = lload(t, d)
  31. c = 11
  32. f(1,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement