Advertisement

std::vector bindings for angelscript

Started by April 21, 2008 11:13 PM
8 comments, last by Khaos Dragon 16 years, 7 months ago
I am just wondering if there exist std::vector bindings for angelscript?
I notice that Anthony Casteel (deyja) made an std::vector binding for angelscript version 1.10... however it does not seem to be up to date with the latest angelscript.

If anybody has any advice on how to port deyja's code to the lastest version of angelscript that would be widely appreciated. I very much like how bindings for math and std::string come packaged with angelscript, but I think eventually a vector addon should be packaged, as it is another one of those core library features that most c++ programmers use.
Advertisement
Anthony's std::vector binding is part of my regression test suite. You can find the updated version in the tests/test_feature/source/ folder in the sdk.

I haven't made a standard add_on as it overloads the built-in array type.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

How do you do templates?
Quote: Original post by WitchLord
Anthony's std::vector binding is part of my regression test suite. You can find the updated version in the tests/test_feature/source/ folder in the sdk.

I haven't made a standard add_on as it overloads the built-in array type.

Regards,
Andreas


Thank you Andreas, the vector implementation there works perfectly. Eventually once I get comfortable in Angelscript, I can perhaps submit some bindings to some common types.

One more question, is the scriptstring type supposed to be a simpler implementation of the std::string? I notice there are bindings for a test std::string type.

std::string can be bound directly with AngelScript, but then you have to bind it as a value type, i.e. asOBJ_VALUE. asCScriptString is a light wrapper for the std::string that allow the std::string to be bound as a reference type, i.e. asOBJ_REF.

I'm planning on adding a standard add-on for registering std::string directly. But I haven't gotten around to converting the stdstring.h/cpp from the test_feature folder into a proper add-on yet.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
How do we use the vector class within angelscript?
I will post examples of how I am doing it sometime tomorrow when I have access to my source at work. Its actually extremely simple.
Obviously you can't register the std::vector template as some generic type that AngelScript will derive from. Templates doesn't work that way, but what you do is that you register a vector type for each vector specialization you want.

With Anthony's implementation you register the std::vector for each element type with a call to RegisterVector, e.g:

// Register std::vector<int>RegisterVector("intVector", "int", engine);// Register std::vector<float>RegisterVector("floatVector", "float", engine);



AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Quote: Original post by WitchLord
Obviously you can't register the std::vector template as some generic type that AngelScript will derive from. Templates doesn't work that way, but what you do is that you register a vector type for each vector specialization you want.

With Anthony's implementation you register the std::vector for each element type with a call to RegisterVector, e.g:

// Register std::vector<int>RegisterVector("intVector", "int", engine);// Register std::vector<float>RegisterVector("floatVector", "float", engine);


Yes that is pretty much exactly what I do.

This topic is closed to new replies.

Advertisement