source: golgotha/src/test/lisp/load_save.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 1.9 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "main/main.hh"
10#include "init/init.hh"
11#include "lisp/lisp.hh"
12#include "lisp/li_load.hh"
13#include "loaders/dir_load.hh"
14#include "loaders/dir_save.hh"
15
16char *data_file="load_save.data";
17
18void save(li_object *o)
19{
20  i4_file_class *fp=i4_open(data_file, I4_WRITE);
21  i4_saver_class *saver_fp=new i4_saver_class(fp);
22
23  // save type info about objects
24  li_save_type_info(saver_fp,0);
25
26  // save the actual object
27  li_save_object(saver_fp, o,0);
28 
29  // first pass just marks sizes, call save again to actually write out code
30  saver_fp->begin_data_write(); 
31
32  li_save_type_info(saver_fp,0);
33  li_save_object(saver_fp, o,0);
34
35  delete saver_fp;
36}
37
38
39li_object *load()
40{
41  i4_file_class *fp=i4_open(data_file);
42  if (fp)
43  {
44    i4_loader_class *loader=new i4_loader_class(fp);
45
46    // remap remaps li_ type numbers to the current types available
47    li_type_number *remap=li_load_type_info(loader,0);
48
49    // load the object
50    li_object *ret=li_load_object(loader,remap,0);
51
52    delete loader;
53    return ret;
54  }
55  return 0;
56}
57
58
59void i4_main(w32 argc, i4_const_str *argv)
60{
61  i4_init();
62
63  // allocate a new li_string
64  li_string *li_str=new li_string("Testing,  1... 2... 3..,  Testing");
65
66  // save the object to disk
67  save(li_str);
68
69  // load an object up
70  li_object *loaded_object=load();
71
72  // print out the object
73  lip(loaded_object);
74
75
76  i4_uninit();
77}
78
Note: See TracBrowser for help on using the repository browser.