Change picture:

Choose file:

How to pack Dao script files into the Dao executable?


Starting from Dao 1.1, Dao VM supports virtual files and allows script files to be stored in byte arrays in a way to preserve the organization of the files. Dao VM is able to load them from memory as from hard disk by setting up equvilant virtual paths and searching among them.

The first thing to do is to use a hex dump tool such as xxd (with option -i ) to generate hex byte arrays from script files. Suppose you have two script files, one is called load.dao , and the other is called test.dao which is in a sub-fold named module .

After the following arrays are generated,
unsignedchar  module_test_dao[]  =  {
    0x0a,  0x6c,  0x20,  0x3d,  0x20,  0x28,  ...
    0x6f,  0x6e,  0x67,  0x3e,  0x29,  0x7b,  ...
    0x20,  0x7d,  0x3b,  0x0a,  0x6c,  0x32,  ...
    0x4c,  0x20,  0x3a,  0x20,  0x31,  0x30,  ...
    0x2e,  0x77,  0x72,  0x69,  0x74,  0x65,  ...
    0x20,  0x6c,  0x32,  0x2c,  0x20,  0x28,  ...
    0x2c,  0x20,  0x28,  0x6c,  0x6f,  0x6e,  ...
    0x32,  0x33,  0x34,  0x35,  0x36,  0x37,  ...
    0x35,  0x36,  0x37,  0x38,  0x39,  0x31,  ...
    0x38,  0x39,  0x27,  0x20,  0x29,  0x3b,  ...
    0x54,  0x65,  0x73,  0x74,  0x28,  0x29,  ...
    0x6f,  0x2e,  0x77,  0x72,  0x69,  0x74,  ...
    0x63,  0x61,  0x6c,  0x6c,  0x20,  0x54,  ...
    0x20,  0x29,  0x3b,  0x0a,  0x7d,  0x0a
};
unsignedint  module_test_dao_len  =  162;
unsignedchar  load_dao[]  =  {
    0x0a,  0x6c,  0x6f,  0x61,  0x64,  0x20,  ...
    0x65,  0x73,  0x74,  0x3b,  0x0a,  0x0a,  ...
    0x3b,  0x0a
};
unsignedint  load_dao_len  =  26;
one just need to define another array in the following way,
char*  dao_virtual_files[][2]  =
{
    {  "load.dao",  load_dao  },
    {  "module/test.dao",  module_test_dao  },
    {  NULL,  NULL  }
};
This array stores a list of path and file names with their hexdump of their file contents. It has to be named as dao_virtual_files (you may name it to anything if you do not intend to use it with the supplied file daoMainv.c from the Dao library).

The first entry in this array is considered as the main script, which is the one will accept command line arguments and start execution. And the last entry has to be NULL-filled to mark the end of the array. The other entries stores the modulized scripts which could be organized into folds, and could be dependent on by the script in the first entry. Here the second entry has path and file name as "module/test.dao", by specifying in this way, the load statement "load module.test;" in the "load.dao" file will be properly handled.

At this point, you can compile the packing file with hexdump of your scripts with the Dao VM using the daoMainv.c instead of the normal daoMain.c or daoMaindl.c . You can either include the packing file in daoMainv.c , or compile it indepently and link them together.

That's all, pretty simple, maybe a tool will be provided in the future to do this automatically.
view count 1072 times
created at 2009-09-19, 18:30 GMT
modified at 2010-04-06, 19:40 GMT

123 4
56 78910 11
121314151617 18
192021222324 25
26272829

fu: ... I forgot to say something about the plan for the whole new year in my previous reply. Well, besides w ... (Jan.19,01:40)

fu: ... Happy new dragon year (which will start from this sunday)! Actually, it was a busy month (I wish th ... (Jan.18,22:46)

ybabel: What's the plan for the new year ? Hello 'vry budy :- ) happy new year (when is the new year for you Fu ?) I saw you come back and comm ... (Jan.18,18:59)

This site is powered by Dao
Copyright (C) 2009,2010, daovm.net.
Webmaster: admin@daovm.net