fr1kin

lua sandbox

Sep 17th, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. local hasloaded = false;
  2.  
  3. local ty, p = type, pairs;
  4. local smt, gmt = setmetatable, getmetatable;
  5. local sfe, gte = setfenv, getfenv;
  6. local rs = rawset;
  7.  
  8. function tCopy(t, lookup_table)
  9.     if (t == nil) then return nil end
  10.    
  11.     local copy = {}
  12.     smt(copy, gmt(t))
  13.     for i,v in p(t) do
  14.         if ( !ty(v) == "table" ) then
  15.             copy[i] = v
  16.         else
  17.             lookup_table = lookup_table or {}
  18.             lookup_table[t] = copy
  19.             if lookup_table[v] then
  20.                 copy[i] = lookup_table[v] -- we already copied this table. reuse the copy.
  21.             else
  22.                 copy[i] = tCopy(v,lookup_table) -- not yet copied. copy it.
  23.             end
  24.         end
  25.     end
  26.     return copy
  27. end
  28.  
  29. local function LoadLuaFileProtected( lf )
  30.     local ENV = {};
  31.     local GLOBAL = tCopy( _G );
  32.     // add detoured func like this
  33.     // GLOBAL.func = oldfunc;
  34.     setmetatable( ENV, { __index = GLOBAL } );
  35.     local oldENV = gte( 0 );
  36.     sfe( 0, ENV );
  37.     LUA_LoadFile( lf );
  38.     sfe( 0, oldENV );
  39. end
  40.  
  41. // rushed, whatever
  42. setmetatable( package.loaded, {
  43.     __newindex = function( t,k,v )
  44.         if( k == "notification" && hasloaded == false ) then
  45.             hasloaded = true;
  46.             LoadLuaFileProtected( "client\\luastartup\\nm.lua" );
  47.             LoadLuaFileProtected( "client\\luastartup\\lol.lua" );
  48.         end
  49.         rs( t,k,v );
  50.     end,
  51. })
Advertisement
Add Comment
Please, Sign In to add comment