datastructures with javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sumaira Maqsood Ali

    datastructures with javascript

    HI,
    I have a C program that outputs html code and embedded javascript code.
    I have a datastructure in my C file whose data values have to be
    printed dyanamically by javascript when the viewer clicks on the
    corresponding button in the browser. Is there a way I can make this
    datastructure in C file available to Javascript when the viewer request
    to see that information.
    Thanks
    Sumaira

  • Berislav Lopac

    #2
    Re: datastructures with javascript

    Sumaira Maqsood Ali wrote:[color=blue]
    > HI,
    > I have a C program that outputs html code and embedded javascript
    > code. I have a datastructure in my C file whose data values have to
    > be printed dyanamically by javascript when the viewer clicks on the
    > corresponding button in the browser. Is there a way I can make this
    > datastructure in C file available to Javascript when the viewer
    > request to see that information.[/color]

    Sure there is. Just remember that C structures are just like object without
    methods, and that Javascript is an object-oriented language.

    So, if you have a structure going like this:

    struct myStruct
    {
    char myVar[11];
    int myVar2;
    struct subStruct
    {
    char mySubVar1[5];
    int mySubVar2;
    }
    } my_structure;

    You can easily convert it into a JS object similar to this:

    var myObject = new Object();
    myObject.myVar1 = "write the value of myStruct.myVar here";
    myObject.myVar2 = 100;
    myObject.subObj ect = new Object();
    myObject.subObj ect.mySubVar1 = "text";
    myObject.subObj ect.mySubVar2 = 285;

    Berislav

    --
    Berislav Lopac
    Web developer


    Comment

    • Richard Cornford

      #3
      Re: datastructures with javascript

      "Berislav Lopac" <berislav.lopac .l@duoplus.hr> wrote in message
      news:bftd0q$6qd $1@sunce.iskon. hr...
      <snip>[color=blue]
      >... . Just remember that C structures are just like object
      >without methods, and that Javascript is an object-oriented
      >language.[/color]
      [color=blue]
      >So, if you have a structure going like this:
      >
      >struct myStruct
      > {
      > char myVar[11];
      > int myVar2;
      > struct subStruct
      > {
      > char mySubVar1[5];
      > int mySubVar2;
      > }
      > } my_structure;
      >
      >You can easily convert it into a JS object similar to this:
      >
      > var myObject = new Object();
      > myObject.myVar1 = "write the value of myStruct.myVar here";
      > myObject.myVar2 = 100;
      > myObject.subObj ect = new Object();
      > myObject.subObj ect.mySubVar1 = "text";
      > myObject.subObj ect.mySubVar2 = 285;[/color]

      Or do the same using the slightly more compact JS Object literal
      notation:-

      var myObject = {
      myVar1:"write the value of myStruct.myVar here",
      myVar2:100,
      subObject:{
      mySubVar1:"text ",
      mySubVar2:285
      }
      };

      Richard.


      Comment

      Working...