From c222f77c097a4f0806d8748b5974dc737d78f504 Mon Sep 17 00:00:00 2001
From: Sven Robertz <sven@cs.lth.se>
Date: Tue, 19 Feb 2013 14:51:04 +0100
Subject: [PATCH] added var array

---
 examples/simple/Decoder.java      | 15 ++++++++++++++-
 examples/simple/example_encoder.c | 12 +++++++++---
 examples/simple/simple.lc         |  2 +-
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/examples/simple/Decoder.java b/examples/simple/Decoder.java
index 278c5aa..c059df2 100644
--- a/examples/simple/Decoder.java
+++ b/examples/simple/Decoder.java
@@ -5,7 +5,7 @@ import java.io.InputStream;
 import se.lth.control.labcomm.LabCommDecoderChannel;
 
 public class Decoder
-  implements TwoInts.Handler, IntString.Handler 
+  implements TwoInts.Handler, IntString.Handler, TwoArrays.Handler
 {
 
   LabCommDecoderChannel decoder;
@@ -16,6 +16,7 @@ public class Decoder
     decoder = new LabCommDecoderChannel(in);
     TwoInts.register(decoder, this);
     IntString.register(decoder, this);
+    TwoArrays.register(decoder, this);
 
     try {
       System.out.println("Running decoder.");
@@ -33,6 +34,18 @@ public class Decoder
     System.out.println("Got IntString, x="+d.x+", s="+d.s);
   }
 
+  public void handle_TwoArrays(TwoArrays d) throws java.io.IOException {
+    System.out.println("Got TwoArrays:");
+    for(int i=0; i<d.fixed.length; i++) {
+	System.out.print(d.fixed[i]+" ");
+    }
+    System.out.println();
+    for(int i=0; i<d.variable[0].length; i++) {
+	System.out.print(d.variable[0][i]+" ");
+	System.out.print(d.variable[1][i]+" ");
+    }
+    System.out.println();
+  }
 
   public static void main(String[] arg) throws Exception {
     Decoder example = new Decoder(
diff --git a/examples/simple/example_encoder.c b/examples/simple/example_encoder.c
index dcd015b..689d12c 100644
--- a/examples/simple/example_encoder.c
+++ b/examples/simple/example_encoder.c
@@ -28,19 +28,25 @@ int main(int argc, char *argv[]) {
   printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b);
   labcomm_encode_simple_TwoInts(encoder, &ti);
 
-  int foo[10];
+  int foo[20];
 
   simple_TwoArrays ta;
   ta.fixed.a[0] = 17;
   ta.fixed.a[1] = 42;
-  ta.variable.n_0 = 10;
+  ta.variable.n_1 = 10;
   ta.variable.a = foo;
+  
+  int k;
+  for(k=0; k<20; k++) {
+	foo[k] = k;
+  }
+
+  labcomm_encode_simple_TwoArrays(encoder, &ta);
 
   ti.a = 23;
   ti.b = 47;
   printf("Encoding TwoInts, a=%d, b=%d\n", ti.a, ti.b);
   labcomm_encode_simple_TwoInts(encoder, &ti);
 
-  labcomm_encode_simple_TwoArrays(encoder, &ta);
 
 }
diff --git a/examples/simple/simple.lc b/examples/simple/simple.lc
index ea08013..2adfb2e 100644
--- a/examples/simple/simple.lc
+++ b/examples/simple/simple.lc
@@ -15,5 +15,5 @@ sample struct {
 
 sample struct {
   int fixed[2];
-  int variable[_];
+  int variable[2,_];
 } TwoArrays;
-- 
GitLab