[slang-users] Creating nested structures

John E. Davis davis at space.mit.edu
Fri Sep 5 16:42:42 UTC 2008


Laurent Perez <laurent.perez at unicaen.fr> wrote:
> Is there a way to create an interpreter structure from a nested C
> structure ?
>
> struct first {
> 	int a;
> 	int b;
>}
>
> struct second {
> 	int c;
> 	struct first d;
>}
>
> How do I create an interpreter structure corresponding to the second C
> defined structure ?

I can tell you the easiest way to answer this precise question, but a
more general answer would involve asking more about what you want to
do within the interpeter.  The easiest way to create a structure that
looks like the above is to use:

    char buf[256];
    sprintf (buf, "struct{c=%d, d=struct{a=%d, b=%d}};", 
                  second.c, first.a, first.b);
    (void) SLang_load_string (buf);

The use of SLang_load_string has the effect of pushing the structure
onto the slang stack.  While this will accomplish the stated goal, I
am not sure if this is really what you want.

Thanks,
--John


More information about the slang-users-l mailing list