SC2Mapster Forums

Development > General Map Development

Galaxy Scripting

  • 4 posts
  • on Mon, 08 Mar 2010 13:07:17

    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 on 08 Mar 2010 by vjeux
  • 6 hours later (on Mon, 08 Mar 2010 19:44:41)

    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 days later (on Fri, 12 Mar 2010 00:40:09)

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

  • 7 hours later (on Fri, 12 Mar 2010 08:38:21)

    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!