Jump to content
  • Advertisement
Sign in to follow this  
Sami Vuorela

Template containers angelscript addon library release!

This topic is 704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Rejoice, code warriors!
 
I have just released a template containers library for angelscript which provides bindings for various STL containers, allowing you to declare template containers containing anything in angelscript.
 
 
 
These container types are supported:
  • vector
  • list
  • deque
  • set
  • unordered_set
  • map
  • unordered_map
 
 
All containers can store as keys and values: primitives, objects and handles.
 
You can make template specializations of containers of your favourite c++ classes for extra performance.
 
All containers have iterators that work like this:
vector<int> myvec;
...
for(auto it = myvec.begin(); it++;){
  MyFunction( it.value );
}
 
 
Check the manual for more informations!
 
Requires Angelscript version 2.30.0
Check all the requirements here in the manual page
 
Uses the same license as angelscript, the zlib license, super freee.
 
 
 
ps. Its my first library release ever, so my management of the github repo might be sliiightly sub-optimal.
Edited by Sami Vuorela

Share this post


Link to post
Share on other sites
Advertisement

Thanks a lot for sharing this, Sami.

 

I've included a link to it on the further resources page, so it will be easy for others to find it in the future.

 

I hope that more developers will follow your example, so we can gather a large library of readily usable add-ons and utilities for the AngelScript engine. biggrin.png

Share this post


Link to post
Share on other sites

Sami - how much testing has gone into the library so far? Do you consider it an alpha/beta release, or ready for production use?

 

Thank you!

Share this post


Link to post
Share on other sites

Not much testing in practice. I'm using it in my little game project and it hasn't exploded yet.

 

The github repo includes a little test application that tests most functions and iteration of each container while using primitives, objects and handles. Everything works and returns the right things during those tests.

 

I haven't tried it on linux at all, because I don't know how to linux. It shouldn't be dependent on any windows things though.

I suppose I should call it beta.

 

As for users testing it, I'm not sure if anyone has even downloaded it yet. The github page graphs tell me that only one person has cloned it. Maybe someone downloaded it with the "Download ZIP" button and that button doesn't show up on any graph.

Share this post


Link to post
Share on other sites

This is exactly what I've been searching for. I'm building a modular game engine with AngelScript as main scripting language, so I'm definitely going to have a look to your work. Thank you for sharing this :D

Just one comment about iterator syntax:

We should be able to use auto instead of rewriting the container type, like we can in C++. Do you think it could be implemented?

Share this post


Link to post
Share on other sites

"for(auto it = mycontainer.begin();it++;)" is actually already halfway implemented, but its undocumented because it crashes with containers that are internally actual angelscript template types.

 

You can use it right now in the current build with containers: vector, list, set, unordered_set containing: primitives or strings.

 

 

I'll try to make it work with all types. Fighting against some copy constructors right now, soon they will bend to my will.

Share this post


Link to post
Share on other sites

Yay, auto iterators now work with all data types and all container types!

 

You can download the experimental build here: https://github.com/Sami-Vuorela/aatc/archive/experimental-auto-iterators.zip

You might also want to read the associated readme: https://github.com/Sami-Vuorela/aatc/blob/experimental-auto-iterators/EXPERIMENTAL_README.txt

Edited by Sami Vuorela

Share this post


Link to post
Share on other sites

Wow, that was quick smile.png

I tried to include your code in my project to see if it works, however I noticed you used an as:: alias of the AngelScript namespace, while I don't in the rest of my code...

 

// In aatc_config.hpp

namespace as = AngelScript;

 

This line fails because the AngelScript namespace is not defined (on purpose, I didn't added AS_USE_NAMESPACE to my preprocessor definitions).

Edited by Zylann

Share this post


Link to post
Share on other sites

Apparently there were 5 of those "as::" monsters still haunting the code. Everything is already wrapped in x_AS_NAMESPACE.

Fixed.

You can download the new, "as::" free version from the same link.

Share this post


Link to post
Share on other sites

Yay, it works, thank you!

 

Then, I tried various random things, and I got errors in some cases:

        for(vector_iterator<int> it(@karabraxos); ++it;)

The engine complains about a missing pre-increment operator. However it's not that bad after all, let's just write it++ at the moment.

    class Block
    {
        string name;
        Block(const string &in name_)
        {
            name = name_;
        }
    }
//...
        set<Block> bag;

Does not compile, as well as the following:

// Vector2i is a C++ class
        unordered_map<Vector2i,string> spacehash;

They say

E: ../projects/samples/helloworld/HelloWorld.ac: (112, 7): Attempting to instantiate invalid template type 'set<Block>'

and

E: ../projects/samples/helloworld/HelloWorld.ac: (126, 3): An exception Type 'Vector2i' has no method required for container's 'unordered_map::insert' method. occurred.

 

EDIT: I tried adding a default constructor to Block, the error turned to:

E: ../projects/samples/helloworld/HelloWorld.ac: (117, 3): An exception Type 'Block' has no method required for container's 'set::insert' method. occurred.

 

I assume I have to write a specialization for each C++ types I could put as a key of the containers... oh no, we can't do this for maps and unordered_maps? No template space hashs yet, then tongue.png

 

How could we use script classes as keys, then? Maybe defining an uint someFunctionNameToGetHashCode(const T &in v) function overload?

And how could we use object handles as keys, but STILL using someFunctionNameToGetHashCode for those? (sorry, I like to find edge cases...)

 

Finally, a bit of syntax:

to access the key and the value of a map_iterator, we have to write:

it.current_key();
it.current_value();

But it could be shorter to write like this:

it.key
it.value

Where key and value are actually properties returning references, and we could assign them transparently if needed (oh. But what happens if we assign the key of a map while iterating?).

 

The auto syntax works pretty well, maybe we're close to a foreach mechanism? Just a macro and here you go tongue.png

#define foreach(iterator_name, container) for(auto iterator_name = container.begin(); it++;)
Edited by Zylann

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!