🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

AngelScript <-> C++ binder class.

Started by
45 comments, last by NickGalko 10 years, 7 months ago

Finally got the type exporter to work.

+ Type exporter
+ Constructor support
+ Constructor overload support
+ Destructor support
+ Dummy constructor/destructor support


I'll implement methods and properties later.



Looking nice! How are you going to differentiate POD's, "classes" and reference objects? And you also should support single-ref objects too.
Advertisement
There's also a type trait for whether or not an object is POD. It's called, appropriately, is_pod.
Alright, here's the weekend changes laugh.gif

  • Finished support for constructors / destructors
  • Dummy constructors/destructors are supported by setting .ctor_dummy() or .dtor_dummy()
  • Support for class methods exports (overload supported too)
  • asOBJ_POD flag being detected (thanks SiCrane)
  • Added support for AS namespaces
    I'll add support for properties now... It isn't on SVN yet, but I'll commit in some minutes.


    Initial/special flags are supported too:

    [color=#660066][font=CourierNew, monospace][size=2]Exporter[/font][color=#666600][font=CourierNew, monospace][size=2]::[/font][color=#660066][font=CourierNew, monospace][size=2]Export[/font][color=#666600][font=CourierNew, monospace][size=2]([/font][color=#000000][font=CourierNew, monospace][size=2]module[/font][color=#666600][font=CourierNew, monospace][size=2])[/font][color=#000000][font=CourierNew, monospace][size=2]
    [/font][color=#666600][font=CourierNew, monospace][size=2][[/font][color=#000000][font=CourierNew, monospace][size=2]
    [/font][color=#660066][font=CourierNew, monospace][size=2]Exporter[/font][color=#666600][font=CourierNew, monospace][size=2]::[/font][color=#660066][font=CourierNew, monospace][size=2]Class[/font][color=#666600][font=CourierNew, monospace][size=2]<[/font][color=#660066][font=CourierNew, monospace][size=2]MyClass[/font][color=#666600][font=CourierNew, monospace][size=2]>(asOBJ_NOHANDLE) // Here[/font][color=#000000][font=CourierNew, monospace][size=2]
    [/font][color=#666600][font=CourierNew, monospace][size=2].[/font][color=#000000][font=CourierNew, monospace][size=2]ctor_dummy[/font][color=#666600][font=CourierNew, monospace][size=2]()[/font][color=#000000][font=CourierNew, monospace][size=2]
    [/font][color=#666600][font=CourierNew, monospace][size=2].[/font][color=#000000][font=CourierNew, monospace][size=2]dtor_dummy[/font][color=#666600][font=CourierNew, monospace][size=2]()[/font][color=#000000][font=CourierNew, monospace][size=2]
    [/font][color=#666600][font=CourierNew, monospace][size=2]];[/font]
I'll try this on my project (I'm binding a ton of 3d engine functions from "Irrlicht") and give you feedback :)
Feedbacks are always welcome. Feel free :)

You know It's not fully featured yet. But I'm on the way! :D

Feedbacks are always welcome. Feel free :)

You know It's not fully featured yet. But I'm on the way! :D


Let me know when templates are supported!! That's what I struggle with currently...
Some updates:
  • Object members / offset detection being supported now via Class<MyClass>().member("life", &MyClass::_life);
  • Object accessors are supported now via Class<MyClass>().property("name", &MyClass::getName, &MyClass::setName());

    [quote name='WoLfuluss' timestamp='1315277546' post='4858046']
    Feedbacks are always welcome. Feel free :)

    You know It's not fully featured yet. But I'm on the way! :D


    Let me know when templates are supported!! That's what I struggle with currently...
    [/quote]

    I think this will be the last thing I'll add unsure.gif
    Lets see rolleyes.gif
Something I just thought about that would be immensely helpful you might want to consider.

We all know that we can;t inherit registered types from script, but there is a way around this restriction in the form of writing a script-based wrapper around the registered object. What if there was a flag in the exporter you are writing that would automatically generate and compile the script for classes we would want to inherit from?

Updates!
  • Script functions can be called now without any pain laugh.gif
    like this:


    /// Creates the engine
    Engine engine;

    /// Creates a module and compiles a script into it
    /// these modules doesn't needs to be released (it's automatic when Engine goes out of scope or gets destroyed
    Module* myModule = engine.createModule("MyModuleName");
    myModule->compile("script.as");

    // First way to call - not recommended
    myModule->getFunction<void()>("main")();

    // Second way to call - holds the function "pointer" and can be called many times.
    Function<int(int,int)> sum = myModule->getFunction<int(int,int)>("sum")();
    int a = sum(5, 10); // Returns 15
    int b = sum(6, 13); // Returns 19



    Suggestions? cool.gif
    BTW, it isn't on SVN yet, since it still support only 2 arguments - I'm writing the code generator for that... I'll commit in some hours.


    Something I just thought about that would be immensely helpful you might want to consider.

    We all know that we can;t inherit registered types from script, but there is a way around this restriction in the form of writing a script-based wrapper around the registered object. What if there was a flag in the exporter you are writing that would automatically generate and compile the script for classes we would want to inherit from?




    I'll take a look into this. Can you provide me an example of what you're exactly talking about? I have an idea, but I need a working example. smile.gif
Here is an example. Suppose that you have a game object class called GameObject. In your implementation, you want to be able to inherit from this object and add new features to it, such as and Enemy that can ShootAtPlayer.

The current solution is something like the following, assuming GameObject is registered as Core_GameObject with the functions AddModel and SomeOtherMethod.

// Angelscript

class GameObject
{
GameObject()
{
m_Core = Core_GameObject();
}

GameObject( const Core_GameObject@ obj)
{
@m_Core = obj;
}

// Let's assume that ScenegraphNode is doing the same thing as this class.

ScenegraphNode@ AddModel(const string@ resource)
{
return ScenegraphNode(m_Core.AddModel(resource));
}

void SomeOtherMethod()
{
m_Core.SomeOtherMethod();
}

private Core_GameObject@ m_Core;
};

// Then your enemy class.

class Enemy : GameObject
{
void ShootAtPlayer()
{
// Implementation here.
}
};

This topic is closed to new replies.

Advertisement