save/load macro in list 53/8853/2
Antoine ELIAS [Wed, 29 Aug 2012 07:55:22 +0000 (09:55 +0200)]
Change-Id: I18c5e6b41cfe5a387adbe76219ee48e30a908351

scilab/modules/io/macros/%_save.sci
scilab/modules/io/macros/%_sodload.sci
scilab/modules/io/tests/unit_tests/saveload_v5.dia.ref
scilab/modules/io/tests/unit_tests/saveload_v5.tst

index 7d649f4..9368e2b 100644 (file)
@@ -48,6 +48,9 @@ function [] = %_save(%__filename__, varargin)
         for %__i__ = definedfields(l)
             if typeof(l(%__i__)) == "handle" then
                 result(%__i__) = extractMatrixHandle(l(%__i__));
+            elseif isMacro(l(%__i__)) | isCompiledMacro(l(%__i__)) then
+                //build an arbitrary name to the macro
+                result(%__i__) = extractMacro(l(%__i__), "function");
             elseif isList(l(%__i__)) then
                 result(%__i__) = inspectList(l(%__i__));
             else
@@ -60,6 +63,9 @@ function [] = %_save(%__filename__, varargin)
             fieldValue = getfield(kField, l);
             if typeof(fieldValue) == "handle" then
                 fieldValue = extractMatrixHandle(fieldValue);
+            elseif isMacro(fieldValue) | isCompiledMacro(fieldValue) then
+                //build an arbitrary name to the macro
+                fieldValue = extractMacro(fieldValue, "function");
             elseif isList(fieldValue) then
                 fieldValue = inspectList(fieldValue);
             end
index 61a1451..8d4c3ae 100644 (file)
@@ -41,6 +41,9 @@ function %_sodload(%__filename__, varargin)
             for i = definedfields(varValue)
                 if typeof(varValue(i)) == "ScilabMatrixHandle" then
                     varValue(i) = createMatrixHandle(varValue(i));
+                elseif typeof(varValue(i)) == "ScilabMacro" then
+                    //convert tlist to macro
+                    varValue(i) = createMacro(varValue(i), "function");
                 elseif isList(varValue(i)) then
                     varValue(i) = parseList(varValue(i));
                 else
@@ -53,6 +56,9 @@ function %_sodload(%__filename__, varargin)
                 fieldValue = getfield(kField, varValue);
                 if typeof(fieldValue) == "ScilabMatrixHandle" then
                     fieldValue = createMatrixHandle(fieldValue);
+                elseif typeof(fieldValue) == "ScilabMacro" then
+                    //convert tlist to macro
+                    fieldValue = createMacro(fieldValue, "function");
                 elseif isList(fieldValue) then
                     fieldValue = parseList(fieldValue);
                 end
@@ -811,7 +817,6 @@ function %_sodload(%__filename__, varargin)
 
     //multiple output variables to prevent listinfile prints
     [%__variableList__, %__varB__, %__varC__, %__varD__] = listvarinfile(%__filename__);
-
     //
     if size(varargin) <> 0 then
         for i = 1:size(varargin)
index 33abc2c..d84c654 100644 (file)
@@ -123,12 +123,18 @@ if ~Check(a,b,c,d) then bugmes();quit;end
 function a = toto(x,y)
     a = x + y;
 endfunction
+l = list(toto);
 ref = toto(3*5, 9*3);
 save(TMPDIR + "/savemacro.sod", "toto");
 clear toto;
 load(TMPDIR + "/savemacro.sod");
 assert_checkequal(toto(3*5, 9*3), ref);
 assert_checkequal(type(toto), 13);
+save(TMPDIR + "/savemacro.sod", "l");
+clear l;
+load(TMPDIR + "/savemacro.sod");
+assert_checkequal(l(1)(3*5, 9*3), ref);
+assert_checkequal(type(l(1)), 13);
 clear toto;
 deff("a = toto(x,y)", "a = x + y;", "n");
 save(TMPDIR + "/savemacro.sod", "toto");
index 5cbe1e2..ca952a7 100644 (file)
@@ -156,6 +156,7 @@ if ~Check(a,b,c,d) then pause,end
 function a = toto(x,y)
     a = x + y;
 endfunction
+l = list(toto);
 
 ref = toto(3*5, 9*3);
 save(TMPDIR + "/savemacro.sod", "toto");
@@ -164,6 +165,12 @@ load(TMPDIR + "/savemacro.sod");
 assert_checkequal(toto(3*5, 9*3), ref);
 assert_checkequal(type(toto), 13);
 
+save(TMPDIR + "/savemacro.sod", "l");
+clear l;
+load(TMPDIR + "/savemacro.sod");
+assert_checkequal(l(1)(3*5, 9*3), ref);
+assert_checkequal(type(l(1)), 13);
+
 clear toto;
 deff("a = toto(x,y)", "a = x + y;", "n");
 save(TMPDIR + "/savemacro.sod", "toto");