[SOLVED] Issue creating a plugin


photo

Recommended Posts

I'm currently working on creating a plugin for the Unigine Editor.  I've created a custom class with two constructors as so

 

class MyClass

{

public:

  Tile(char* apName);

  Tile(const std::string& aName);

};

 

in the class that inherits from Unigine::Plugin I have

class UnigineToolPlugin : public Unigine::Plugin

{

  int init()

  {

    Unigine::ExternClass<MyClass> *mc = Unigine::MakeExternClass<MyClass>();

    mc->addConstructor<char*>();

    Unigine::Interpreter::addExternClass("MyClass", mc);

 

    return 1;

  }

};

 

In the script I have

 

int init()

{

  MyClass cm = new MyClass("TEST");

}

 

The script fails to load and the output from the console window is

 

Variable::getExternClassObject() : can't convert string to char * __ptr64

Editor::update() : editor update function return 0

 

Does anybody have a clue to what is going wrong or what I may have missed?

 

Please note this worked when I created a static function that takes a char*

 

static MyClass* makeClass(char* apName);

 

and then passed that in as a constructor

 

mc->addConstructor(&MakeClass);

Link to post

Hi Joshua!

 

Thanks for noticing that, I'll do my investigation and report back. By the way, could you please try to use const char * instead of char* and tell me if that'll work?

Link to post

OK, I changed from Unigine::String to const char * and it worked.  Not sure why this broke when I went from code compiled into our software to a DLL; I had been using std::string.

 

NOTE : When I say I went from Unigine::String I mean that I changed all string type inputs to Unigine::String to get things working.  Switching to const char*, instead of just char*, didn't affect the program.

Link to post

Joshua,

 

I did some research, here's correct version of the code:

#include <UnigineEngine.h>
#include <UnigineInterface.h>
#include <string>

/*
 */
using namespace Unigine;

/*
 */
class MyClass {
	public:
		MyClass(const char *name) { Log::message("MyClass::MyClass(const char *): called with \"%s\"\n",name); }
		MyClass(const std::string &name) { Log::message("MyClass::MyClass(const std::string &): called with \"%s\"\n",name); }
};

/*
 */
int main(int argc,char **argv) {
	
	// export extern class
	ExternClass<MyClass> *my_object = MakeExternClass<MyClass>();
	my_object->addConstructor<const char*>();
	Interpreter::addExternClass("MyClass",my_object);
	
	// init engine
	EnginePtr engine(UNIGINE_VERSION,argc,argv);
	
	// enter main loop
	engine->main();
	
	return 0;
}

As I said, the reason was that there's no implicit cast from char * to Unigine::Variable, the only one that exists is from const char * to Unigine::Variable. I think we didn't implement implicit cast to char * because of safety, so please use const char * instead.

Link to post