Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualViolet CLM

Posted 09 July 2013 - 02:48 PM

Maybe I should back up a bit, and express the issue in terms of what I would like the result to be, rather than in terms of what happens when I try specific things in order to get there. I want the following code to work in AngelScript:

void main() {
  someObject.someProperty = foo;
  someObject.someProperty = bar;
}

void foo() {
  //do stuff
}
Where "bar" is defined within the application, and is an arbitrary number, not even necessarily a pointer to a location that exists within the application's allotted memory. Maybe 0, maybe 1, maybe 0x87654321. I don't really care what type it has within AngelScript so long as I can send that arbitrary number back into the application again.

For the record, this seems to be working now. smile.png Solution:
  • Register all the arbitary numbers ("bar") as an enum, since that's the easiest way to define true constants in AngelScript, as opposed to read-only values.
  • As ever, register a single funcdef for the AngelScript functions ("foo").
  • Create and register a pointer-length value type ("someproperty"). Overload its opAssign and opEquals methods to accept both funcdef instances and enum instances, and also register an implicit value cast from value type to enum. (That last one not really needed, but it means that other functions need only be overloaded twice -- funcdef or enum -- not thrice -- funcdef, enum, or value type. Less bother.)
  • Add checks in a whole lot of application-internal places to determine when and where addRef() and release() need to be called, including the constructor, destructor, and opAssign for the value type.
Thanks again for your time, both in helping me out and in the more general development process. smile.png

#1Violet CLM

Posted 09 July 2013 - 02:17 PM

Maybe I should back up a bit, and express the issue in terms of what I would like the result to be, rather than in terms of what happens when I try specific things in order to get there. I want the following code to work in AngelScript:

void main() {
  someObject.someProperty = foo;
  someObject.someProperty = bar;
}

void foo() {
  //do stuff
}
Where "bar" is defined within the application, and is an arbitrary number, not even necessarily a pointer to a location that exists within the application's allotted memory. Maybe 0, maybe 1, maybe 0x87654321. I don't really care what type it has within AngelScript so long as I can send that arbitrary number back into the application again.

For the record, this seems to be working now. smile.png Solution:
  • Register all the arbitary numbers ("bar") as an enum, since that's the easiest way to define true constants in AngelScript, as opposed to read-only values.
  • As ever, register a single funcdef for the AngelScript functions ("foo").
  • Create and register a four-bit value type ("someproperty"). Overload its opAssign and opEquals methods to accept both funcdef instances and enum instances, and also register an implicit value cast from value type to enum. (That last one not really needed, but it means that other functions need only be overloaded twice -- funcdef or enum -- not thrice -- funcdef, enum, or value type. Less bother.)
  • Add checks in a whole lot of application-internal places to determine when and where addRef() and release() need to be called, including the constructor, destructor, and opAssign for the value type.
Thanks again for your time, both in helping me out and in the more general development process. smile.png

PARTNERS