Problems with user-type vectors


#1

Hey :smile:

I can’t figure out how to use user-types vectors.
How can I do something like this :

var a = Vector()
var b = MyClass()
a.push_back(b)

If it’s not possible, is it possible at least to do something like :

var a = MyClassVector()
var b = MyClass()
a.push_back(b)

MyClass is a class added to ChaiScript environment with : chaiscript::utility::add_class

Thanks :slight_smile:


#2

Resolved using :

chaiscript::ModulePtr m1 = chaiscript::ModulePtr(new chaiscript::Module());
m1->add(chaiscript::user_type<Decoration>(), "Decoration");
m1->add(chaiscript::vector_conversion<std::vector<Decoration>>());
m1->add(chaiscript::bootstrap::standard_library::vector_type<std::vector<Decoration> >("Vector_Decoration"));

I didn’t found a way to push_back() some “Decoration” into a normal Vector() but I guess I will have to do without


#3

Glad you found the vector_conversion

If you give a full example and what the push_back call you are trying to make that doesn’t work, I might be able to help


#4

Decoration is a C++ Class made to contain a Sprite.
My script does look like that :

[::]Include(self, "Decoration")
[::]Include(self, "World")
[::]Include(self, "Cursor")
[::]Octopus(self, "cursor", "cursor")
[::]Octopus(self, "world", "world")

var decoVector = Vector()
var deco = world.getDecoByID("mydeco")
decoVector.push_back(deco)

The [::] means “Execute that line before executing the script”.
I had a lot of problems with Chaiscript and Threads, to execute a script I compress all lines into a single line.
So

var decoVector = Vector()
var deco = world.getDecoByID("mydeco")
decoVector.push_back(deco)

Will look like that :

var decoVector = Vector(); var deco = world.getDecoByID("mydeco"); decoVector.push_back(deco)

So I can eval() the line, it’s really dirty but I can’t figure out how to execute a script from a script.
So what I did until now is : Stopping the thread, saving locals and state, reload the thread,
,execute lines with [::] in priority, execute the “one-line script”, stopping the thread, restore locals and state and reloading the thread.