Advertisement
snake5

SGScript - meta-object sketch

Jul 27th, 2014
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // BEFORE
  2. global sgs_evalspec_env =
  3. {
  4.     array = array,
  5.     dict = dict,
  6.     map = map,
  7.     vec2 = vec2,
  8. };
  9. function sgs_evalspec( file, env )
  10. {
  11.     global _G;
  12.     envbk = _G;
  13.     pcall = _G.pcall;
  14.     eval_file = _G.eval_file;
  15.     sys_backtrace = _G.sys_backtrace;
  16.     _G = get_merged( env, sgs_evalspec_env );
  17.    
  18.     errmsg = null;
  19.     errstack = null;
  20.     pcall(function sgs_evalspec_trycode() use( file, eval_file )
  21.     {
  22.         eval_file( file );
  23.     },
  24.     function sgs_evalspec_errhandler( code, msg ) use( errmsg, errstack, sys_backtrace )
  25.     {
  26.         errmsg = msg;
  27.         errstack = sys_backtrace( true );
  28.     });
  29.    
  30.     _G = envbk;
  31.    
  32.     return !errmsg, errmsg, errstack;
  33. }
  34. // AFTER
  35. function sgs_evalspec( file, env )
  36. {
  37.     global _G;
  38.     envbk = _G;
  39.     _G = clone( env );
  40.     metaobj_set( _G, envbk );
  41.    
  42.     errmsg = null;
  43.     errstack = null;
  44.     pcall(function sgs_evalspec_trycode()
  45.     {
  46.         eval_file( file );
  47.     },
  48.     function sgs_evalspec_errhandler( code, msg ) use( errmsg, errstack )
  49.     {
  50.         errmsg = msg;
  51.         errstack = sys_backtrace( true );
  52.     });
  53.    
  54.     _G = envbk;
  55.    
  56.     return !errmsg, errmsg, errstack;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement