SC2Mapster Forums

Development > Miscellaneous Development

Galaxy Scripting

  • 4 posts
    #1 Mar 08, 2010 at 13:07 UTC - 0 likes

    No dynamic allocation

    Can't seem to allocate new objects on the fly. There is no such things as malloc or new.

    I tried to get the pointer from a local variable but it gets killed when leaving the function:

    struct test {
      int i;
      int j;
    };
    
    test* createTest() {
      test o;
      o.i = 5;
      o.j = 1;
      return &o;
    }
    
    void Init() {
      test *object = createTest();
      object->i;
      // Invalid stack pointer
    }
    

    No Object Copy

    If you want to copy an object, you have to do it by hand.

    test A = createTest();
    test B = A;
    // This field is not a member of the struct type
    test *B = A;
    // Bulk copy not supported.
    

    Casting

    There is no casting allowed

    void *a = createTest();
    // No implicit cast allowed
    void *a = (void *)(createTest());
    // Syntax Error: No explicit cast allowed
    
    Last edited Mar 08, 2010 by vjeux
    #2 Mar 08, 2010 at 19:44 UTC - 0 likes

    If returning &o makes it so the stack pointer is invalid, I'm not sure how you'd properly return a pointer without something like malloc.

    #3 Mar 12, 2010 at 00:40 UTC - 0 likes

    I see lots of "function" definitions of actual function return types. Is it a general (void *) handle or some special type?

    #4 Mar 12, 2010 at 08:38 UTC - 0 likes

    As there is no type casting, you can't use void*.

  • 4 posts

You must login to post a comment. Don't have an account? Register to get one!