Jump to content

[SOLVED] How to create a buffer as a variable in my plugin


photo

Recommended Posts

In my c++ plugin I would be able to create a smart pointer  in this way:

Unigine::Ptr<Unigine::Buffer> ptr = Unigine::Buffer::create();

 

ptr->writeStream ....  //write some data in

 

Now I need to convert this buffer to a variable and return this variable to be used in the script.

 

I'm constructing in this way.

 

variable.setExternClassObject("Buffer",ptr->getInterface());

 

and in the script, and set the variable to a Buffer object

 

//cmd is a SharedData which contains an array of variables

 

Buffer buf = cmd.getNextField() ;  // this variable is a Buffer object. so it will be returned from variable.getExternClassObject

 

But it does not work. I'm wondering if the Buffer defined in the Library.cpp is not the same thing as described with Unigine::Buffer therefore I can't return it in this way.

 

Another thing I tried is if I pass a Buffer object from the script to my plugin, I can successfully convert it into a StreamPtr using the variable.getStream function.

 

Now I have no idea how should I achieve my goal, I would really need to create the Unigine::Buffer object in my c++ plugin, and it has to be returned as a variable to the script to

 

be further processed. Is it possible? And what would be the correct way to do it?

 

Link to comment

Chen,

 

In short, the idea is to pass Stream instance (since only such interface is available in C++ API) and then convert it into Buffer on the script side to be handled further. Maybe you could find source/samples/Api/Transfer sample useful as a reference.

Link to comment
×
×
  • Create New...