File: restorable.pike

package info (click to toggle)
roxen 1.2beta2-3
  • links: PTS
  • area: contrib
  • in suites: slink
  • size: 16,920 kB
  • ctags: 8,589
  • sloc: ansic: 89,632; asm: 8,431; sh: 2,915; makefile: 1,784; cpp: 377
file content (45 lines) | stat: -rw-r--r-- 906 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* $Id: restorable.pike,v 1.4 1997/05/31 22:01:16 grubba Exp $ */

static private array __vars=({});

static private array save_variables()
{
  mixed b, a;
  array res = ({ }), variable;
  if(!sizeof(__vars)) // First time, not initialized.
    foreach(indices(this_object()), a)
    {
      b=this_object()[a];
      if(!catch { this_object()[a]=b; } ) // It can be assigned. Its a variable!
      {
	__vars+=({});
	res += ({ ({ a, b }) });
      }
    }
  else
    foreach(__vars, a)
      res += ({ ({ a, this_object()[a] }) });
  return res;
}


static private void restore_variables(array var)
{
  if(var)
    foreach(var, var)
      catch { this_object()[var[0]] = var[1]; };
}

string cast(string to)
{
  if(to!="string") error("Cannot cast to "+to+".\n");
  return encode_value(save_variables());
}

void create(string from)
{
  array f;
  catch {
    restore_variables(decode_value(from));
  };
}